【问题标题】:Mysql Server high CPU load and high memory usageMysql Server高CPU负载和高内存使用
【发布时间】:2022-01-18 14:39:24
【问题描述】:

大家好, 我有一个 Cpanel VPS 服务器,详细信息如下: 8核CPU | 32GB 内存 | 450GB SSDVME Cpanel V100.0.5 on CentOS v7.9.2009 Mysql V8.0 Litespeed 服务器 Web Host Professional (2-Worker) License (with LSCache Standard) 我将此服务器用作共享主机,并且有一些流量很高的网站。 我尝试了很多方法并阅读了很多文章以获得最佳性能,但不幸的是服务器总是有很高的平均负载,MYSQL 服务器 cpu 负载超过 100% 并且使用 30GB 内存!!!!!! 这是 my.cnf 文件:

[mysqld]
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
bind_address            = 127.0.0.1
max_connections         = 100
max_user_connections    = 80
wait_timeout            = 300
interactive_timeout     = 300
disable-log-bin=1
default-authentication-plugin=mysql_native_password
performance-schema=0
key-buffer-size=2G
join_buffer_size = 32M
sort_buffer_size = 16M
read_buffer_size = 16M
read_rnd_buffer_size = 128M
thread_stack        = 8M
thread_cache_size       = 8
myisam_sort_buffer_size = 512M
thread_stack            = 5M
thread_cache_size       = 32
max_binlog_size         = 100M
max_heap_table_size = 2048M
tmp_table_size      = 2048M
table_open_cache    = 3072
table_definition_cache  = 8200
skip-name-resolve   =1
performance_schema  = ON
concurrent_insert   = ALWAYS
low_priority_updates    = 1
default-storage-engine=InnoDB
innodb_buffer_pool_size=24G
innodb_buffer_pool_instances = 24
innodb_file_per_table       = 1
innodb_log_file_size            = 3072M
innodb_log_files_in_group       = 2
innodb_log_buffer_size      = 128M
innodb_log_file_size = 64M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
max_allowed_packet=268435456
open_files_limit=40000
default-storage-engine=innodb
event_scheduler = OFF
mysqlx=0
slow-query-log=1
slow-query-log-file= /var/lib/mysql/mysql-slow-query.log
long-query-time=1

这是顶部显示的内容:

top - 18:07:10 up  4:51,  1 user,  load average: 23.36, 21.19, 15.64
Tasks: 266 total,  15 running, 248 sleeping,   3 stopped,   0 zombie
%Cpu(s): 30.1 us, 21.3 sy, 47.7 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.8 si,  0.0 st
KiB Mem : 32780000 total,  5730248 free, 10833944 used, 16215808 buff/cache
KiB Swap: 15626236 total, 15626236 free,        0 used. 20516092 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
22844 mysql     20   0   32.6g   4.5g  18028 S 269.9 14.4 252:39.28 mysqld
 6908 liliome   30  10 1036500 101008  46684 R  32.8  0.3   0:29.10 lsphp
 7536 liliome   30  10 1038428 101556  45348 R  26.2  0.3   0:23.27 lsphp
 8911 parfuma   30  10 1141864 125180  39784 S  26.2  0.4   0:01.63 lsphp
 7556 liliome   30  10 1036164  99384  45528 S  24.2  0.3   0:23.72 lsphp
 8850 parfuma   30  10 1048088 105052  39616 R  24.2  0.3   0:02.70 lsphp
 6523 liliome   30  10 1038872 103252  46596 R  23.8  0.3   0:33.37 lsphp
 8948 parfuma   30  10 1068108 124128  38948 S  23.5  0.4   0:01.45 lsphp
 8937 liliome   30  10 1033132  92788  41868 R  21.5  0.3   0:01.23 lsphp
    1 root      20   0   50352  10916   4192 R  21.2  0.0  11:31.33 systemd
 7278 liliome   30  10 1038464 100944  45908 R  21.2  0.3   0:28.64 lsphp
 7434 liliome   30  10 1036336  99804  45672 R  20.9  0.3   0:24.50 lsphp
 8522 liliome   30  10 1040252 103176  45544 R  16.9  0.3   0:07.71 lsphp
 8708 parfuma   30  10 1058200 115912  39700 S  15.6  0.4   0:04.85 lsphp
 8936 parfuma   30  10 1070156 124580  39068 S  15.6  0.4   0:01.40 lsphp
 8484 liliome   30  10 1038604 101160  45756 R  14.2  0.3   0:07.59 lsphp
 9008 negroupi  30  10 1008676  62644  37076 S  12.3  0.2   0:00.37 lsphp

this is process manaer report 请让我知道你们还需要什么来帮助我优化服务器以获得最佳性能:)

提前致谢

【问题讨论】:

  • 这能回答你的问题吗? MySQL not releasing memory
  • TOP 报告显示任务 15 正在运行和 248 处于睡眠状态,这引发了 2 个需要考虑的问题。请发布 iostat -xm 5 3 的操作系统命令提示符的 TEXT 结果,按设备和核心/cpu 计数计算 IOPS,以查看 15 个正在运行的任务对于您的核心计数是否合理。 248 个休眠任务表示您的 Connect、Process、Close 代码中缺少 CLOSE,以在完成用户的工作单元时管理释放资源。发布提供这 3 个功能的代码可能会让某人有机会建议 CLOSE 放置..
  • 嗨,感谢您的帮助,设备:rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util fd0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 SDA 0.00 0.00 0.00 6.80 87.20 0.06 1.81 40.93 0.24 2.59 1.97 1.97 2.64 1.40 13.12 DM-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 cover the I i i i sper y i ioState >
  • 您可以发布用于连接、处理、关闭客户端连接的代码吗?发布的 IOSTAT 不可读。在每行的开头放置 4 个空格,我们应该能够读取结果。应该有至少 12 行输出 - 在 3 个周期的每个周期之间持续 5 秒 delav。
  • 请您发布一份新的 TOP 报告,在更改 4 个全局变量后的第一页进行比较。

标签: mysql


【解决方案1】:

将这些降低到不超过 RAM 的 1%:

max_heap_table_size = 2048M  --> 200M
tmp_table_size      = 2048M  --> 200M

这将有助于防止交换,这可能会影响性能。

然后让我们讨论一下你最慢的查询;请务必包含EXPLAINSHOW CREATE TABLE

【讨论】:

  • 您好,首先,感谢您的帮助,我已经进行了更改,但没有真正更改任何内容:) 仍然具有相同的负载和内存使用率
  • 那么我们需要看看一些慢查询。更多:mysql.rjweb.org/doc.php/mysql_analysis#slow_queries_and_slowlog
  • 能否请您提供更多详细信息,在这种情况下我不是那么专业
【解决方案2】:

每秒速率 = RPS

考虑在您的配置中禁用这 4 个值,方法是使用以下行开头 (井号)# 和空格字符。

join_buffer_size = 32M
sort_buffer_size = 16M
read_buffer_size = 16M
read_rnd_buffer_size = 128M

您可能会发现 Handler_read_next 和 Handler_read_rnd_next RPS 将显着降低。很少需要增加这 4 个全局变量的默认值。

如果您需要进一步的帮助,请查看个人资料以获取联系信息。

【讨论】:

  • 嗨,实际上并没有太大变化......仍然使用 30GB 或内存,但我猜 cpu 负载有点下降
  • 请提供更多信息。在 pastebin.com 上发布并分享链接。从您的 SSH 登录根目录中,文本结果为:A) SELECT COUNT(*) FROM information_schema.tables; B) 显示全球状态;至少 24 小时正常运行时间后 C) 显示全局变量; D) 显示完整的处理程序; E) 状态;不显示状态,只是状态; G) 显示 ENGINE INNODB 状态;为服务器工作负载调优分析提供建议。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-29
  • 2012-05-14
  • 1970-01-01
  • 1970-01-01
  • 2021-02-04
  • 2014-03-16
  • 1970-01-01
相关资源
最近更新 更多