Dimitriããã®ããã°ãèªãã§ã¿ãã
ãã®è¨äºã¯Â MySQL Casual Advent Calendar 2018 - Qiita 24æ¥ç®ã®è¨äºã§ãã
æ¨æ¥ã¯hmatsu47ããã«ããMySQL 8.0 が DMR/RC だった頃に試した機能について振り返ってまとめてみる - Qiitaã§ããã
ãã®è¨äºã«ã¤ãã¦
MySQLã®å種ãã³ããã¼ã¯ã«ã¤ãã¦æ¸ããã¦ãã Oracle ã® Dimitriさんのブログ ãããã¾ãã ã¡ã¸ã£ã¼ãã¼ã¸ã§ã³ã¢ããã®ã¿ã¤ãã³ã°ãæ§è½æ¹åãå ¥ã£ãå ´åãæ§ã ãªãã¿ã¼ã³ã®ãã³ããã¼ã¯ãè¡ãå ¬éãã¦ãã¾ãã
ä½ããã°ã©ããDimitriããèªä½ã®dimstatãå©ç¨ãããã®ã¨ãªã£ã¦ãã¦ãè¦æ¹ã»ç¥èªãåããã«ããã¦è¾ããã¨ãã話ãåããå²ã¨èãã¦ããã®ã§ä»åããç¨åº¦ã¾ã¨ãããã¨æãã¾ãã
ãªããDimitriãããè¡ããã³ããã¼ã¯ã¯ããã¾ã§ãã³ããã¼ã¯ãã¼ã«ã«ããè² è·ããããéã®ãã¼ã¸ã§ã³éã®æ¹åãMySQLã®ãã©ã¼ã¯(Percona Server, MariaDB)ã¨ã®æ¯è¼ãã¡ã¤ã³ã¨ãªã£ã¦ãã¾ããã¾ããã¨ã«ããããã«ããã¯ã¨ãªã£ã¦ããå é¨å¦çãæ¢ããããªã±ã¼ã¹ãããã¾ãããã®ãããæ¹åã®æ©æµãå®ãµã¼ãã¹ã§åãããããã¯å®éã«åã ã®ç°å¢ã§è©¦ãã¦ã¿ãå¿ è¦ãããã¾ãã
ããã¯è¯ãæªãã§ã¯ãªãããã³ããã¼ã¯ãã©ããããã¸ã·ã§ã³ã»è¦³ç¹ã§è¡ã£ã¦ããããã¨ãã話ãªã®ã§ä¸ã®äººãè¡ããªããããªããããã¨å人çã«ã¯æã£ã¦ãã¾ãã
ç¥èªã«ã¤ãã¦
MySQLã®ããå¤æ´ããããã©ã¡ã¼ã¿ããåç¥ã®æ¹ã¯ãããããªï¼ãã¨åããäºãå¤ãã®ã§ãããããã§ãåå¾ã®æç« ãèªã¾ãªãã¨æ¬å½ã«ãããªã®ãåãããªãäºãããã¾ããMySQLã®ãã©ã¡ã¼ã¿ã®ç¥èªã«ã¤ãã¦ã¯ãã®ã¾ã¾ãã©ã¡ã¼ã¿åããè±èªã®ã¹ã©ã³ã°çãªç¥èªã¯ã©ããã£ãç¥èªãªã®ããæ¸ãã¦ããã¾ãã
ä¸è¬çãªè±èªã®ç¥èª
- PITA: pain in the ass: ã¤ã©ã¤ã©ããããããããã
- BTW: by the way: ã¨ããã§
MySQLé¢é£ããã©ã¡ã¼ã¿ã®ç¥èª
ç¥èª | ãã©ã¡ã¼ã¿ã説æ |
---|---|
48cores-HT 2S Skylake server | 2ã½ã±ãã(åè¨48ã³ã¢ HyperThreadingæå¹) ã® Intel Skylakeã®CPUãè¼ãããµã¼ã |
OL7.4 | Oracle Linux 7.4 |
BP | innodb_buffer_pool |
dblwr | innodb_doublewrite |
trx_commit | innodb_flush_log_at_trx_commit |
checksum | innodb_checksum_algorithm |
PFS | performance_schema |
AHI | Adaptive Hash Index(innodb_adaptive_hash_index) |
io capacity | innodb_io_capacity |
io max | innodb_io_capacity_max |
lru depth | innodb_lru_scan_depth |
BP instances | innodb_buffer_pool_instances |
cleaner threads | innodb_page_cleaners |
checksumã«ã¤ãã¦ã¯ãã¤ããªãã°ã§ãå©ç¨ããã¦ãã¾ãããDimitriããã®ããã°ã§ç»å ´ããè¨æ¶ã¯ç¡ãã®ã§åºæ¬çã«InnoDBã®checksumã¨èãã¦è¯ããã¨æãã¾ãã
ã°ã©ãã®è¡¨é¡ã«åºã¦ããMySQLé¢é£ããã©ã¡ã¼ã¿ã®ç¥èª
ç¥èª | ãã©ã¡ã¼ã¿ã説æ |
---|---|
trx1 | ãã©ã³ã¶ã¯ã·ã§ã³æå¹(主ã«sysbenchã®ã°ã©ãã§ç»å ´) |
pool128G | innodb_buffer_pool_size = 128G |
ahi0 | innodb_adaptive_hash_index = OFFãahi1ãªãON(ããã©ã«ãã¯ON) |
10Mx8tab | 10 millionã®ãã¼ãã«ã8å(10 million x 8 table)ã主ã«sysbenchãå©ç¨ããå ´åã«åºã¦ãã¾ãã |
uniform-ps-trx | sysbenchã®ãªãã·ã§ã³ãã¾ã¨ãã¦ç¥ãããã®ã--rand-type=uniform --db-ps-mode=autoãtrxã¯ãã©ã³ã¶ã¯ã·ã§ã³ã使ç¨(使ããªãå ´åã¯--skip-trxãªãã·ã§ã³ãå©ç¨)ãsysbench 1.0.15æç¹ã§ã¯--rand-typeã§æå®å¯è½ãªå¤ã¯ uniform,gaussian,special,pareto ã®4ã¤ã§ããã©ã«ãã¯specialã |
p_sel1 | sysbenchã®point_selectã主ãã¼ã«å¯¾ããä¸ææ¤ç´¢(ex: WHEREå¥ã§id=[ã©ã³ãã ãªå¤]ã®ã¿æå®)ã |
binlog0/1 | binlog0ã¯skip_log_bin=1 ã§ãã¤ããªãã°ã®åºåãç¡å¹ã1ã¯ãã¤ããªãã°ã®åºåæå¹ã |
ãã¾ã: sysbench 1.0ã§å©ç¨ããluaãã¡ã¤ã«
sysbenchã¯ãã¼ã¸ã§ã³ 0.5 ããluaãå©ç¨ããããã«ãªã£ã¦ãã¾ãã1.0.15ã§ã¯ä»¥ä¸ã®luaãã¡ã¤ã«ãç¨æããã¦ãã¾ãã
bulk_insert.lua oltp_common.lua oltp_delete.lua oltp_insert.lua oltp_point_select.lua oltp_read_only.lua oltp_read_write.lua oltp_update_index.lua oltp_update_non_index.lua oltp_write_only.lua select_random_points.lua select_random_ranges.lua
OLTP_RWã¨ç¥ããã¦ããã®ã¯åºæ¬çã«oltp_read_write.luaãå©ç¨ãã¦ããã¨èãã¦è¯ãã§ããoltp_common.luaãåç §ããã¨é ã®æ¹ã§ãã£ãããªãã·ã§ã³ã確èªããäºãåºæ¥ã¾ãã
ã°ã©ããè¦ã
æ¦ãããã¾ã§ã®å 容ã§æè¿ã®ã°ã©ãã¯(ãããã)ç解å¯è½ã«ãªã£ã¦ããã¨æãã¾ãã 以ä¸ããã¤ãã®ä¾ãåèã«è§£èª¬ãã¾ãã
ã°ã©ãä¾1
このブログ ã® このグラフ ã¨ãªãã¾ãã
sysbenchã®OLTP_RW(oltp_read_write.lua)ãinnodb_buffer_pool_size=32Gããã©ã³ã¶ã¯ã·ã§ã³æå¹ãinnodb_doublewrite=0ããã¤ããªãã°ã®åºåç¡å¹ãªã±ã¼ã¹ã§MariaDB 10.3.5ãMySQL 5.7ãPercona Server 5.7ãMySQL 8.0.13ã§ã®æ¯è¼ã¨ãªãã¾ãã
表é¡ã§1..1024usrã¨ããã®ã§ã¦ã¼ã¶ã»ãã·ã§ã³æ°ã1,2,4,8,..,512,1024ã®ã±ã¼ã¹ã¨åéããããã§ãããã°ã©ãä¸é¨ã«ããéã32, 64, 128ã®3ãã¿ã¼ã³ã§sysbenchãå®è¡ããã°ã©ãã¨ãªãã¾ããã¾ããCommit/secã¨ããã®ã§sysbenchã®OLTP_RWãå®è¡ããéã«ç§éã³ãããæ°ãã°ã©ãåãããã®ã¨ãªãã¾ãã
dimstatã§ã°ã©ãåããå ´åããã³ããã¼ã¯éã§ãããééãéãã¦ãã°ã©ãã¨ãã¦ã¯ééãåºæ¥ãªãç¹å¾´ãããã¾ã(ãã¡ããåãæ¹ã«ããã¾ã)ã
ã°ã©ãä¾2
このブログ ã® このグラフ ã¨ãªãã¾ãã sysbenchã®TPC-C(æè¿ã®ãã¼ã¸ã§ã³ããTPC-Cç¸å½ã®ãã³ããã¼ã¯ãsysbenchã§å®è¡ã§ãã¾ã)ã10 x 100 warehouseã®ãã¼ã¿ãã¦ã¼ã¶ã»ãã·ã§ã³æ°ã 1,2,4, ... , 512, 1024ãinnodb_buffer_pool_sizeã128Gãinnodb_adaptive_hash_indexãç¡å¹ã¨æå¹ãinnodb_doublewriteãç¡å¹ã¨æå¹ããã©ã³ã¶ã¯ã·ã§ã³æå¹ãã¨ãã£ãã±ã¼ã¹ã§ãã³ããã¼ã¯ãè¡ã£ãã°ã©ãã§ããTPC-Cã¯warehouseã®æ°ã§ãã¼ã¿éãå¤ããé¡ã®ãã³ããã¼ã¯ã§ãã
ã°ã©ãä¸é¨ã«ããéããå·¦ãã
- innodb_adaptive_hash_index=0, innodb_doublewrite=0
- innodb_adaptive_hash_index=1, innodb_doublewrite=1
- innodb_adaptive_hash_index=0, innodb_doublewrite=1
- innodb_adaptive_hash_index=0, innodb_doublewrite=1, innodb_checksum_algorithm=crc32(chksum1ãããããã°ã®èª¬æèªã¾ãªãã¨åãããªã), innodb_io_capacity=2000, innodb_io_capacity_max=4000, innodb_buffer_pool_instances=8(bp8ããã説æãè¦å½ãããªãã®ã§å¤å)
bp8ãã¡ãã£ã¨è¬ã§ã(innodb_buffer_pool_sizeã128Gãªã®ã§ããã©ã«ãã§innodb_buffer_pool_instancesã¯8ã®ãã)ã
ãã®ã°ã©ãããä¸çªåãããããå·®ã¯2ã¨3ã§AHIãç¡å¹ãªæ¹ãæ§è½ãåºãã¨ããäºã§ãããããªããAHIãæå¹ãªæ¹ãéãã±ã¼ã¹ãããããããããã¯ã·ã§ã³ç°å¢ã§å¤æ´ããå ´åã¯ãµã¼ãã»MySQLããã¡ãã¨ã¢ãã¿ãªã³ã°ããã¦ããç°å¢ã§æ§è½ãã©ãå¤ããã確èªããäºããªã¹ã¹ã¡ãã¾ãã
ã°ã©ãä¾3
このブログ ã® このグラフ ã§ãã sysbenchã®OLTP_RWã1000ä¸è¡ã®ãã¼ãã«ã8å(10Mx8tab)ããã©ã³ã¶ã¯ã·ã§ã³æå¹(trx1)ããã¤ããªãã°ã®åºåç¡å¹/æå¹(binlog0/1)ãsync_binlogã0/1/1000(sync0/1/1K)ãã§MySQL5.7ã«å¯¾ãããã³ããã¼ã¯ã MySQL5.7ã ã¨ãã¤ããªãã°ãç¡å¹ã®æ¹ãã¦ã¼ã¶ã»ãã·ã§ã³æ°ã128ãããããé ããªãã¨ããä¸æè°ãªçµæã«ãªã£ã¦ãäºãåããã¾ãã
OLTP_RWã®ä¸ã®ç¹å®ã®å¦çãé ãã¨è¦ãã®ãããããã oltp_update_non_index.lua ã使ã£ãã¨æããã以ä¸ã®ã°ã©ããç¶ãã¦è¼ãã¦ãã¾ãã
ãã¤ããªãã°ã®åºåãç¡å¹ãªå ´åãINDEXãå«ã¾ãªãã«ã©ã ã®æ´æ°ã«å¯¾ããå¦çã¯ã¦ã¼ã¶ã»ãã·ã§ã³ã64ãè¶ ããã¨ååç¨åº¦ã«ä½ä¸ãã¦ãããã¨ãåããã¾ãã Dimitriããã¯ããã°ã«
as you can see, enabling Binlog is helping a lot MySQL 5.7 to not loose performance on high load.. and this is all because it helps to "hide" the REDO log contention we have in 5.7
ã¨æ¸ããç¶ãã¦8.0ã§ã©ããªã£ããè¼ãã¦ãã¾ãã MySQL8.0ã«ãããOLTP_RWã§ã®çµæãã¦ã¼ã¶ã»ãã·ã§ã³æ°ã«é¢ä¿ç¡ããã¤ããªãã°ãç¡å¹ãªå ´åã®æ¹ãæå¹ãªå ´åããè¯ãçµæã¨ãªã£ã¦ããäºãåããã¾ãã ç¶ãã¦8.0ã«ãããupdate NoKeyã®å ´åã¯ä»¥ä¸ã®ãããªçµæã¨ãªã£ã¦ãã¾ãã åæ§ã«ã¦ã¼ã¶ã»ãã·ã§ã³æ°ã«é¢ä¿ç¡ããã¤ããªãã°ãç¡å¹ãªå ´åã®æ¹ãããçµæã¨ãªã£ã¦ãã¾ãã
ãã¤ããªãã°ã®åºåãç¡å¹ã«ããäºãªãã¦æ¨ä»ããã®ãï¼ãã¨æãã人ãå¤ãã¨æãã¾ãããããã«ããã¯ãæ¢ãå ´å(ãã®å ´åã¯MySQLãã®ãã®ã®)ãæ§è½ã«ä¿ãç©ã¯ç¡å¹ã«ãã1ã¤ãã¤æå¹ã«ãã¦ãã£ãéã®æ§è½å·®ãè¦ã¦ããå¿ è¦ãããã®ã§ããããä¾ã試ãã¦ããã®ã ã¨æãã¾ãã ã¨ãããã¾ã§æ¸ãã¦Amazon Auroraã£ã¦ãã¤ããªãã°ãåºæ¬çã«ç¡å¹ã«ãããã¨ãæ¨å¥¨ãã¨ãããããã©ã«ãç¡å¹ã ã£ãã¨è¨æ¶ãã¦ãããã§ããåæ§ã®åé¡ã¯èµ·ããªãããã«ãªã£ã¦ããã®ããªï¼ã¨ãæãã¾ãã(ã¾ãèµ·ããªãããããªãã§ãããããã£ã¨ããã¶ã)ã
ã¾ã¨ã
èªåãæ £ããã¾ã§ã¯ããªãæç« ã¨ã°ã©ããè¡ã£ããæ¥ãããå ´åã«ãã£ã¦ã¯å¤ãããã°ãèªãã ããã¦ãã¾ãããæ £ããã¨å²ã¨å¼ã£ããããã«èªããããã«ãªãã¾ããæéã®ããæ¹ã¯dimstatèªä½ãèªåã®ç°å¢ã«å ¥ãã¦åããã¦ã¿ãã¨ããåãããããã¨æãã¾ãã
dimstatã試ãã¦ã¿ããæ¹ã¯こちらãã辿ã£ã¦è¡ã£ã¦ããã¥ã¢ã«ã¨ãèªãã¨è¯ãã§ããããã¨ã¯ãããã³ãã«ããã¦ããã®ãApache1ç³»ã ã£ããã¨ãã§é¢é£ããããããã¾ãããããã®ãããã¯è§¦ãå¿ è¦ã¯æ®éç¡ãã®ã§æ°ã«ãããè² ãã§ãããã
MySQLã®æ°ãããã¼ã¸ã§ã³ãåºãã¿ã¤ãã³ã°ããã©ã¼ã¯ã®ãããã¯ãã§ä½ãæ¹è¯ããã£ãå ´åãã¾ãã¯Twitterã§DimitriãããFacebookãPerconaã®äººã¨ããåããããå¾ã«ãããããã£ã¦ã¿ãã¯ãçãªæãã§ããã°ãæ¸ãããäºãããã¾ãã®ã§æ1åãããè¦ãã¦è¦ãã¨è¯ããã¨æãã¾ãã
ãªããæè¿ã¯ã¹ãã¬ã¼ã¸ãIntel Optaneã ã£ããåè¨40ã³ã¢ä»¥ä¸ã®CPUã ã£ããã¨Webç³»ã§ã¯ãªããªã使ããªããããªã¹ããã¯ã§ã®ãã³ããã¼ã¯ãå¤ãã®ã§ããèªèº«ãé¢åãè¦ãç°å¢ã®DBãµã¼ããåè¨20ã³ã¢ä»¥ä¸ã®å ´åã¯å¥éãã³ããã¼ã¯ãåãäºããå§ããã¾ããNUMAç°å¢ãã©ããããã§ãããã³ã¢æ°ã§å¾åãå¤ãããã¨ãçµæ§ããããã§ãã ã¾ãPersistent connectionãå©ç¨åºæ¥ãç°å¢ãã©ãããé«è² è·ãªå ´åã¯çµæ§ãªæ§è½å·®ãåºãããã¾ãã
ææ¥ã¯ããããæçµæ¥(25æ¥ç®)ãkk2170ããã¨ãªãã¾ãã