简体   繁体   English

通常冷静的网络服务器具有CPU峰值,对MySQL有一定的查询

[英]Usually calm webserver has CPU spikes with certain query on MySQL

I have moved websites from Windows 2008R2 to Windows 1012R2. 我已将网站从Windows 2008R2移动到Windows 1012R2。 On the new server i have spikes in CPU performance when a certain script kicks in. One connection that runs this query takes up 55%, that's not a real big problem, but 2 minutes later a second connection with same query comes up. 在新服务器上,当某个脚本启动时,我的CPU性能会出现高峰。运行此查询的一个连接占用55%,这不是一个真正的大问题,但是2分钟之后会出现第二个具有相同查询的连接。 And there is where it goes wrong. 而且它出错了。 Now MySQL gobbles up 100% CPU and the server has no time to serve - even cached - websites. 现在MySQL吞噬了100%的CPU,服务器没有时间服务 - 甚至是缓存 - 网站。

This is, i think the peace of script that is the culprit: 这是,我认为脚本的和平是罪魁祸首:

if(isset($_GET['q'])){
global $wpdb;

$table_suggest = $wpdb->prefix . "suggest";
$word = $_GET['q'];
$getwords = "SELECT words from $table_suggest WHERE words LIKE '{$word}%' ORDER BY words ASC LIMIT 0, 10";
// echo $getwords;
$wpdb->show_errors();
$wpdb->get_results($getwords);
// header('Content-Type: text/html',true);
foreach ($wpdb->last_result as $row){
echo $row->words."\n";
}
flush();
}
else {echo "need search query";}

Which makes numerous of these in my log: 在我的日志中有很多这些:

SELECT words FROM wp_suggest WHERE words = '(sub)distributieovereenkomsten';
# User@Host: User[User] @ localhost [127.0.0.1]
# Query_time: 0.109377  Lock_time: 0.000000 Rows_sent: 2  Rows_examined: 64298
SET timestamp=1497086405;
SELECT words FROM wp_suggest WHERE words = 'Misbruik';
# Time: 170610 11:20:06
# User@Host: User[User] @ localhost [127.0.0.1]
# Query_time: 0.109375  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 64298

I think this script harvests words for the search engine. 我认为这个脚本可以为搜索引擎收集单词。 Considering this site ran perfectly normal on my old server, i guess this should be running on my newer and better server flawless too. 考虑到这个站点在我的旧服务器上运行完全正常,我想这应该在我更新更好的服务器上运行完美。

So maybe someone with better knowledge about MySQL could scan my my.ini for me to see, if there is room for performance. 所以也许对MySQL有更好了解的人可以扫描我的my.ini给我看,如果有性能空间的话。

My current situation: 我目前的情况:

  • Intel Xeon L5640 英特尔至强L5640
  • 6GB internal memory 6GB内存
  • Windows 2012R2 IIS8.5 x64 Windows 2012R2 IIS8.5 x64
  • PHP7.1.1 x64 PHP7.1.1 x64
  • MySQL 5.5 x64 MySQL 5.5 x64

My current my.ini: 我现在的my.ini:

[client]
port=3306

[mysql]
default-character-set=UTF8

[mysqld]
max-allowed_packet = 64M
wait-timeout = 6000
slow_query_log_file = d:/mysql/slow-queries.log
long_query_time=10
port=3306
basedir="C:/Program Files/MySQL/MySQL Server 5.5/"
datadir="D:/mysql/"
character-set-server=UTF8
default-storage-engine=INNODB
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=150
query_cache_size=0
table_cache=256
tmp_table_size=16M
max_heap_table_size=16M
thread_cache_size=8
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=69M
key_buffer_size=55M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=256K
innodb_additional_mem_pool_size=3M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=2M
innodb_buffer_pool_size=3076M
innodb_log_file_size=768M
innodb_thread_concurrency=8

MySQL itselfs caculated it needs 9GB as innodb_buffer_pool_size, but my server has only 6 for everything now, and mysqld.exe is only using 850MB. MySQL本身计算它需要9GB作为innodb_buffer_pool_size,但我的服务器现在只有6个,而mysqld.exe只使用850MB。 And most of the time CPU does not exceeds 40%, so that's not realy the problem, i guess. 并且大多数时候CPU不超过40%,所以这不是真正的问题,我想。

Thanks in advance for any help. 在此先感谢您的帮助。

I went to Percona and generated an ini tailored to my config, and it looks like all is working smoothly now. 我去Percona并根据我的配置生成了一个ini,看起来现在一切都很顺利。 I have to monitor the server for a few days, but i am confident my problem is solved. 我必须监控服务器几天,但我相信我的问题已经解决了。

Thanks all for thinking with me. 谢谢大家和我一起思考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM