Mysqld消耗232%的CPU

时间:2019-03-26 07:24:57

标签: mysql connection innodb

我的mysqld进程消耗232%的CPU,并且有14000+个连接

(我对这个东西有些陌生,但在Stack Overflow寻求帮助之后)。

顶部:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 3112 mysql     20   0 7061444 1.397g  15848 S 232.6  8.9   1138:06 mysqld

系统:  Ubuntu 18.04,  16GB RAM,  8核CPU,  120GB磁盘  和MySQL版本5.7.25

mysql> show status like 'Conn%';
+-----------------------------------+-------+
| Variable_name                     | Value |
+-----------------------------------+-------+
| Connection_errors_accept          | 0     |
| Connection_errors_internal        | 0     |
| Connection_errors_max_connections | 0     |
| Connection_errors_peer_address    | 0     |
| Connection_errors_select          | 0     |
| Connection_errors_tcpwrap         | 0     |
| Connections                       | 14007 |
+-----------------------------------+-------+
7 rows in set (0.01 sec)

并显示“%timeout%”之类的变量

mysql> show variables like "%timeout%";
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 28800    |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| wait_timeout                | 28800    |
+-----------------------------+----------+
13 rows in set (0.01 sec)

和mysqld.cnf设置

[mysqld]
# Skip reverse DNS lookup of clients
skip-name-resolve
default-storage-engine=InnoDB

max_allowed_packet=500M
max_connections = 256
interactive_timeout=7200
wait_timeout=7200

innodb_file_per_table=1
innodb_buffer_pool_size = 8G
innodb_buffer_pool_instances = 4
innodb_log_file_size = 1G
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
innodb_open_files=5000
innodb_io_capacity=2000
innodb_io_capacity_max=4000
innodb_old_blocks_time=2000
open_files_limit=50000

query_cache_type = 1
query_cache_min_res_unit = 1M
query_cache_limit = 1M
query_cache_size = 50M

tmp_table_size= 256M
max_heap_table_size= 256M

#key_buffer_size = 128M
thread_stack = 128K
thread_cache_size = 32

slow-query-log = 1
slow-query-log-file = /var/lib/mysql/mysql-slow.log
long_query_time = 1
  

注意:已更正mysqld.cnf值之上的内容,以与所附的以下报告相匹配

其他信息:

在执行多个数据库事务时服务器冻结。有锁之类的东西还是任何配置缺陷?

(背景:这是一个WordPress博客,现在没有人在访问它。我不知何故从一个旧博客中导入了11.5万个帖子,但被这个CPU幽灵击中了)

2 个答案:

答案 0 :(得分:1)

每秒速率= RPS-有关my.cnf [mysqld]部分的建议,

innodb_lru_scan_depth=100  # from 1024 to reduce 90% of cpu cycles used for function every SECOND
innodb_io_capacity=3500  # from 2000 to enable higher IOPS on your SSD devices
innodb_flushing_avg_loops=5  # from 30 to reduce innodb_buffer_pool_pages_dirty overhead - count was 3183 in SGStatus
read_buffer_size=256K  # from 128K to reduce handler_read_next RPS of 277,134
read_rnd_buffer_size=192K  # from 256K to reduce handler_read_rnd_next RPS of 778

还有更多机会可以通过“全局变量”来改善性能。 免责声明:我是个人资料中提到的网站的作者,该个人资料包括联系信息。

答案 1 :(得分:0)

[1] 2 4的架构不良可能是导致CPU过多和性能下降的原因。我将讨论补救方法here

同时,“您无法摆脱性能问题”。我看了一眼设置-都是“合理的”。