Painfully slow, Devel Query logs show culprit I have been having a few problems with one of my clients site. Its a big site, theres a few thousand nodes, 10k users, and it holds large images galleries with 100+ images that are 500kb each.

At its slowest, the average page load is 45 seconds!! And the worst i when you are logged in.

After enabling devel query logs, this one stands out as the worst...

3923.69 ms  1  node_tag_new  P A
INSERT INTO history (uid, nid, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2)

Thats the first page load, the second is much much worse....

65594.921 ms  node_tag_new   P A
UPDATE history SET timestamp=:db_update_placeholder_0 WHERE ( (uid = :db_condition_placeholder_0) AND (nid = :db_condition_placeholder_1) )

What is the history table? Any idea why it is taking so long to run the query?
What is the history table?


This is a table for keeping track of what user has read what node. (To show a new/updated message next to it.) 


  Any idea why its taking so long to run the query?


This could be anything, and might be at the server level (not related to Drupal). 

First, check if SQL is slow outside Drupal (eg. PHPmyadmin). Run the same query, see what happens.

If SQL is still slow and you have ssh access to the server, try to run some disk speed checks using sudo hdparm -Tt /dev/sda and dd if=/dev/zero of=/tmp/output bs=8k count=10k; rm -f /tmp/output (assuming Linux). I had a slow site recently that was caused by a malfunctioning hard drive.