ä¸ãInnoDB 表åå¨ä¼å
1ãOPTIMIZE TABLE
éæ¶çä½¿ç¨ OPTIMIZE TABLE è¯å¥æ¥éç»è¡¨ï¼å缩浪费ç表空é´ãè¿æ¯å¨å ¶å®ä¼åææ¯ä¸å¯ç¨çæ åµä¸æç´æ¥çæ¹æ³ãOPTIMIZE TABLE è¯å¥éè¿æ·è´è¡¨æ°æ®å¹¶é建表索å¼ï¼ä½¿å¾ç´¢å¼æ°æ®æ´å ç´§åï¼åå°ç©ºé´ç¢çãè¯å¥çæ§è¡ææä¼å 表çä¸åèä¸åãè¿å¤§ç表æè è¿å¤§çç´¢å¼åå次添å 大éæ°æ®çæ åµä¸é½ä¼ä½¿å¾è¿ä¸æä½åæ ¢ã
2ãèªå¢ä¸»é®
InnoDB表ï¼å¦æ主é®è¿é¿ï¼é¿æ°æ®åå主é®ï¼æè å¤ä¸ªåç»åå主é®ï¼ä¼æµªè´¹å¾å¤ç©ºé´ãåæ¶ï¼äºçº§ç´¢å¼ä¹å å«ä¸»é®ãè¿ç§æ åµï¼å¯ä»¥èèå建èªå¢åä½ä¸ºä¸»é®ï¼æè 使ç¨åç¼ç´¢å¼ã
3ãVARCHAR
对äºéè¦åå¨é¿åº¦ä¸å®æè å å«å¾å¤NULLå¼çå符串åï¼ä½¿ç¨ VARCHAR ä»£æ¿ CHAR ãå¨å°è¡¨åºç¨ä¸ï¼ç¼å使ç¨åç£ç I/O æ¶èä¼æ´å°ã
4ãå缩çè¡æ ¼å¼åå¨
对äºå å«å¤§ééå¤ææ¬æè æ°åç大表ï¼å¯ä»¥èèéç¨å缩çè¡æ ¼å¼åå¨ãè¿æ ·æ°æ®å è½½ä¼åå°å¯¹ç¼åå I/O çéæ±ãå¨ä½¿ç¨å缩è¡æ ¼å¼åï¼éè¦èèå缩è¡æ ¼å¼ COMPRESSED åçä¸åæ§è½å½±åã
äºãInnoDB äºå¡ç®¡çä¼å
ä¼å InnoDB äºå¡å¤çï¼ä¸»è¦éè¦æ¾å°äºå¡ç¹æ§åæå¡å¨è´è½½é´çæ个平衡ç¹ãä¾å¦ï¼ä¸ç§éè¦æ交å åäºå¡çï¼æè æ¯é2-3个å°æ¶æ交ä¸æ¬¡äºå¡çä¸ååºç¨è¡¨ç°ã
1ãAUTOCOMMIT 设置
MySQL çé»è®¤è®¾ç½® AUTOCOMMIT=1 ä¼éå¶ç¹å¿æ°æ®åºçæ§è½ãå¦æå¯ä»¥çè¯ï¼å¯ä»¥å¨åºç¨ä¸ä½¿ç¨ SET AUTOCOMMIT=0 æè START TRANSACTION ï¼ç¶åå°å¤ä¸ªç¸å ³çæ°æ®åæ´æä½æ·»å å°åä¸äºå¡ä¸ï¼ç¶åæ§è¡ COMMIT è¯å¥æ¥æ交äºå¡ï¼æ交æ°æ®åæ´ã
InnoDB 对äºå¼åæ°æ®åºåæ´çæä½ï¼å¿ é¡»å°å ¶è¿è¡æ¥å¿å·çã
2ãåªè¯»äºå¡
对äºåªå å« SELECT è¯å¥çäºå¡ï¼å¯ç¨ AUTOCOMMIT ï¼ä½¿å¾ InnoDB è½å¤è¯å«åªè¯»äºå¡ï¼ç¶åè¿è¡ç¸åºçä¼åã
3ãåæ»æä½
é¿å
对大æ°æ®éæä½æå
¥ï¼æ´æ°åå é¤ä¹åçåæ»æä½ãå¦æä¸ä¸ªå¤§çäºå¡ææ
¢äºæå¡å¨ï¼é£ä¹åæ»å°æ¯æå¡å¨æ§è½åå¾æ´ç³ãå¯ä»¥åæ¹å¤ç大æ°æ®éæä½ãéè¿æè¿ç¨æ¹å¼ç»æ¢çåæ»æä½ä¼å¨æå¡å¨å¯å¨æ¶éæ°å¯å¨ã
å¯ä»¥éè¿å¦ä¸çç¥åå°æ¤ç±»é®é¢åçï¼
-
å¢å¤§ç¼åï¼é¿å é¢ç¹ç£çI/Oã
-
设置 innodb_change_buffering=allï¼è¿æ · update å delete æä½ä¹ä¼å insert ä¸æ ·è¿è¡ç¼åï¼åæ»ä¹æ´å¿«ã
-
æå¨commitï¼åå²å¤§æ°æ®æä½ã
为äºé¿å æ¶ç©ºçåæ»ãå¢å¤§ç¼åï¼ä½¿å¾åæ»è¿ç¨å¯ä»¥åºç¨å°æ大çèµæºä»¥ä¾¿å¿«éæ§è¡ãæè ææåæ»è¿ç¨ï¼ç¶å使ç¨innodb_force_recovery=3é项éå¯ã
对äºè¾å¤æ§è¡èæ¶inserts, updates, å deletes æä½çæå¡å¨ï¼ç¡®ä¿innodb_change_buffering=allå¼å¯ã
4ãæ¥å¿å·ç
InnoDB å¦ä¼æ¯ç§å·çä¸æ¬¡æ¥å¿ï¼å¦æå¯ä»¥æ¿åææ°äºå¡å´©æºçæ°æ®æ失ï¼å¯ä»¥è®¾ç½®innodb_flush_log_at_trx_commit = 0ãè½ç¶æ¥å¿çå·çæä½ä¹ä¸æ¯ä¿è¯çï¼åæ¶ä¹å¯ä»¥è®¾ç½®innodb_support_xa = 0ï¼åå°ç£çåäºè¿å¶æ¥å¿çåæ¥æä½ã
Note
innodb_support_xa 已被å¼ç¨ï¼å°æ¥çæ¬ä¼è¢«ç§»é¤ãMySQL 5.7.10çæ¬ï¼InnoDB XAäºå¡ç两é¶æ®µæ交æ¯é»è®¤æ¯æçï¼ä¸è½è®¾ç½®ç¦ç¨innodb_support_xaã
5ãèæ¶äºå¡æ°æ®
è¡ä¿®æ¹æå é¤åï¼è¡æ°æ®å undo logs å¨ç©çä¸å¹¶æ²¡æç«å»è¢«åæ´ãå³ä½¿å¨äºå¡ç«å»æ交åãæ§æ°æ®ä¼ä¿æç´å°ä¹åå¯å¨çäºå¡æè 并åæ§è¡çäºå¡å®æåãè¿æ ·ï¼è¿äºäºå¡å¯ä»¥ä¸ç´è®¿é®å°ç¸å ³çæ§æ°æ®ãæ以èæ¶çäºå¡ä¼é»æ¢ InnoDB æ¸ é¤å ¶å®ç¸å ³äºå¡çæ°æ®ã
6ãå ³èå é¤
å¦æä¸ä¸ªèæ¶çäºå¡ä¿®æ¹æè å é¤äºæäºè¡ãé£ä¹å ¶å®ä½¿ç¨è¿äºæ°æ®çäºå¡ï¼å¦æäºå¡çº§å«è®¾ç½®å¨READ COMMITTED æè REPEATABLE READ 级å«ï¼åéè¦é¢å¤çå¤çæ¥é建æ§æ°æ®ã
7ãå ³èæ¥è¯¢
å½ä¸ä¸ªèæ¶çäºå¡ä¿®æ¹äºæ个表ï¼å ¶å®ä½¿ç¨æ¤è¡¨çäºå¡å°ä¸ä¼ä½¿ç¨è¦çç´¢å¼ãå¦æäºçº§ç´¢å¼å å«æ¯è¾æ°çPAGE_MAX_TRX_IDï¼æè æäºè®°å½è¢«æ 记为已å é¤ï¼InnoDB å¯è½éè¦ä½¿ç¨èç°ç´¢å¼æ¥æ¥è¯¢ç¸åºçè®°å½ã
è¦çç´¢å¼æ¥è¯¢ï¼ä½¿ç¨äºçº§ç´¢å¼å³å¯è·å¾æéçæ°æ®ï¼èä¸éè¦è®¿é®è¡¨æ°æ®ï¼
ä¸ãInnoDBåªè¯»äºå¡ä¼å
InnoDB å¯ä»¥é¿å ç»åªè¯»äºå¡èµ transaction ID (TRX_ID )ãäºå¡IDåªå¯¹æ§è¡åæä½ï¼æè å«é读æä½ï¼å¦ SELECT … FOR UPDATEæç¨ãå»é¤ä¸å¿ è¦çäºå¡IDï¼æå©äºåå°æ¯æ¬¡è¯»åæä½å¿ 须访é®çå é¨æ°æ®ç»æ大å°ã
InnoDB å¨ä»¥ä¸æ æ¯è½å¤è¯å«åªè¯»æä½ï¼
-
äºå¡ä»¥è¯å¥ START TRANSACTION READ ONLY å¼å§ï¼è¿ç§æ åµä¸ï¼æ°æ®åæ´æä½ä¼å¼åé误ï¼äºå¡ä»ä¼ä»¥åªè¯»æ§è´¨è¿è¡ï¼
ERROR 1792 (25006): Cannot execute statement in a READ ONLY transaction.
对äºäºå¡ä¸ç临æ¶è¡¨å¯ä»¥è¿è¡ä»»ä½æä½ã
-
autocommit = onï¼å¹¶ä¸äºå¡åªå å«ä¸ä¸ªè¯å¥ï¼ä¸è¯å¥ä¸ºæ²¡æ使ç¨FOR UPDATE æè LOCK IN SHARED MODE çSELECT è¯å¥ã
-
äºå¡ä»¥READ ONLY é项å¼å§ã
è¿æ ·ï¼å¯¹äºè¯»ç¹å¿çåºç¨ï¼å¦æ¥è¡¨åºç¨ï¼å¯ä»¥å°ä¸ç³»åçæ¥è¯¢è¯å¥ç»¼åå°ä¸ä¸ªåªè¯»çäºå¡ä¸ï¼æè å¨æ§è¡æ¥è¯¢å设置 autocommit = onï¼æè å¨åºç¨ä¸é¿å å°åæ´æä½åæ¥è¯¢æä½ç¸äºå½±åã.
åãéåæ¥å¿ï¼redo logï¼ä¼å
å¯ä»¥èèéµå¾ªä»¥ä¸ä¼åæå¼ï¼
1ãæ¥å¿å¤§å°
ç¡®ä¿éåæ¥å¿è¶³å¤å¤§ï¼å³ä½¿åç¼åæ± ï¼buffer poolï¼ä¸æ ·å¤§ãå½ InnoDB å满 redo log æ¶ï¼æå¡å¨ä¼åºäºä¸ä¸ªæ£æ¥ç¹ï¼checkpointï¼å°±ä¼å°æ¥å¿ä¸çåæ´å
容åå°ç£çãå¦æ redo log æ件è¿å°ï¼é£ä¹å°±ä¼å¼åæå¡å¨é¢ç¹çåçãè½ç¶ä¹åï¼è®¾ç½®è¿å¤§ç redo log ä¼å¼èµ·æ¢å¤æ¶é´çè¿é¿ï¼ä½æ¯ç°å¨ï¼æ¢å¤æºå¶å·²ç»å¨é度ä¸æå¾å¤§çä¼åï¼å æ¤ä¸ç¨åèèæ¤å ç´ ã
æ件ç大å°åæ°éå¯ä»¥ä½¿ç¨ï¼ innodb_log_file_size å innodb_log_files_in_group è¿è¡è®¾ç½®ã
2ãæ¥å¿ç¼å
å¯ä»¥èèå¢å¤§æ¥å¿ç¼åï¼log bufferï¼ã大çæ¥å¿ç¼åå¯ä»¥å®¹çº³æ´å¤§çäºå¡æ§è¡ï¼é¿å ä¸å¿ è¦çåçæä½ã设置åéï¼innodb_log_buffer_size ã
3ãread-on-write
é ç½® innodb_log_write_ahead_size åé以é¿å âread-on-writeâï¼å°±æ¯å½ä¿®æ¹çåèä¸è¶³ä¸ä¸ªæ´ç³»ç» blockæ¶ï¼éè¦å°æ´ä¸ª block 读è¿å åï¼ä¿®æ¹å¯¹åºçä½ç½®ï¼ç¶åååè¿å»ï¼å¦ææ们以 block 为åä½æ¥åå ¥çè¯ï¼ç´æ¥å®æ´è¦çåå ¥å³å¯ï¼ãè¿ä¸ªé ç½®å®ä¹äº redo log ç write-ahead å大å°ã
设置innodb_log_write_ahead_size ç大å°ä»¥å¹é æä½ç³»ç»æè æ件系ç»çç¼åå大å°ã
Read-on-write ç产çæ¯å ä¸ºå¨ write-ahead å大å°åæä½ç³»ç»æè æ件系ç»çç¼åå大å°ä¸å¹é çæ åµä¸ï¼redo log åæ æ³å®å ¨çåå ¥å°æä½ç³»ç»ï¼æè æ件系ç»å¼èµ·çã
innodb_log_write_ahead_size çå¼å¯ä»¥è®¾ç½®ä¸º InnoDB æ¥å¿æ件å大å°çåæ°(2n)ãæå°çå¼ä¸º(512)ã设置为æå°å¼æ¶ Write-ahead ä¸ä¼åçãæ大å¼ä¸º innodb_page_size ãå¦æ设置çå¼å¤§äºinnodb_page_sizeï¼é£ä¹æå¡å¨ä¼ä½¿ç¨innodb_page_sizeå¼ã
innodb_log_write_ahead_size å¼è®¾ç½®ç太å°ï¼ä¼å¯¼è´ read-on-writeï¼è®¾ç½®è¿å¤§ï¼åä¼å½±å fsync æ§è½ï¼å 为ä¸æ¬¡éè¦äºå¤ä¸ªæ°æ®åã
äºãInnoDB表ç大æ°æ®è½½å ¥
å¿«éæå ¥éç¨æå¼ï¼
1ãAUTOCOMMIT
å¯¼å ¥æ°æ®æ¶ï¼å ³é autocommit 模å¼ï¼é¿å æ¯æ¬¡è¡æå ¥å¯¼è´çæ¥å¿å·çãå¨æ§è¡å¼å§åç»æä½¿ç¨ SET AUTOCOMMIT å COMMIT è¯å¥ï¼
SET autocommit=0;
…SQLimport statements …
COMMIT;
mysqldump é项 –opt ï¼é»è®¤å¯ç¨ï¼ä¼å建 dump è½¬å¨ æ件ï¼ä»¥æ§è¡å¿«éæ°æ®å¯¼å ¥ï¼é¿å å°ææçæ°æ®è½½å ¥å åå¼åé®é¢ãå³ä½¿ä¸ä½¿ç¨SET autocommit å COMMITã
2ãäºçº§ç´¢å¼é® UNIQUE éå¶
å¦æå¨äºçº§ç´¢å¼é®ä¸æ UNIQUE éå¶ï¼å¯ä»¥å¨è½½å ¥æ¶ææ¶å ³éæ¤æ£æ¥ï¼
SET unique_checks=0;
…SQLimport statements …
SET unique_checks=1;
对äºè¾å¤§ç表ï¼æ¤æä½å¯ä»¥èç大éçç£ç I/Oï¼å 为 InnoDB å¯ä»¥ä½¿ç¨å®ç change bufferï¼change buffer ç主è¦ç®çæ¯å°å¯¹äºçº§ç´¢å¼çæ°æ®æä½ç¼åä¸æ¥ï¼ä»¥æ¤åå°äºçº§ç´¢å¼çéæºIOï¼å¹¶è¾¾å°æä½å并çææï¼æ¥æ¹éåäºçº§ç´¢å¼è®°å½ãç¡®ä¿æ°æ®ä¸å å«éå¤é®ã
3ãFOREIGN KEY
å¦æ表é®å å« FOREIGN KEY éå¶ãå¯ä»¥åå¯¼å ¥æé´å ³éæ¤éå¶ã
4ãæ¹éå¤è¡æå ¥
使ç¨æ¹éå¤è¡æå ¥ï¼ä»¥åå°ä¸å¿ è¦å®¢æ·ç«¯æå¡å¨é´éä¿¡ï¼
SET foreign_key_checks=0;
…SQLimport statements …
SET foreign_key_checks=1;
INSERT INTO yourtable VALUES (1,2), (5,5), …;
éç¨äºä»»ä½ç±»å表ã
5ãèªå¢åæ¹éæå ¥
å½æ¹éæå ¥æ¶åèªå¢åæ¶ï¼è®¾ç½® innodb_autoinc_lock_mode = 2 ï¼é»è®¤1ï¼0ï¼traditionalï¼1ï¼consecutiveï¼2ï¼interleavedï¼ã
6ã主é®é¡ºåºæå ¥
以主é®ç顺åºè¿è¡æ¹éæå ¥ä¼æ´å¿«ãInnoDB 表主é®ç´¢å¼ä¸ºèç°ç´¢å¼ï¼clustered index, 以主é®ç顺åºè®¿é®ä¼å¾å¿«ï¼ãç¹å«æ¯å¯¹äºæ æ³å®å ¨è½½å ¥ç¼åç大表ã
7ãå ¨æç´¢å¼
å ¨æç´¢å¼å¯¼å ¥ï¼
-
表å建æ¶å®ä¹æ°åFTS_DOC_IDï¼ç±»å BIGINT UNSIGNED NOT NULL,ï¼åä¸å®ä¹ç´¢å¼FTS_DOC_ID_INDEXï¼å¦ä¸ï¼
CREATE TABLE t1 (
FTS_DOC_ID BIGINT unsigned NOT NULL AUTO_INCREMENT,
title varchar(255) NOT NULL DEFAULT ”,
text mediumtext NOT NULL,
PRIMARY KEY (‘FTS_DOC_ID’)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;CREATE UNIQUE INDEX FTS_DOC_ID_INDEX on t1(FTS_DOC_ID);
-
è½½å ¥æ°æ®ã
-
æ°æ®è½½å ¥åï¼å¨ç¸åºçåä¸åå»ºå ¨æç´¢å¼ã
Note
å¨ innodb åå¨å¼æä¸ï¼ä¸ºäºæ¯æå ¨ææ£ç´¢ï¼å¿ é¡»æä¸ä¸ªåä¸ word è¿è¡æ å°ï¼å¨ innodb ä¸è¿ä¸ªå被å½å为FTS_DOC_IDï¼å ¶ç±»åå¿ é¡»ä¸º BIGINT UNSIGNED NOT NULL,å¹¶ä¸ innodb åå¨å¼æä¼å¨è¯¥åä¸å ä¸ä¸ä¸ªå为FTS_DOC_ID_INDEX çå¯ä¸ç´¢å¼ãä¸è¿°æä½ç± innodb åå¨å¼æèªå·±å®æï¼ç¨æ·ä¹å¯ä»¥å¨å建表æ¶æå¨æ·»å ï¼ä¸»è¦å¯¹åºç约ææ¡ä»¶ã
常è§çç´¢å¼æ¯ææ¡£å°å ³é®è¯çæ å°ï¼ææ¡£ââ>å ³é®è¯
åæç´¢å¼æ¯å ³é®è¯å°ææ¡£çæ å°ï¼å ³é®è¯ââ>ææ¡£
å ¨æç´¢å¼éè¿å ³é®åæ¾å°å ³é®åæå¨ææ¡£ï¼å¯ä»¥æé«æ¥è¯¢æç
å ãInnoDB æ¥è¯¢ä¼å
å建éå½çç´¢å¼ä»¥ä¼åæ¥è¯¢ï¼éç¨æå¼å¦ä¸ï¼
-
å°å ³é®æ¥è¯¢æ常ç¨ççåå å«è¿è¡¨ä¸»é®ä¸ã
-
主é®åä¸è¦ä½¿ç¨è¿å¤çåæè è¿é¿çåãå 为äºçº§ç´¢å¼å å«ä¸»é®ï¼è¿å¤§ç主é®ä¼é æç£çI/Oåå åç浪费ã
-
ä¸è¦å¨æ¯ä¸ªåä¸å建äºçº§ç´¢å¼ï¼ä¸ä¸ªæ¥è¯¢åªè½ä½¿ç¨ä¸ä¸ªç´¢å¼ã对äºæå°ä½¿ç¨çåååéæ©æ§ä¸å¤§çåå建索å¼å¯¹äºæ¥è¯¢ä¼åä¸ä¼æ太大帮å©ãå¦æé对ä¸ä¸ªè¡¨çæ¥è¯¢é常å¤ï¼åéè¦æ¾å°è½å¤æå©äºæå¤æ¥è¯¢çå¤å主é®ãå¦æç´¢å¼åè½å¤è¦çæéè¦æ¥è¯¢çæ°æ®åï¼é£ä¹å°±å¯ä»¥åªä½¿ç¨ç´¢å¼è¿è¡æ°æ®æ¥è¯¢ï¼èä¸éè¦ä»è¡¨ä¸è·åæ°æ®ã
-
å¦ææä¸åçæ°æ®ä¸è½ä¸ºNULLï¼é£ä¹å¨å建表çæ¶åå°å ¶çå½ä¸º NOT NULL ãä¼åå¨ä»¥æ¤å¯ä»¥æ´é«çå³å®æä¼ä½¿ç¨ç´¢å¼ã
-
å¯ä»¥é对ä½æ¥è¯¢äºå¡è¿è¡ç¸åºçä¼åã
ä¸ãInnoDB DDL æä½ä¼å
-
许å¤DDLæä½ï¼å¦è¡¨åç´¢å¼ç(CREATE, ALTER, åDROP è¯å¥) å¯ä»¥å¨çº¿æ§è¡ã
-
ä½¿ç¨ TRUNCATE TABLE ä»£æ¿ DELETE FROM tbl_name æ¥æ¸ 空表ï¼å¤é®éå¶å¯ä»¥ä½¿å¾ TRUNCATE è¯å¥å¦æ®éç DELETE è¯å¥è¬æä½ãè¿ç§æ æ¯ä¸ï¼ä¸ç³»åå¦ DROP TABLE å CREATE TABLE è¯å¥ä¼æ§è¡çå¾å¿«ã
-
å 为主é®InnoDB表çåå¨ç»ææ¯é«åº¦æ´åçï¼ä¸»é®çåæ´ä¼å¼èµ·æ´å¼ 表çéæãæ好å°ä¸»é®å®ä¹å å«å¨è¡¨å建è¯å¥ä¸ï¼é¿å ä¸å¿ è¦çåææ´æ¹ã
å «ãInnoDB ç£ç I/O ä¼å
å¦ææ°æ®åºç设计å sql æä½ä¼åé½éµå¾ªäºæä½³å®è·µï¼æ°æ®åºä¾ç¶å 为 I/O è´è½½èååºéå¸¸æ ¢ï¼é£ä¹å°±éè¦é对 I/O è¿è¡ä¸é¨çä¼åãå¯ä»¥éè¿ Unix ç top å·¥å ·ï¼æè Windows çä»»å¡ç®¡çå¨æ¥æ¥çå·¥ä½è´è½½ï¼å¦æä½ äº70%ï¼é£ä¹è´è½½å主è¦å¨ç£çã
1ãå¢å¤§ç¼åï¼
InnoDB ç¼åä¸çæ°æ®è®¿é®ä¸éè¦ç£çI/Oï¼ä½¿ç¨innodb_buffer_pool_size 设置ã建议设置为系ç»å åç 50 ~ 75%ã
2ãè°æ´å·ççç¥ï¼
æäºçæ¬ GNU/Linux ç³»ç»ï¼ä½¿ç¨fsync() æè ç¸å ³æ¹æ³è¿è¡å·çæ¶ï¼é度ä¼éå¸¸æ ¢ãè¿æ¶ï¼å¦æå½±åå°æ°æ®åºæ§è½ï¼é£ä¹å¯ä»¥éè¿è®¾ç½®innodb_flush_method = O_DSYNC æ¥åæ´å·ççç¥ã
3ãè°æ´ Linux ç³»ç» AIO ç£çè°åº¦çç¥ä¸º noopï¼åéåï¼ æè deadlineï¼è¯»ãåéåï¼
InnoDB å¨ Linux ç³»ç»ä¸ä½¿ç¨å¼æ¥ I/O åç³»ç»ï¼æ¬å°AIOï¼éè¿é¢è¯»åå请æ±æ¥æ§è¡æ°æ®æ件读åãé ç½®åéinnodb_use_native_aio é»è®¤å¯ç¨ãç£çè°åº¦çç¥å¯¹æ¬å° AIO å½±åæ¯è¾å¤§ãé常建议设置为 noop æè deadlineã
4ãSolaris 10 x86_64æ¶æ建议使ç¨direct I/Oçç¥
5ãRAIDé ç½®
6ãnon-rotational åå¨
Non-rotational åå¨éç¨äºéæºè¯»åï¼rotational åå¨ç¸åéç¨äºé¡ºåºè¯»åãä¸åçåå¨è®¾å¤å¯¹æ°æ®åæ¥å¿çæä½ç±»åä¸åã
æ°æ®åºéæºè¯»åç±»æ件å æ¬ï¼file-per-table å general tablespace æ°æ®æ件, undo tablespaceæ件åtemporary tablespace æ件ã顺åºè¯»åç±»æ件å æ¬ï¼InnoDB system tablespace æ件(åºäº doublewrite buffering and change buffering) åæ¥å¿æä»¶ï¼ binary log æ件åredo log æ件çï¼ã
ä½¿ç¨ non-rotational åå¨æ¶ï¼éè¦å¯¹ä»¥ä¸é ç½®è¿è¡ä¼åï¼
-
innodb_checksum_algorithmï¼crc32 ç®æ³ä½¿ç¨äºä¸ç§æ´å¿«çä¸è´æ§æ£æ¥ç®æ³ï¼å¯¹äºé«éåå¨è®¾å¤ï¼æ¨è使ç¨ã
-
innodb_flush_neighborsï¼é对rotationalåå¨è®¾å¤ä¼åã对äºnon-rotational设å¤æè æ··ç¨æ æ¯ï¼åéç¦ç¨ã
-
innodb_io_capacityï¼é»è®¤ç200设å®å¯¹äºä½ç«¯non-rotationalåå¨è®¾å¤å·²ç»è¶³å¤ãå ¶å®ï¼é æ 设置ã
-
innodb_io_capacity_maxï¼é»è®¤2000 é对non-rotational åå¨ã
-
innodb_log_compressed_pagesï¼å¦æredo logsåå¨å¨non-rotational设å¤ï¼å¯ä»¥å¼çç¦ç¨è¯é项æ¥åå°æ¥å¿ã
-
innodb_log_file_sizeï¼å¦æredo logs åå¨å¨non-rotational åå¨è®¾å¤ï¼è®¾ç½®æ¤é项æ大读åç¼åã
-
innodb_page_sizeï¼è®¾ç½®æ¤å¼ä»¥å¹é ç£çinternal sector sizeãæ©æçSSD设å¤ä¸º4KBï¼ä¸äºæ°çæ¬çSSDè½å¤æ¯æå°16KBãé»è®¤çé¢InnoDB ä¹å¤§å°ä¸º16KBãå°½é使å¾æ°æ®åºé¡µå¤§å°ååå¨è®¾å¤çå大å°æ¥è¿ï¼åå°æ æ³ä¸æ¬¡åå ¥ç£ççæ°æ®å¤§å°ã
-
binlog_row_imageï¼binary logs åå¨å¨non-rotational 设å¤æ åµä¸ï¼å¦æææç表é½æ主é®ï¼é£ä¹å¯ä»¥å°æ¤åé设置为æå°æ¥åå°æ¥å¿ã
7ãå¢å¤§ I/O 容é以åå° backlogs è´è½½
å¦æååéä¼å 为æ£æµç¹æä½èä¸é´æçéä½ï¼é£ä¹å¯ä»¥å¼çå¢å innodb_io_capacity çå¼ãå¼è¶å¤§ï¼æ°æ®åºå·çé¢çä¼å¢å¤§ï¼ä»èé¿å äºå 为 backlog çæä½å¸¦æ¥çååéçå½±åã
8ãè°æ´æ°æ®åºI/O容é
å¦æç³»ç»è½å¤æ»¡è¶³ InnoDB å·çæä½ãå¯ä»¥èèåå°innodb_io_capacity é ç½®ãé常éè¦å°æ¤åéå°½é设置ä½ä¸äºãï¼SHOW ENGINE INNODB STATUSï¼
9ãå°ç³»ç»è¡¨ç©ºé´æ件åå¨å¨ Fusion-io设å¤
å¦æ使ç¨æ¯æåååç Fusion-io 设å¤åå¨ç³»ç»è¡¨ç©ºé´æ件(âibdata filesâ) ï¼é£ä¹å¯ä»¥å¯¹ doublewrite buffer-related I/Oè¿è¡ç¸åºçä¼åãè¿ç§æ åµä¸ï¼ä¼èªå¨ä½¿ç¨ Fusion-io 设å¤çåååæ¿ä»£ doublewrite buffering (innodb_doublewrite)è¿è¡æ°æ®ç读åãè¿ç§ç¹æ§åªæ¯æ Fusion-io 硬件设å¤å Fusion-io NVMFS Linux åºç¨ãå¯ä»¥éè¿åé innodb_flush_method = O_DIRECT è¿è¡é ç½®ã
Note
设置æ¯å ¨å±æ§çï¼å½±åææ设å¤ä¸çæ°æ®è¯»åã
10ãç¦ç¨å缩æ°æ®é¡µæ¥å¿
ä½¿ç¨ InnoDB 表å缩ç¹æ§æ¶ï¼éæ°å缩çå¾çæ°æ®é¡µï¼å¦ææ°æ®æååï¼åä¼åå ¥ redo logãé ç½®åéinnodb_log_compressed_pages é»è®¤å¯ç¨ï¼é²æ¢æ°æ®åºæ¢å¤æé´ï¼å 为 zlib ç®æ³çååå¼åæ°æ®åºå´©æºãå¦æå¯ä»¥ç¡®è®¤ zlib çæ¬ä¸ä¼åçååï¼é£ä¹å¯ä»¥å ³é innodb_log_compressed_pages åéæ¥åå°éå缩产çç redo log è´è½½ã