简体   繁体   English

mysql 将变量 innodb_flush_method 设置为 O_DSYNC 或 O_DIRECT

[英]mysql setting variable innodb_flush_method to O_DSYNC or O_DIRECT

In my configuration innodb_flush_method=O_DSYNC from O-DIRECT reduces about 75% the iowait, and accordingly this the load.在我的配置中,来自O-DIRECT innodb_flush_method=O_DSYNC减少了大约 75% 的 iowait,从而减少了负载。 Should I set another variables besides innodb_flush_method to reduce more the iowait?除了 innodb_flush_method 之外,我应该设置另一个变量来减少更多的 iowait 吗?

My configuration file is:我的配置文件是:

[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

I have a database with 100 Innodb tables, 3 of them has about 25000 records, the others has no significant records.我有一个包含 100 个 Innodb 表的数据库,其中 3 个有大约 25000 条记录,其他没有重要记录。 The average queries in peak time is about 160, the majority is SELECT高峰期平均查询160左右,大部分是SELECT

innodb_buffer_pool_size innodb_buffer_pool_size

Major problem is innodb_buffer_pool_size is too small.主要问题是innodb_buffer_pool_size太小。 Recommandation is set to 50~75% of main memory.建议设置为主内存的 50~75%。

innodb_buffer_pool_size=64M

I strongly recommand that you should increase it's value.我强烈建议你应该增加它的价值。

Generally speaking, O_DIRECT is little bit fast because InnoDB Buffer Pool caches Data+Index, So with O_DIRECT disabled File System Page Cache is faster.一般来说, O_DIRECT有点快,因为 InnoDB 缓冲池缓存数据+索引,所以禁用O_DIRECT文件系统页面缓存更快。 MySQL Manaual says ( http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#sysvar_innodb_flush_method ) MySQL 手册说( http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#sysvar_innodb_flush_method

Depending on hardware configuration, setting innodb_flush_method to O_DIRECT can either have either a positive or negative effect on performance.根据硬件配置,将 innodb_flush_method 设置为 O_DIRECT 可以对性能产生积极或消极影响。 Benchmark your particular configuration to decide which setting to use.对您的特定配置进行基准测试以确定要使用的设置。

But in my experience, there was no significant difference between O_DIRECT and O_DSYNC.但根据我的经验,O_DIRECT 和 O_DSYNC 之间没有显着差异。 Both SSD and HDD are test. SSD和HDD都经过测试。

Anyway you should increase innodb_buffer_pool_size .无论如何你应该增加innodb_buffer_pool_size

Calculating innodb buffer pool hit ratio计算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

Eg above examples,例如上面的例子,

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

I think this value is too small in your case.我认为这个值在你的情况下太小了。

query_cache_size查询缓存大小

"the majority is SELECT" “大多数是选择”

If most queries are SELECT and update query is rare, I think increasing query_cache_size is very helpful for you.如果大部分查询都是SELECT,而update查询很少,我觉得增加query_cache_size对你很有帮助。

Could you post your query cache status as follows?你能发布你的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)

Calculating innodb buffer pool hit ratio计算innodb缓冲池命中率

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

first, figure out your query cache hit ratio.首先,弄清楚您的查询缓存命中率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM