gpt4 book ai didi

php - 通常平静的网络服务器有 CPU 尖峰与 MySQL 上的某些查询

转载 作者:行者123 更新时间:2023-11-30 21:57:48 25 4
gpt4 key购买 nike

我已将网站从 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,看起来现在一切正常。我必须监控服务器几天,但我相信我的问题已经解决。

谢谢大家和我一起思考。

关于php - 通常平静的网络服务器有 CPU 尖峰与 MySQL 上的某些查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44476083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com