[英]Why would this UPDATE query be killing my CPU?
So over time I've noticed my website getting slower and slower, normally at peak traffic hours and weekends - the CPU load would hit 10x what it should be and often the website would turn unresponsive. 因此,随着时间的流逝,我注意到我的网站越来越慢,通常是在高峰时段和周末-CPU负载将达到应有的10倍,并且通常网站会变得无响应。
After much hacking away at stuff, I've discovered commenting out this line brings the CPU load down to normalcy: 经过大量修改之后,我发现注释掉这行代码会使CPU负载降低到正常水平:
$this->file_hits++;
$this->weekly_file_hits++;
$this->daily_file_hits++;
$this->file_last_dl_ip = $downloader_ip;
$this->file_last_dl_time = current_time('mysql');
$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 is code from a WordPress plugin. 这是来自WordPress插件的代码。 It fires when a file is downloaded, and is pretty self explanatory, just logs hits/IP/date etc into the appropriate row in the DB. 它在下载文件时触发,并且很容易解释,只需将命中/ IP /日期等记录到数据库中的相应行中。
I don't understand why this pretty simple update query would result in this? 我不明白为什么这个非常简单的更新查询会导致这种情况?
Some info: 一些信息:
It looks like your UPDATE
query is running slowly. 看起来您的UPDATE
查询运行缓慢。 That could be because 那可能是因为
file_id
column so WHERE file_id = something
can run faster in your UPDATE
. 它需要在file_id
列上有一个索引,因此WHERE file_id = something
在UPDATE
可以更快地运行。 Is this the WP-Filebase plugin? 这是WP-Filebase插件吗? If so, the usual advice to contact the plugin author doesn't apply, because the plugin has been closed by the wordpress.org authorities. 如果是这样,则联系插件作者的通常建议不适用,因为该插件已被wordpress.org当局关闭。
You are doing backups, right? 您正在备份,对不对? If not, back up your database before doing anything else. 如果没有,请先备份数据库,然后再执行其他操作。
You need to fix up the slow table yourself. 您需要自己修复慢速表。 It's best to do this at a low-traffic time for your site. 最好在您的网站流量少的时候执行此操作。
Open up phpmyadmin, open your WordPress database, and look for a table with a name like wp_filebase_files
or wp_filebasefiles
. 打开phpmyadmin,打开您的WordPress数据库,并查找名称类似于wp_filebase_files
或wp_filebasefiles
。 Click on the name. 单击名称。 (I don't know exactly what the table name is.) (我不知道确切的表名是什么。)
Then click the Operations tab at the top of your screen. 然后,单击屏幕顶部的“操作”选项卡。
Then, under Table maintenance click the Optimize Table link. 然后,在“表维护”下,单击“优化表”链接。 It may run for a while. 它可能会运行一段时间。 Then see if performance improves. 然后查看性能是否提高。 If that doesn't help, click the Repair Table link. 如果那没有帮助,请单击“修复表”链接。 Then try performance again. 然后再次尝试性能。
If these don't help, you may need an index on your table. 如果这些方法没有帮助,则您可能需要在表上建立索引。 Here's how to add one. 这是添加一个的方法。
On the left side of phpMyAdmin, click the [+] sign next to your table, then click the [+] signs next to Columns and Indexes. 在phpMyAdmin的左侧,单击表旁边的[+]符号,然后单击“列和索引”旁边的[+]符号。
If it shows file_id
as an index, you already have the index your query needs, and my advice can't help you. 如果它显示file_id
作为索引,则说明您已经具有查询所需的索引,而我的建议无济于事。 (Sorry.) (抱歉。)
If it doesn't, click New under Indexes. 如果不是,请单击“索引”下的“ 新建 ”。 You'll get a dialog box. 您将看到一个对话框。 Fill it out like this. 像这样填写。
Then click Go. 然后单击执行。 It may take a while to create the index. 创建索引可能需要一段时间。 Then see if your performance picks up. 然后查看您的演奏是否加快。
This kind of thing happens to busy databases; 这种情况发生在繁忙的数据库中。 it's normal, but it's a pain in the neck. 这很正常,但是脖子很疼。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.