简体   繁体   中英

Usually calm webserver has CPU spikes with certain query on MySQL

I have moved websites from Windows 2008R2 to 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. And there is where it goes wrong. Now MySQL gobbles up 100% CPU and the server has no time to serve - even cached - websites.

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.

My current situation:

  • Intel Xeon L5640
  • 6GB internal memory
  • Windows 2012R2 IIS8.5 x64
  • PHP7.1.1 x64
  • MySQL 5.5 x64

My current 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. And most of the time CPU does not exceeds 40%, so that's not realy the problem, i guess.

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. I have to monitor the server for a few days, but i am confident my problem is solved.

Thanks all for thinking with me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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