2

在我的配置innodb_flush_method=O_DSYNC中,O-DIRECTiowait 减少了大约 75%,因此负载。我应该设置除 innodb_flush_method 之外的其他变量来减少更多的 iowait 吗?

我的配置文件是:

[mysqld]
innodb_file_per_table=1
query_cache_size=128M
thread_cache_size=64
key_buffer_size=32M
max_allowed_packet=16M
table_cache=1024
table_definition_cache=8192
wait_timeout=20
max_user_connections=25
innodb_flush_method=O_DSYNC
open_files_limit=16384

myisam_sort_buffer_size=2M

collation_server=utf8_unicode_ci
character_set_server=utf8

tmp_table_size = 384M
max_heap_table_size = 384M
innodb_buffer_pool_size=64M
innodb_thread_concurrency=8
max_connections=125

我有一个包含 100 个 Innodb 表的数据库,其中 3 个有大约 25000 条记录,其他的没有重要记录。高峰期的平均查询数约为 160,大部分是SELECT

4

1 回答 1

6

innodb_buffer_pool_size

主要问题是innodb_buffer_pool_size太小了。推荐设置为主内存的 50~75%。

innodb_buffer_pool_size=64M

我强烈建议你应该增加它的价值。

一般来说,O_DIRECT速度有点快,因为 InnoDB Buffer Pool 缓存 Data+Index,所以O_DIRECT禁用 File System Page Cache 会更快。MySQL手册说(http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#sysvar_innodb_flush_method

根据硬件配置,将 innodb_flush_method 设置为 O_DIRECT 会对性能产生正面或负面影响。对您的特定配置进行基准测试以决定使用哪个设置。

但根据我的经验,O_DIRECT 和 O_DSYNC 之间没有显着差异。SSD 和 HDD 都经过测试。

无论如何你应该增加innodb_buffer_pool_size.

计算 innodb 缓冲池命中率

mysql> SHOW GLOBAL STATUS LIKE '%innodb%';
+---------------------------------------+-------------+
| Variable_name                         | Value       |
+---------------------------------------+-------------+
.....
.....
| Innodb_buffer_pool_read_requests      | 11054273949 |
| Innodb_buffer_pool_reads              | 135237      |
| Innodb_buffer_pool_wait_free          | 0           |
....

innodb buffer pool hit ratio = ((Innodb_buffer_pool_read_requests) / (Innodb_buffer_pool_read_requests + Innodb_buffer_pool_reads)) * 100

例如上面的例子,

hit ratio = (11054273949  / (11054273949  + 135237)) * 100 = 99.99%

我认为这个值在你的情况下太小了。

查询缓存大小

“大多数是选择”

如果大多数查询是 SELECT 并且更新查询很少,我认为增加query_cache_size对您很有帮助。

你能发布你query cache status的如下吗?

mysql> show global status like 'Qc%';
+-------------------------+------------+
| Variable_name           | Value      |
+-------------------------+------------+
| Qcache_free_blocks      | 13         |
| Qcache_free_memory      | 1073403104 |
| Qcache_hits             | 217949     |
| Qcache_inserts          | 337009     |
| Qcache_lowmem_prunes    | 0          |
| Qcache_not_cached       | 2122598    |
| Qcache_queries_in_cache | 68         |
| Qcache_total_blocks     | 167        |
+-------------------------+------------+

mysql> show global status like 'com_select%';
+---------------+---------+
| Variable_name | Value   |
+---------------+---------+
| Com_select    | 3292531 |
+---------------+---------+
1 row in set (0.00 sec)

计算 innodb 缓冲池命中率

 query cache hit ratio = ((Qcache_hits) / (Qcache_hits + Com_select)) * 100

首先,弄清楚你的查询缓存命中率。

于 2013-12-20T12:17:45.790 回答