我有 MySQL 服务器 5.6,我使用压力测试来评估它的性能。测试后mysqltuner.pl的结果如下:

root@master-1:/home/debian# perl mysqltuner.pl
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password:  >>  MySQLTuner 1.6.4 - Major Hayden <major@mhtx.net>
 >>  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] Currently running supported MySQL version 5.6.29-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM 
[--] Data in InnoDB tables: 34G (Tables: 29)
[!!] Total fragmented tables: 4

-------- 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: 1h 56m 26s (4M q [592.634 qps], 398 conn, TX: 8B, RX: 6B)
[--] Reads / Writes: 81% / 19%
[--] Binary logging is enabled (GTID MODE: OFF)
[--] Total buffers: 1.0G global + 1.1M per thread (8190 max threads)
[OK] Maximum reached memory usage: 1.1G (4.63% of installed RAM)
[OK] Maximum possible memory usage: 9.5G (40.45% of installed RAM)
[OK] Slow queries: 0% (0/4M)
[OK] Highest usage of available connections: 0% (44/8190)
[OK] Aborted connections: 0.75%  (3/398)
[!!] Query cache is disabled
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 2 sorts)
[OK] Temporary tables created on disk: 0% (0 on disk / 27 total)
[OK] Thread cache hit rate: 84% (62 created / 398 connections)
[OK] Table cache hit rate: 75% (309 open / 408 opened)
[OK] Open file limit used: 0% (54/9K)
[OK] Table locks acquired immediately: 100% (4M immediate / 4M locks)
[OK] Binlog cache memory access: 100.00% ( 704225 Memory / 704225 Total)

-------- MyISAM Metrics ------------------------------------------------------
[!!] Key buffer used: 18.2% (3M used / 16M cache)
[OK] Key buffer size / total MyISAM indexes: 16.0M/95.0K
[!!] Read Key buffer hit rate: 80.0% (5 cached / 1 reads)

-------- InnoDB Metrics ------------------------------------------------------
[--] InnoDB is enabled.
[!!] InnoDB buffer pool / data size: 512.0M/34.2G
[!!] InnoDB buffer pool <= 1G and innodb_buffer_pool_instances(!=1).
[OK] InnoDB Used buffer: 96.95% (31769 used/ 32767 total)
[OK] InnoDB Read buffer efficiency: 99.83% (94182005 hits/ 94340114 total)
[!!] InnoDB Write buffer efficiency: 0.00% (0 hits/ 1 total)
[OK] InnoDB log waits: 0.00% (0 waits / 178758 writes)

-------- ThreadPool Metrics --------------------------------------------------
[--] ThreadPool stat is disabled.

-------- AriaDB Metrics ------------------------------------------------------
[--] AriaDB is disabled.

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

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

-------- Replication Metrics -------------------------------------------------
[--] This server is acting as master for 2 server(s).
[!!] This replication slave is running with the read_only option disabled.
[OK] This replication slave is up to date with master.

-------- Recommendations -----------------------------------------------------

然后我停止压力测试脚本,我发现内存几乎已满,MySQL 不会释放它(即使在一天没有任何查询并重新启动 MySQL 之后),类似于内存泄漏或错误。在 my.cnf 中,缓冲区大小为 innodb_buffer_pool_size=512M,在将其更改为 2G 后,但没有任何帮助。在 这个 教程中,我使用了以下命令,但我看到了一些不好的东西:

询问:

select
page_type as Page_Type,
sum(data_size)/1024/1024 as Size_in_MB
from information_schema.innodb_buffer_page
group by page_type
order by Size_in_MB desc;

结果 :

+--------------------------------+------------+------------+------------+
| Table_Name                     | Index_Name | Page_Count | Size_in_MB |
+--------------------------------+------------+------------+------------+
| `SYS_COLUMNS`                  | CLUST_IND  |          1 | 0.01321316 |
| `SYS_INDEXES`                  | CLUST_IND  |          1 | 0.00615215 |
| `SYS_FIELDS`                   | CLUST_IND  |          1 | 0.00364017 |
| `SYS_TABLES`                   | CLUST_IND  |          1 | 0.00293446 |
| `SYS_FOREIGN`                  | FOR_IND    |          1 | 0.00023651 |
| `SYS_FOREIGN`                  | REF_IND    |          1 | 0.00022316 |
| NULL                           | NULL       |     131055 | 0.00000000 |
| `mysql`.`slave_relay_log_info` | PRIMARY    |          1 | 0.00000000 |
| `mysql`.`slave_master_info`    | PRIMARY    |          1 | 0.00000000 |
| `mysql`.`slave_worker_info`    | PRIMARY    |          1 | 0.00000000 |
+--------------------------------+------------+------------+------------+
10 rows in set (1.49 sec)

如您所见,一行是 NULL 并且有 131055 page_count。 缓冲池中页面类型的结果如下:

询问:

select
page_type as Page_Type,
sum(data_size)/1024/1024 as Size_in_MB
from information_schema.innodb_buffer_page
group by page_type
order by Size_in_MB desc;

结果:

+-------------------+------------+
| Page_Type         | Size_in_MB |
+-------------------+------------+
| INDEX             | 0.02639961 |
| IBUF_INDEX        | 0.00000000 |
| INODE             | 0.00000000 |
| IBUF_BITMAP       | 0.00000000 |
| SYSTEM            | 0.00000000 |
| UNKNOWN           | 0.00000000 |
| FILE_SPACE_HEADER | 0.00000000 |
| UNDO_LOG          | 0.00000000 |
| TRX_SYSTEM        | 0.00000000 |
+-------------------+------------+
9 rows in set (1.04 sec)

htop 的结果如下:

enter image description here

当 MySQL 服务器上没有任何负载时,您可以看到缓存大小使用情况和 mysqld 个进程。

我不明白为什么没有释放内存(缓存),或者我想知道这是否是一个错误。

有帮助吗?

解决方案

key_buffer(用于缓存 MyISAM索引 innodb_buffer_pool(用于 InnoDB 数据索引)增长到 my.cnf 中指示的最大值;之后它们不会缩小。这不是内存泄漏。两者都是缓存

我希望你只使用 InnoDB。如果是这样,请使用以下设置:

key_buffer_size = 40M       -- the system tables need it
innodb_buffer_pool_size =   -- about 70% of available RAM.

忽略 Tuner 提到的“碎片化”表;这是假的。

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top