Wordpress + php + mysql 高pu使用率

问题描述 投票:-1回答:1

我正在使用 字press, php 7.2mysql Ver 15.1 Distrib 10.1.44-MariaDB搭配4颗酷睿i7 CPU和10GB Ram,运行在以下设备上。ubuntu 18.04 LTS. 问题是即使在低负载的情况下,比如每秒有5个用户,所有4个CPU都会飙升到100%,并且持续存在。过了一段时间,CPU都满了,我只得到错误500。另外,我所有的模块都是最新的。

我试着禁用wordpress中的所有插件,并运行同样的测试,但问题依然存在。

我也使用了一些插件来优化数据库,比如说 wp-optimize但没有运气。这 /var/log/mysql/mysql-slow.log 文件也是空的。

包括htop在内,只用了几秒钟就完成了负载测试的结果。

Datadog的相关测试的监控仪表盘。

如上图所示,你可以理解为...。mysqld 正在无缘无故地使用过多的CPU。

我还运行了 mysqltuner 这就是结果。

 >>  MySQLTuner 1.7.19 - Major Hayden <[email protected]>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[OK] Logged in using credentials passed on the command line
[OK] Currently running supported MySQL version 10.1.44-MariaDB-0ubuntu0.18.04.1
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ------------------------------------------------------------------
[OK] Log file /var/log/mysql/error.log exists
[--] Log file: /var/log/mysql/error.log(7K)
[OK] Log file /var/log/mysql/error.log is readable.
[OK] Log file /var/log/mysql/error.log is not empty
[OK] Log file /var/log/mysql/error.log is smaller than 32 Mb
[!!] /var/log/mysql/error.log contains 8 warning(s).
[!!] /var/log/mysql/error.log contains 3 error(s).
[--] 3 start(s) detected in /var/log/mysql/error.log
[--] 1) 2020-05-09 12:36:17 139638727916672 [Note] /usr/sbin/mysqld: ready for connections.
[--] 2) 2020-05-09 12:28:42 140719406492800 [Note] /usr/sbin/mysqld: ready for connections.
[--] 3) 2020-05-09 10:52:43 139784491093120 [Note] /usr/sbin/mysqld: ready for connections.
[--] 2 shutdown(s) detected in /var/log/mysql/error.log
[--] 1) 2020-05-09 12:32:02 140713171822336 [Note] /usr/sbin/mysqld: Shutdown complete
[--] 2) 2020-05-09 10:53:00 139784442357504 [Note] /usr/sbin/mysqld: Shutdown complete

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +Aria +CSV +InnoDB +MEMORY +MRG_MyISAM +MyISAM +PERFORMANCE_SCHEMA +SEQUENCE
[--] Data in InnoDB tables: 112.0K (Tables: 4)
[--] Data in MyISAM tables: 38.7M (Tables: 52)
[OK] Total fragmented tables: 0

-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[!!] There is no basic password file list!

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 48m 13s (73K q [25.317 qps], 1K conn, TX: 978M, RX: 11M)
[--] Reads / Writes: 96% / 4%
[--] Binary logging is disabled
[--] Physical Memory     : 9.8G
[--] Max MySQL memory    : 10.6G
[--] Other process memory: 0B
[--] Total buffers: 4.7G global + 6.9M per thread (800 max threads)
[--] P_S Max memory usage: 511M
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 6.5G (67.07% of installed RAM)
[!!] Maximum possible memory usage: 10.6G (108.28% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (0/73K)
[OK] Highest usage of available connections: 25% (204/800)
[!!] Aborted connections: 10.65%  (193/1812)
[OK] Query cache is disabled by default due to mutex contention on multiprocessor machines.
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 12K sorts)
[OK] No joins without indexes
[!!] Temporary tables created on disk: 83% (2K on disk / 3K total)
[OK] Thread cache hit rate: 84% (284 created / 1K connections)
[OK] Table cache hit rate: 97% (222 open / 228 opened)
[OK] table_definition_cache(400) is upper than number of tables(303)
[OK] Open file limit used: 6% (304/4K)
[!!] Table locks acquired immediately: 84%

-------- Performance schema ------------------------------------------------------------------------
[--] Memory used by P_S: 511.6M
[--] Sys schema is installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is enabled.
[--] Thread Pool Size: 4 thread(s).
[--] Using default value is good enough for your version (10.1.44-MariaDB-0ubuntu0.18.04.1)

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.4% (24M used / 134M cache)
[OK] Key buffer size / total MyISAM indexes: 128.0M/10.0M
[OK] Read Key buffer hit rate: 100.0% (695K cached / 152 reads)
[OK] Write Key buffer hit rate: 100.0% (18 cached / 18 writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 3.9G/112.0K
[OK] Ratio InnoDB log file size / InnoDB Buffer pool size: 500.0M * 2/3.9G should be equal to 25%
[OK] InnoDB buffer pool instances: 3
[--] InnoDB Buffer Pool Chunk Size not used or defined in your version
[!!] InnoDB Read buffer efficiency: 85.36% (1493 hits/ 1749 total)
[!!] InnoDB Write Log efficiency: 0% (1 hits/ 0 total)
[OK] InnoDB log waits: 0.00% (0 waits / 1 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is enabled.
[OK] Aria pagecache size / total Aria indexes: 128.0M/1B
[!!] Aria pagecache hit rate: 89.4% (26K cached / 2K reads)

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] Binlog format: STATEMENT
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    Control warning line(s) into /var/log/mysql/error.log file
    Control error line(s) into /var/log/mysql/error.log file
    MySQL was started within the last 24 hours - recommendations may be inaccurate
    Reduce your overall MySQL memory footprint for system stability
    Dedicate this server to your database for highest performance.
    Reduce or eliminate unclosed connections and network issues
    Temporary table size is already large - reduce result set size
    Reduce your SELECT DISTINCT queries without LIMIT clauses
    Optimize queries and/or use InnoDB to reduce lock wait

mysql 配置 /etc/mysqld/my.cnf:

[mysqld]
general_log = on
skip-name-resolve
innodb_read_io_threads=4
innodb_write_io_threads=4
general_log_file = /var/log/mysql/mysql.log
log_error=/var/log/mysql/mysql_error.log
#
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                        = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
#
# * InnoDB
innodb_buffer_pool_size= 4000M
max_connections =800
wait_timeout=100
interactive_timeout=100
query_cache_size=0
query_cache_type=0
query_cache_limit=2M
tmp_table_size=500M
max_heap_table_size=500M
thread_cache_size=4
performance_schema=ON
innodb_log_file_size=500M
innodb_buffer_pool_instances=3
innodb_autoinc_lock_mode = 2

/var/log/mysql/error.log

2020-05-09 12:36:16 139638727916672 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2020-05-09 12:36:16 139638727916672 [Note] InnoDB: The InnoDB memory heap is disabled
2020-05-09 12:36:16 139638727916672 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-05-09 12:36:16 139638727916672 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2020-05-09 12:36:16 139638727916672 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-05-09 12:36:16 139638727916672 [Note] InnoDB: Using Linux native AIO
2020-05-09 12:36:16 139638727916672 [Note] InnoDB: Using SSE crc32 instructions
2020-05-09 12:36:16 139638727916672 [Note] InnoDB: Initializing buffer pool, size = 3.9G
2020-05-09 12:36:16 139638727916672 [Note] InnoDB: Completed initialization of buffer pool
2020-05-09 12:36:16 139638727916672 [Note] InnoDB: Highest supported file format is Barracuda.
2020-05-09 12:36:17 139638727916672 [Note] InnoDB: 128 rollback segment(s) are active.
2020-05-09 12:36:17 139638727916672 [Note] InnoDB: Waiting for purge to start
2020-05-09 12:36:17 139638727916672 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.46-86.2 started; log sequence number 1832982
2020-05-09 12:36:17 139632989665024 [Note] InnoDB: Dumping buffer pool(s) not yet started
2020-05-09 12:36:17 139638727916672 [Note] Plugin 'FEEDBACK' is disabled.
2020-05-09 12:36:17 139638727916672 [Note] Server socket created on IP: '::'.
2020-05-09 12:36:17 139638727916672 [Warning] 'user' entry 'wp_user@server' ignored in --skip-name-resolve mode.
2020-05-09 12:36:17 139638727916672 [Warning] 'db' entry 'db_name wp_user@server' ignored in --skip-name-resolve mode.
2020-05-09 12:36:17 139638727916672 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.1.44-MariaDB-0ubuntu0.18.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  Ubuntu 18.04
php mysql wordpress nginx cpu
1个回答
0
投票

每秒速率=RPS

建议考虑对你的my.cnf [mysqld]部分进行修改。

thread_cache_size=256  # from 4 for default minimum
innodb_io_capacity=900  # from 200 to enable higher IOPS
read_rnd_buffer_size=128K  # from 256K to reduce handler_read_rnd_next RPS of 256
read_buffer_size=256K  # from 128K to reduce handler_read_next RPS of 828

这些变化将减少服务器上的CPU繁忙程度。 有更多的机会可以改善你的my.cnf。

观察:操作系统的交换空间为0.对于你的10GB服务器来说,6GB是合理的,并避免Out of memory.Select_scan RPhr为1546,可以通过在表上使用适当的索引来减少。在www.mysqlservertuning.com,在我们的FAQ页面上,我们有关于Q的提示。我如何找到JOINS或QUERIES不使用索引?以提高响应时间,并通过使用索引来减少CPU繁忙百分比。

© www.soinside.com 2019 - 2024. All rights reserved.