![](/img/trans.png)
[英]Setting innodb_flush_method to O_DIRECT on Centos 7.8
[英]mysql setting variable innodb_flush_method to O_DSYNC or O_DIRECT
在我的配置中,來自O-DIRECT
innodb_flush_method=O_DSYNC
減少了大約 75% 的 iowait,從而減少了負載。 除了 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
主要問題是innodb_buffer_pool_size
太小。 建議設置為主內存的 50~75%。
innodb_buffer_pool_size=64M
我強烈建議你應該增加它的價值。
一般來說, O_DIRECT
有點快,因為 InnoDB 緩沖池緩存數據+索引,所以禁用O_DIRECT
文件系統頁面緩存更快。 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
。
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,而update查詢很少,我覺得增加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)
query cache hit ratio = ((Qcache_hits) / (Qcache_hits + Com_select)) * 100
首先,弄清楚您的查詢緩存命中率。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.