Simple wpdb->query sometimes kills my CPU?
-
Very quick summary. I have a website that has about 200-250 users on at its peak times.
Sometimes, all is great. Sometimes, CPU load gets up to 15,16,17 (should be <4 ideally) and the site almost becomes unresponsive. Sometimes this doesn’t happen, even with 300 users on. It honestly fluctuates at any given time. Can’t figure out what its related to. Have many plugins and a very active Buddypress community (caching as well, but doesn’t really help with logged-in users) so narrowing it down is tough.
ANYWAY.
I accidentally found out one day removing this one query of a plugin “relieves” the load almost immediately.$wpdb->query("UPDATE " . $wpdb->wpfilebase_files . " SET file_hits = file_hits + 1, weekly_file_hits = weekly_file_hits + 1, daily_file_hits = daily_file_hits + 1, file_last_dl_ip = '" . $downloader_ip . "', file_last_dl_time = '" . $this->file_last_dl_time . "' WHERE file_id = " . (0+$this->file_id));
This query is called when a file gets downloaded. Removing this one query – not all the hundreds of lines of code around it is also executed per download – just this one line. This relieves the load to “acceptable” ranges (still not ideal, but the site becomes snappier, there’s definitely cause-and-effect here, I mean I kinda expect the site to slow down when there’s 200-300 users on but this line being removed seems to relieve the “crippling” of the site).
But, why?
It’s not a crazy query. This table is indexed as well. Is there another way for me to perform the same query in order to test? (Note the “file_hits + 1” type of stuff which isn’t doable with a wpdb->update call)
- The topic ‘Simple wpdb->query sometimes kills my CPU?’ is closed to new replies.