我的服务器开始表现出与内存使用相关的新行为。
它的使用率曾经稳定在 40% 左右,但现在它全天稳步上升,在午夜达到约 58%,然后在当地时间午夜时分立即回落到 40%。
我猜这类似于 MySQL 删除了一些缓存数据,但我想确定一下。特别是,午夜时分发生了什么?我当时没有安排任何 cron 作业。我如何检查 mysqld 运行清理任务的时间?
这是一台主要运行 apache2 和 mysql 的 Ubuntu 20 服务器。
mysqltuner.pl 输出如下:
>> MySQLTuner 2.0.1
* Jean-Marie Renouard <[email protected]>
* Major Hayden <[email protected]>
>> Bug reports, feature requests, and downloads at http://mysqltuner.pl/
>> Run with '--help' for additional options and output filtering
[--] Skipped version check for MySQLTuner script
[OK] Logged in using credentials from Debian maintenance account.
[OK] Currently running supported MySQL version 8.0.30-0ubuntu0.20.04.2
[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 (0B)
[--] Log file /var/log/mysql/error.log is empty. Assuming log-rotation. Use --server-log={file} for explicit file
-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in InnoDB tables: 1.9G (Tables: 48)
[--] Data in MyISAM tables: 6.6M (Tables: 6)
[OK] Total fragmented tables: 0
-------- Analysis Performance Metrics --------------------------------------------------------------
[--] innodb_stats_on_metadata: OFF
[OK] No stat updates during querying INFORMATION_SCHEMA.
-------- Views Metrics -----------------------------------------------------------------------------
-------- Triggers Metrics --------------------------------------------------------------------------
-------- Routines Metrics --------------------------------------------------------------------------
-------- Security Recommendations ------------------------------------------------------------------
[--] Skipped due to unsupported feature for MySQL 8
-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined
-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 14d 5h 54m 23s (82M q [66.737 qps], 9M conn, TX: 544G, RX: 17G)
[--] Reads / Writes: 50% / 50%
[--] Binary logging is enabled (GTID MODE: OFF)
[--] Physical Memory : 7.8G
[--] Max MySQL memory : 11.8G
[--] Other process memory: 0B
[--] Total buffers: 2.0G global + 65.9M per thread (151 max threads)
[--] P_S Max memory usage: 72B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 2.6G (32.96% of installed RAM)
[!!] Maximum possible memory usage: 11.8G (151.35% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (8K/82M)
[OK] Highest usage of available connections: 5% (8/151)
[OK] Aborted connections: 0.00% (0/9400218)
[--] Skipped name resolution test due to skip_networking=ON in system variables.
[--] Query cache have been removed in MySQL 8
[!!] Sorts requiring temporary tables: 26% (117K temp sorts / 448K sorts)
[OK] No joins without indexes
[OK] Temporary tables created on disk: 0% (4 on disk / 37K total)
[OK] Thread cache hit rate: 99% (8 created / 9M connections)
[OK] Table cache hit rate: 99% (76M hits / 76M requests)
[OK] table_definition_cache (2000) is greater than number of tables (394)
[OK] Open file limit used: 1% (185/10K)
[OK] Table locks acquired immediately: 99% (110K immediate / 110K locks)
[OK] Binlog cache memory access: 100.00% (35868716 Memory / 35868826 Total)
-------- Performance schema ------------------------------------------------------------------------
[--] Performance_schema is activated.
[--] Memory used by P_S: 72B
[--] Sys schema is installed.
-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.
-------- MyISAM Metrics ----------------------------------------------------------------------------
[--] MyISAM Metrics are disabled on last MySQL versions.
-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 2.0G/1.9G
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (4.6875%): 48.0M * 2/2.0G should be equal to 25%
[!!] InnoDB buffer pool instances: 8
[--] Number of InnoDB Buffer Pool Chunk: 16 for 8 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 100.00% (17684791564 hits/ 17684882383 total)
[!!] InnoDB Write Log efficiency: 71.82% (275141861 hits/ 383080665 total)
[OK] InnoDB log waits: 0.00% (0 waits / 107938804 writes)
-------- Aria Metrics ------------------------------------------------------------------------------
[--] Aria Storage Engine not available.
-------- 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: ROW
[--] XA support enabled: ON
[--] Semi synchronous replication Master: Not Activated
[--] Semi synchronous replication Slave: Not Activated
[--] This is a standalone server
-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
Reduce your overall MySQL memory footprint for system stability
Dedicate this server to your database for highest performance.
Buffer Key MyISAM set to 0, no MyISAM table detected
Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU
Variables to adjust:
*** MySQL's maximum memory usage is dangerously high ***
*** Add RAM before increasing MySQL buffer variables ***
sort_buffer_size (> 256K)
read_rnd_buffer_size (> 256K)
key_buffer_size=0
innodb_log_file_size should be (=256M) if possible, so InnoDB total log files size equals 25% of buffer pool size.
innodb_buffer_pool_instances(=2)
答案1
我认为 RAM 使用率会在午夜时分下降,因为那时 apache2 正在使用 log-rotate 来轮换日志。这会导致配置重新加载:
[Fri Aug 19 00:00:11.474987 2022] [mpm_event:notice] Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f mod_fcgid/2.3.9 configured -- resuming normal operations
对于 mpm_event 来说,这意味着未使用的进程被回收。这些进程可能为过去的连接分配了不再需要的内存。