【问题标题】:High CPU usage on server by MySQL on AWS ubuntu serverAWS ubuntu 服务器上的 MySQL 在服务器上的 CPU 使用率很高
【发布时间】:2018-11-19 18:52:32
【问题描述】:

MySQL 显示出非常高的 CPU 使用率。有时超过 200%。 我的查询登录速度很慢。并且慢查询时间设置为1s。 没有任何慢查询。 我正在使用代码点火器 PHP。

我的 my.cnf 文件:

[mysqld]
innodb_io_capacity=2000
innodb_read_io_threads=32
innodb_write_io_threads=32
innodb_log_buffer_size=250M
innodb_thread_concurrency=0
innodb_buffer_pool_size=1000M
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
##
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address       = 127.0.0.1
#
# * Fine Tuning
#
innodb_buffer_pool_size = 12G
key_buffer_size     = 1G
max_allowed_packet  = 256M
thread_stack        = 192K
thread_cache_size       = 100
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
max_connections        = 300


#innodb_buffer_pool_instances=8
#innodb_read_io_threads=8
#innodb_write_io_threads=8

#open_files_limit = 1024
#table_open_cache = 400
server_id           = 2
bind-address        = 0.0.0.0
log_bin             = /var/log/mysql/mysql-bin.log
log_bin_index       = /var/log/mysql/mysql-bin.log.index
relay_log           = /var/log/mysql/mysql-relay-bin
relay_log_index     = /var/log/mysql/mysql-relay-bin.index
expire_logs_days    = 10
max_binlog_size     = 100M
log_slave_updates   = 1
auto-increment-increment = 2
auto-increment-offset = 2
replicate-ignore-db=phpmyadmin
replicate-ignore-db=mysql
skip-name-resolve
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit=0
query_cache_size=0

sort_buffer_size = 2M
join_buffer_size = 128K
read_buffer_size = 128K
read_rnd_buffer_size=256K

我可以做些什么来减少 CPU 使用率? 有什么方法可以找到导致 CPU 使用率高的查询 o

【问题讨论】:

  • PHP 和 CI 标签是否相关?
  • 我不知道 CI 方面的某些东西是否会导致这种情况我尝试了我在 MySQL 网站上可以在 Internet 上找到的所有内容,所以我认为可能对 CI 有很好了解的人可以帮助我,如果他们有之前遇到过这个问题

标签: php mysql amazon-ec2 codeigniter-3


【解决方案1】:

没有慢查询

没有慢查询,或者日志中没有显示慢查询?我认为您的第一个呼叫将是检查查询日志记录是否按预期工作。这可以使用任意锁轻松完成,而不会增加系统的额外负载。

假设确实没有超过 1 秒的查询,那么负载会来自许多耗时不到 1 秒的查询。您需要将它们全部捕获,以识别和优先考虑您的调整工作。但您可以从启用查询缓存开始(由于某种原因您已禁用)。

【讨论】:

  • 我通过运行 SELECT SLEEP(2); 来测试它。并且该查询已登录
  • 是的,你是对的。我的 PHP for 循环代码中有一个函数可以触发查询。因此,如果有 1000 名玩家处于活动状态,则此循环会触发相同的查询 1000 次。我转换了我的代码,现在没有查询在 for 循环中运行,现在我的 sql cpu 使用率低于 5%
  • @DesiMulga 请发布您的 BEFORE 和 AFTER 代码,以便我们实际查看您的解决方案。感谢您考虑分享这个详细的简单更改。
猜你喜欢
  • 2018-07-08
  • 2020-03-31
  • 1970-01-01
  • 2015-08-05
  • 1970-01-01
  • 2013-09-20
  • 1970-01-01
  • 2012-12-11
相关资源
最近更新 更多