簡體   English   中英

通常冷靜的網絡服務器具有CPU峰值,對MySQL有一定的查詢

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

我已將網站從Windows 2008R2移動到Windows 1012R2。 在新服務器上,當某個腳本啟動時,我的CPU性能會出現高峰。運行此查詢的一個連接占用55%,這不是一個真正的大問題,但是2分鍾之后會出現第二個具有相同查詢的連接。 而且它出錯了。 現在MySQL吞噬了100%的CPU,服務器沒有時間服務 - 甚至是緩存 - 網站。

這是,我認為腳本的和平是罪魁禍首:

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";}

在我的日志中有很多這些:

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

我認為這個腳本可以為搜索引擎收集單詞。 考慮到這個站點在我的舊服務器上運行完全正常,我想這應該在我更新更好的服務器上運行完美。

所以也許對MySQL有更好了解的人可以掃描我的my.ini給我看,如果有性能空間的話。

我目前的情況:

  • 英特爾至強L5640
  • 6GB內存
  • Windows 2012R2 IIS8.5 x64
  • PHP7.1.1 x64
  • MySQL 5.5 x64

我現在的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本身計算它需要9GB作為innodb_buffer_pool_size,但我的服務器現在只有6個,而mysqld.exe只使用850MB。 並且大多數時候CPU不超過40%,所以這不是真正的問題,我想。

在此先感謝您的幫助。

我去Percona並根據我的配置生成了一個ini,看起來現在一切都很順利。 我必須監控服務器幾天,但我相信我的問題已經解決了。

謝謝大家和我一起思考。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM