亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

innodb_flush_method取值方法(實(shí)例講解)

 更新時(shí)間:2017年03月22日 08:33:43   投稿:jingxian  
下面小編就為大家?guī)?lái)一篇innodb_flush_method取值方法(實(shí)例講解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

innodb_flush_method的幾個(gè)典型取值

fsync: InnoDB uses the fsync() system call to flush both the data and log files. fsync is the default setting.

O_DSYNC: InnoDB uses O_SYNC to open and flush the log files, and fsync() to flush the data files. InnoDB does not use O_DSYNC directly because there have been problems with it on many varieties of Unix.

O_DIRECT: InnoDB uses O_DIRECT (or directio() on Solaris) to open the data files, and uses fsync() to flush both the data and log files. This option is available on some GNU/Linux versions,FreeBSD, and Solaris.

如何取值,mysql官方文檔是這么建議的

How each settings affects performance depends on hardware configuration and workload. Benchmark
your particular configuration to decide which setting to use, or whether to keep the default setting.
Examine the Innodb_data_fsyncs status variable to see the overall number of fsync() calls for
each setting. The mix of read and write operations in your workload can affect how a setting performs.
For example, on a system with a hardware RAID controller and battery-backed write cache, O_DIRECT
can help to avoid double buffering between the InnoDB buffer pool and the operating system's file
system cache. On some systems where InnoDB data and log files are located on a SAN, the default
value or O_DSYNC might be faster for a read-heavy workload with mostly SELECT statements. Always
test this parameter with hardware and workload that reflect your production environment

也就是說(shuō),具體的取值跟硬件配置和工作負(fù)載相關(guān),最好做一次壓測(cè)來(lái)決定。不過(guò)通常來(lái)說(shuō),linux環(huán)境下具有raid控制器和write-back寫(xiě)策略,o_direct是比較好的選擇;如果存儲(chǔ)介質(zhì)是SAN,那么使用默認(rèn)fsync或者osync或許更好一些。

通常來(lái)說(shuō),貌似絕大部分人都取值o_direct,底層有raid卡,讀寫(xiě)策略設(shè)置為write-back。在使用sysbench壓測(cè)oltp類型時(shí),我發(fā)現(xiàn)o_direct確實(shí)比f(wàn)sync性能優(yōu)秀一些,看來(lái)適用于大部分場(chǎng)景,但是最近碰到一個(gè)這樣的sql,客戶反饋很慢,而在相同內(nèi)存的情況下,它自己搭建的云主機(jī)執(zhí)行相對(duì)快很多,后來(lái)我發(fā)現(xiàn)主要就是innodb_flush_method的設(shè)置值不同帶來(lái)的巨大性能差異。

測(cè)試場(chǎng)景1

innodb_flush_method為默認(rèn)值,即fsync,緩存池512M,表數(shù)據(jù)量1.2G,排除緩存池影響,穩(wěn)定后的結(jié)果

mysql> show variables like '%innodb_flush_me%';
+---------------------+-------+
| Variable_name    | Value |
+---------------------+-------+
| innodb_flush_method |    |
+---------------------+-------+
1 row in set (0.00 sec)


mysql> SELECT sql_no_cache SUM(outcome)-SUM(income) FROM journal where account_id = '1c6ab4e7-main';
+--------------------------+
| SUM(outcome)-SUM(income) |
+--------------------------+
|        -191010.51 |
+--------------------------+
1 row in set (1.22 sec)


mysql> SELECT sql_no_cache SUM(outcome)-SUM(income) FROM journal where account_id = '1c6ab4e7-main';
+--------------------------+
| SUM(outcome)-SUM(income) |
+--------------------------+
|        -191010.51 |
+--------------------------+
1 row in set (1.22 sec)
mysql> explain SELECT sql_no_cache SUM(outcome)-SUM(income) FROM journal where account_id = '1c6ab4e7-main';
+----+-------------+---------+------+---------------+------------+---------+-------+--------+-----------------------+
| id | select_type | table  | type | possible_keys | key    | key_len | ref  | rows  | Extra         |
+----+-------------+---------+------+---------------+------------+---------+-------+--------+-----------------------+
| 1 | SIMPLE   | journal | ref | account_id  | account_id | 62   | const | 161638 | Using index condition |
+----+-------------+---------+------+---------------+------------+---------+-------+--------+-----------------------+
1 row in set (0.03 sec)

測(cè)試場(chǎng)景2

innodb_flush_method改為o_direct,排除緩存池影響,穩(wěn)定后的結(jié)果

mysql> show variables like '%innodb_flush_me%';
+---------------------+----------+
| Variable_name    | Value  |
+---------------------+----------+
| innodb_flush_method | O_DIRECT |
+---------------------+----------+
1 row in set (0.00 sec)


mysql> SELECT sql_no_cache SUM(outcome)-SUM(income) FROM journal where account_id = '1c6ab4e7-main';
+--------------------------+
| SUM(outcome)-SUM(income) |
+--------------------------+
|        -191010.51 |
+--------------------------+
1 row in set (3.22 sec)


mysql> SELECT sql_no_cache SUM(outcome)-SUM(income) FROM journal where account_id = '1c6ab4e7-main';
+--------------------------+
| SUM(outcome)-SUM(income) |
+--------------------------+
|        -191010.51 |
+--------------------------+
1 row in set (3.02 sec)


mysql> explain SELECT sql_no_cache SUM(outcome)-SUM(income) FROM journal where account_id = '1c6ab4e7-main';
+----+-------------+---------+------+---------------+------------+---------+-------+--------+-----------------------+
| id | select_type | table  | type | possible_keys | key    | key_len | ref  | rows  | Extra         |
+----+-------------+---------+------+---------------+------------+---------+-------+--------+-----------------------+
| 1 | SIMPLE   | journal | ref | account_id  | account_id | 62   | const | 161638 | Using index condition |
+----+-------------+---------+------+---------------+------------+---------+-------+--------+-----------------------+
1 row in set (0.00 sec)

結(jié)果比較:

兩者執(zhí)行計(jì)劃一摸一樣,性能卻差距很大。在數(shù)據(jù)庫(kù)第一次啟動(dòng)時(shí)的查詢結(jié)果也差距很大,o_direct也差很多(測(cè)試結(jié)果略)。不是很懂為啥這種情況下多了一層操作系統(tǒng)緩存,讀取效率就高了很多,生產(chǎn)環(huán)境設(shè)置一定要以壓測(cè)結(jié)果為準(zhǔn),實(shí)際效果為準(zhǔn),不能盲目信任經(jīng)驗(yàn)值。

改進(jìn)措施:

不改變innodb_flush_method的情況下,其實(shí)這條sql還可以進(jìn)一步優(yōu)化,通過(guò)添加組合索引(account_id,outcome,income),使得走覆蓋索引掃描,可大大地減少響應(yīng)時(shí)間

以上這篇innodb_flush_method取值方法(實(shí)例講解)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • mysql的Buffer?Pool存儲(chǔ)及原理解析

    mysql的Buffer?Pool存儲(chǔ)及原理解析

    buffer pool是mysql一個(gè)非常關(guān)鍵的核心組件,實(shí)際上主要都是針對(duì)內(nèi)存里的Buffer Pool中的數(shù)據(jù)進(jìn)行的,這篇文章主要介紹了mysql的Buffer?Pool存儲(chǔ)及原理,需要的朋友可以參考下
    2022-04-04
  • 關(guān)于避免MySQL替換邏輯SQL的坑爹操作詳解

    關(guān)于避免MySQL替換邏輯SQL的坑爹操作詳解

    這篇文章主要給大家介紹了關(guān)于避免MySQL替換邏輯SQL的坑爹操作的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用mysql具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • Mysql觸發(fā)器語(yǔ)法解讀(附帶簡(jiǎn)單實(shí)用例子)

    Mysql觸發(fā)器語(yǔ)法解讀(附帶簡(jiǎn)單實(shí)用例子)

    這篇文章主要介紹了Mysql觸發(fā)器語(yǔ)法解讀(附帶簡(jiǎn)單實(shí)用例子),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • mysql日期date型和int型互換的方法

    mysql日期date型和int型互換的方法

    下面小編就為大家?guī)?lái)一篇mysql日期date型和int型互換的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-10-10
  • mysql mycat 中間件安裝與使用

    mysql mycat 中間件安裝與使用

    MyCAT是MySQL中間件,前身是阿里大名鼎鼎的Cobar,Cobar在開(kāi)源了一段時(shí)間后,不了了之。于是MyCAT扛起了這面大旗,在大數(shù)據(jù)時(shí)代,其重要性愈發(fā)彰顯。這篇文章主要是MyCAT的入門部署。
    2017-05-05
  • 關(guān)于mysql innodb count(*)速度慢的解決辦法

    關(guān)于mysql innodb count(*)速度慢的解決辦法

    innodb引擎在統(tǒng)計(jì)方面和myisam是不同的,Myisam內(nèi)置了一個(gè)計(jì)數(shù)器,所以在使用 select count(*) from table 的時(shí)候,直接可以從計(jì)數(shù)器中取出數(shù)據(jù)。而innodb必須全表掃描一次方能得到總的數(shù)量
    2012-12-12
  • mysql查找刪除表中重復(fù)數(shù)據(jù)方法總結(jié)

    mysql查找刪除表中重復(fù)數(shù)據(jù)方法總結(jié)

    在本篇文章中小編給大家整理了關(guān)于mysql查找刪除表中重復(fù)數(shù)據(jù)方法和相關(guān)知識(shí)點(diǎn),需要的朋友們參考下。
    2019-05-05
  • mysql show processlist 顯示mysql查詢進(jìn)程

    mysql show processlist 顯示mysql查詢進(jìn)程

    processlist命令的輸出結(jié)果顯示了有哪些線程在運(yùn)行,可以幫助識(shí)別出有問(wèn)題的查詢語(yǔ)句,兩種方式使用這個(gè)命令
    2012-03-03
  • PHP mysqli擴(kuò)展庫(kù) 預(yù)處理技術(shù)的使用分析

    PHP mysqli擴(kuò)展庫(kù) 預(yù)處理技術(shù)的使用分析

    本篇文章,介紹了PHP mysqli擴(kuò)展庫(kù) 預(yù)處理技術(shù)的使用分析。需要的朋友參考下
    2013-05-05
  • MySQL如何比較時(shí)間(datetime)大小

    MySQL如何比較時(shí)間(datetime)大小

    這篇文章主要介紹了MySQL如何比較時(shí)間(datetime)大小,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11

最新評(píng)論