{"id":2260,"date":"2010-08-11T23:13:18","date_gmt":"2010-08-11T15:13:18","guid":{"rendered":"http:\/\/www.orczhou.com\/?p=2260"},"modified":"2011-12-20T23:29:08","modified_gmt":"2011-12-20T15:29:08","slug":"time-to-group-commit-1","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2010\/08\/time-to-group-commit-1\/","title":{"rendered":"MySQL\/InnoDB\u548cGroup Commit(1)"},"content":{"rendered":"<p>\u4f30\u8ba1\u76f8\u5173\u7684\u4e1c\u897f\u4e00\u7bc7\u6587\u7ae0\u662f\u8bb2\u4e0d\u6e05\u695a\u7684\u3002<\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898<a href=\"http:\/\/bugs.mysql.com\/bug.php?id=13669\">\u7531\u6765\u5df2\u4e45<\/a>\uff0cKristian Nielsen\u8fde\u7eed\u5199\u4e86\u56db\u7bc7\u6587\u7ae0\u300aFixing MySQL group commit\u300b(<a href=\"http:\/\/kristiannielsen.livejournal.com\/12254.html\">part 1<\/a> | <a href=\"http:\/\/kristiannielsen.livejournal.com\/12408.html\">part 2<\/a> | <a href=\"http:\/\/kristiannielsen.livejournal.com\/12553.html\">part 3<\/a> | <a href=\"http:\/\/kristiannielsen.livejournal.com\/12810.html\">part 4<\/a>  )\u6df1\u5165\u7ec6\u81f4\u7684\u5206\u6790\u4e86\u201c\u6545\u4e8b\u201d\u7684\u524d\u56e0\u540e\u679c\u3002\u672c\u6587\u5b8c\u5168\u6ca1\u6709\u4efb\u4f55\u65b0\u610f\uff0c\u4ec5\u505a\u4e00\u4e2a\u5c0f\u7684\u603b\u7ed3\u3002\u8fd9\u91cc\u4f1a\u5148\u4ecb\u7ecd\u4e00\u4e0b\u4ec0\u4e48\u662f\u201cGroup Commit\u201d\uff0cMySQL\/InnoDB\u91cc\u9762\u7684Group Commit\u4e3a\u4ec0\u4e48\u5f15\u8d77\u5982\u6b64\u5927\u7684\u5173\u6ce8\uff0c\u73b0\u5728\u662f\u600e\u4e48\u89e3\u51b3\u95ee\u9898\u7684\u3002<!--more--><\/p>\n<div class=\"myt1\">1. \u4ec0\u4e48\u662fGroup Commit<\/div>\n<p>\u7b80\u5355\u7684\uff0cInnoDB\u5728\u6bcf\u6b21\u63d0\u4ea4\u4e8b\u52a1\u65f6\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6570\u636e\u5df2\u7ecf\u6301\u4e45\u5316\u5230\u78c1\u76d8\uff08Durable\uff09\uff0c\u9700\u8981\u8c03\u7528\u4e00\u6b21fsync\uff08\u6216\u8005\u662ffdatasync\u3001\u6216\u8005\u4f7f\u7528O_DIRECT\u9009\u9879\u7b49\uff09\u6765\u544a\u77e5\u6587\u4ef6\u7cfb\u7edf\u5c06\u53ef\u80fd\u5728\u7f13\u5b58\u4e2d\u7684\u6570\u636e\u5237\u65b0\u5230\u78c1\u76d8\uff08\u66f4\u591a\u5173\u4e8e<a href=\"http:\/\/www.orczhou.com\/index.php\/2009\/08\/innodb_flush_method-file-io\/\">fsync<\/a>\uff09\u3002\u800cfsync\u64cd\u4f5c\u672c\u8eab\u662f\u975e\u5e38\u201c\u6602\u8d35\u201d\u7684\uff08\u5173\u4e8e\u201c\u6602\u8d35\u201d\uff1a\u6d88\u8017\u8f83\u591a\u7684IO\u8d44\u6e90\uff0c\u54cd\u5e94\u8f83\u6162\uff09\uff1a\u4f20\u7edf\u786c\u76d8\uff0810K\u8f6c\/\u5206\u949f\uff09\u5927\u7ea6\u6bcf\u79d2\u652f\u6491150\u4e2afsync\u64cd\u4f5c\uff0cSSD\uff08Intel X25-M\uff09\u5927\u7ea6\u6bcf\u79d2\u652f\u64911200\u4e2afsync\u64cd\u4f5c\u3002\u6240\u4ee5\uff0c\u5982\u679c\u6bcf\u6b21\u4e8b\u52a1\u63d0\u4ea4\u90fd\u5355\u72ec\u505afsync\u64cd\u4f5c\uff0c\u90a3\u4e48\u8fd9\u91cc\u5c06\u662f\u7cfb\u7edfTPS\u7684\u4e00\u4e2a\u74f6\u9888\u3002\u6240\u4ee5\u5c31\u6709\u4e86Group Commit\u7684\u6982\u5ff5\u3002<\/p>\n<p>\u5f53\u591a\u4e2a\u4e8b\u52a1\u5e76\u53d1\u65f6\uff0c\u6211\u4eec\u8ba9\u591a\u4e2a\u90fd\u5728\u7b49\u5f85fsync\u7684\u4e8b\u52a1\u4e00\u8d77\u5408\u5e76\u4e3a\u4ec5\u8c03\u7528\u4e00\u6b21fsync\u64cd\u4f5c\u3002\u8fd9\u6837\u7684\u4e00\u4e2a\u7b80\u5355\u7684\u4f18\u5316\u5c06\u5927\u5927\u63d0\u9ad8\u7cfb\u7edf\u7684\u541e\u5410\u91cf\uff0cYoshinori Matsunobu\u7684<a href=\"http:\/\/yoshinorimatsunobu.blogspot.com\/2009\/08\/great-performance-effect-of-fixing.html\">\u5b9e\u9a8c<\/a>\u8868\u660e\uff0c\u8fd9\u5c06\u5e26\u6765\u4e94\u5230\u516d\u500d\u7684\u6027\u80fd\u63d0\u5347\u3002<\/p>\n<div class=\"myt1\">2. MySQL\/InnoDB\u4e0eGroup Commit<\/div>\n<p>MySQL5.0\u5f00\u59cb\uff0cInnoDB\u5c31\u4e0d\u518d\u652f\u6301Group Commit\u4e86\u3002\u57282005\u5e74\uff0cPeter Zaitsev\u5c31\u5c06\u6b64\u4f5c\u4e3a\u4e00\u4e2a<a href=\"http:\/\/bugs.mysql.com\/bug.php?id=13669\">Bug<\/a>\u63d0\u4ea4\uff0c\u76f4\u52302009\u5e74\u5728InnoDB Plugin1.0.4\u624d\u5c06\u6b64\u95ee\u9898\u4fee\u590d\u3002<\/p>\n<div class=\"myt2\">2.1 \u4e3a\u4ec0\u4e485.0\u4e4b\u540eMySQL\/InnoDB\u65e0\u6cd5\u652f\u6301Group Commit<\/div>\n<p>\u7a76\u5176\u66f4\u672c\u539f\u56e0\u53d1\u73b0\uff0c5.0\u4e4b\u540eMySQL\u5f00\u59cb\u652f\u6301\u201c\u5206\u5e03\u5f0f\u4e8b\u52a1\u548c\u4e24\u9636\u6bb5\u63d0\u4ea4\u534f\u8bae\u201d\uff08distributed transactions and Two Phase Commit \/2PC\uff09\uff0c\u5728\u4ee3\u7801\u5b9e\u73b0\u65f6\u4e3a\u4e86\u4fdd\u8bc1Binlog\u4e2d\u7684\u4e8b\u52a1\u987a\u5e8f\u548cInnoDB Log\uff08Transaction Log\u6216\u8005\u53ebredo log\uff09\u4e8b\u52a1\u987a\u5e8f\u4e00\u81f4\uff0c\u88ab\u52a8\u653e\u5f03\u4e86Group Commit\u3002\u5982\u679cBinlog\u987a\u5e8f\u4e0d\u4e00\u81f4\uff0c\u90a3\u4e48\u5907\u5e93\u5c31\u65e0\u6cd5\u786e\u4fdd\u548c\u4e3b\u5e93\u6709\u4e00\u81f4\u7684\u6570\u636e\u3002\u53c2\u8003\u4e0a\u9762\u7684Part 2\u7ed9\u51fa\u4ee3\u7801\u76f8\u5173\u7684\u89e3\u91ca\uff1a<\/p>\n<p>InnoDB\u672c\u8eab\u7684\u4ee3\u7801\u5b9e\u73b0\u662f\u53ef\u4ee5\u652f\u6301Group Commit\u7684\uff0c\u6211\u4eec\u6765\u770b\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<div class=\"myt2\">\u7b2c\u4e00\u9636\u6bb5\uff1a\u5728\u5185\u5b58\u4e2d\u6ce8\u518c\u4e8b\u52a1commit\uff08\u8fd8\u6ca1\u6709\u6301\u4e45\u5316\uff0c\u8fd9\u662f\u6bd4\u8f83\u5feb\u7684\uff09<\/div>\n<div class=\"mycode\"> trx->flush_log_later = TRUE;<br \/>\n innobase_commit_low(trx);<br \/>\n trx->flush_log_later = FALSE;<\/div>\n<div class=\"myt2\">\u7b2c\u4e8c\u9636\u6bb5\uff1a\u8c03\u7528write\u548cfsync<\/div>\n<div class=\"mycode\"> trx_commit_complete_for_mysql(trx)<\/div>\n<p>\u4e0a\u9762\u7684\u7b2c\u4e8c\u4e2a\u9636\u6bb5\u6570\u636e\u6301\u4e45\u5316\u662f\u6bd4\u8f83\u6162\u7684\uff0c\u6240\u4ee5\u5f53\u591a\u7ebf\u7a0b\u5e76\u53d1\u5b8c\u6210\u7b2c\u4e00\u9636\u6bb5\u540e\uff0c\u53ef\u4ee5\u4e00\u8d77\u53ea\u8c03\u7528\u4e00\u6b21fsync\u6765\u6301\u4e45\u5316\u5168\u90e8\u6570\u636e\uff08fsync\u5e94\u8be5\u662f\u4ee5\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e3a\u5355\u4f4d\u7684\uff09\u3002<\/p>\n<p>\u5982\u679c\u6253\u5f00\u4e86\u4e8c\u8fdb\u5236\u65e5\u5fd7\uff0c\u90a3\u4e48\u4ee3\u7801\u5c31\u6709\u4e9b\u4e0d\u4e00\u6837\u4e86\u3002MySQL\u4f7f\u7528\u4e86\u201c\u4e24\u9636\u6bb5\u63d0\u4ea4\u201d\uff08XA\/2-phase commit \uff09\u6765\u4fdd\u8bc1\u5b58\u50a8\u5f15\u64ce\u548c\u4e8c\u8fdb\u5236\u65e5\u5fd7\u7684\u4e00\u81f4\uff0c\u5728\u4e0a\u9762\u7684\u8fc7\u7a0b\u4e4b\u524d\u6709\u591a\u4e86\u4e00\u6b65\uff1a<\/p>\n<div class=\"mycode\">    innobase_xa_prepare()<br \/>\n    write() and fsync() binary log<br \/>\n    innobase_commit()<\/div>\n<p><span style=\"color:red;font-weight:bold;\">\u5728innobase_xa_prepare\u51fd\u6570\u4e2d\u9700\u8981\u83b7\u53d6\u6392\u4ed6\u9501<a href=\"http:\/\/www.orczhou.com\/index.php\/2010\/06\/mysql-innodb-source-code-sync-1\/\">prepare_commit_mutex<\/a>\uff0c\u76f4\u5230\u4e0a\u9762\u7684innodb_commit\u7ed3\u675f\u9501\u624d\u91ca\u653e\uff0c\u6240\u4ee5\u4e0a\u9762\u7684binlog write and fsync\u4e5f\u5c31\u65e0\u6cd5Group\u64cd\u4f5c\u4e86\uff08\u5f53binlog_sync=1\u65f6\uff09<\/span>\u3002\u5f53\u8bbe\u7f6eBinlog_sync=1\u65f6\uff0cInnoDB\u5c31\u65e0\u6cd5\u505aGroup_commit\u4e86\uff0c\u5982\u679cprepare_commit_mutex\u63d0\u524d\u91ca\u653e\u4e86\uff0c\u5219\u53ef\u80fd\u5bfc\u81f4InnoDB\u5185\u90e8\u7684\u4e8b\u52a1\u987a\u5e8f\u548cBinlog\u5185\u90e8\u4e8b\u52a1\u7684\u987a\u5e8f\u4e0d\u4e00\u81f4(\u8fd9\u91cc\u503c\u5f97\u5546\u69b7\uff0c\u53c2\u8003\u4e0b\u9762\u7684\u53c2\u8003\u6587\u732e6)\u3002<\/p>\n<div class=\"myt2\">2.2 Facebook\u7684\u89e3\u51b3\u65b9\u6848<\/div>\n<p>Facebook\u4f5c\u4e3a\u4e00\u4e2aSNS\uff08Social network service\uff09\u7f51\u7ad9\uff0c\u5728\u4e92\u8054\u7f51\u754c\u5df2\u7ecf\u521b\u9020\u4e86\u5947\u8ff9\u3002\u5728\u6280\u672f\u9886\u57dfFacebook\u4e5f\u4e3a\u5f00\u6e90\u793e\u533a\uff08\u5305\u62ecMySQL PHP Linux\u7b49\uff09\u505a\u4e86\u5f88\u591a\u7684\u6770\u51fa\u7684\u8d21\u732e\uff0c\u5e0c\u671b\u6211\u4eec\u516c\u53f8\u80fd\u4ee5\u6b64\u4e3a\u76ee\u6807\u3002<\/p>\n<p>\u5f00\u6e90\u793e\u533a\u4e3a\u6b64\u4e5f\u5c55\u5f00\u4e86\u5f88\u591a\u8ba8\u8bba\uff0cMark Callaghan\uff08Facebook\uff09\u63d0\u51fa\u7684&#8221;<a href=\"http:\/\/www.facebook.com\/note.php?note_id=386328905932\">Ticket System<\/a>&#8220;\u76ee\u524d\u770b\u5230\u7684\u6700\u7b80\u6d01\u800c\u6709\u6548\u7684\u5b9e\u73b0\u3002<\/p>\n<p>Facebook\u5c1d\u8bd5\u4e24\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u4e00\uff0c\u901a\u8fc7\u4e00\u4e2aInnoDB\u7684UT_LIST\u94fe\u8868\u6765\u786e\u4fddInnoDB\u548cBinlog\u5185\u90e8\u7684\u987a\u5e8f\u4e00\u81f4\uff1b\u4e8c\uff0c\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u201cTicket System\u201d\uff0c\u5f53\u591a\u4e2a\u7ebf\u7a0b\u90fd\u8fdb\u5165innobase_xa_prepare()\u9636\u6bb5\u65f6\uff0c\u5c31\u5206\u914d\u4e00\u4e2a&#8221;ticket&#8221;\u503c\uff0c\u5e76\u4e14\u5206\u914d\u7684ticket\u503c\u662f\u5355\u8c03\u589e\u52a0\u7684\u3002\u5f53\u7ebf\u7a0b\u7684binlog\u51c6\u5907commit\u65f6\uff0c\u5fc5\u987b\u4fdd\u8bc1\u5c0f\u4e8e\u5f53\u524dticket\u7684binlog\u90fd\u63d0\u4ea4\u4e86\uff0c\u5982\u679c\u8fd9\u65f6\u6709\u591a\u4e2a\u4e8b\u52a1\u7684binlog\u5219\u53ef\u4ee5\u540c\u65f6\u5408\u5e76\u63d0\u4ea4\u3002<\/p>\n<p>\u8fd9\u91cc\u53ef\u4ee5\u770b\u5230\u76f8\u5173\u7684\u6027\u80fd\u6d4b\u8bd5\u60c5\u51b5\uff1a<a href=\"http:\/\/www.facebook.com\/note.php?note_id=386328905932\">Laying the foundatation for group commit<\/a><\/p>\n<div class=\"myt2\">2.2 InnoDB Plugin<\/div>\n<p>\u5728InnoDB Plugin 1.0.4<strong>\u58f0\u79f0<\/strong>\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\u3002\u4e0b\u9762\u662fPlugin\u624b\u518c\u4e0a\u7684\u4e00\u6bb5\u539f\u8bdd\uff1a<\/p>\n<blockquote><p>\nBeginning with InnoDB Plugin 1.0.4, the group commit functionality inside InnoDB works with the Two Phase Commit protocol in MySQL. Re-enabling of the group commit functionality fully ensures that the ordering of commit in the MySQL binlog and the InnoDB logfile is the same as it was before.\n<\/p><\/blockquote>\n<p>\u76f8\u5173\u7684<a href=\"http:\/\/www.innodb.com\/wp\/products\/innodb_plugin\/plugin-performance\/innodb-plugin-1-0-4-group-commit-test-sysbench\/\">\u6027\u80fd\u6d4b\u8bd5\u6570\u636e<\/a>\u3002\uff08sync_binlog = 0\u65f6\uff09<\/p>\n<p>\u5f88\u9057\u61be\uff0c\u6211\u8fd8\u4e0d\u77e5\u9053\u5177\u4f53\u7684\u5b9e\u73b0\u7ec6\u8282\uff0c\u4e5f\u8fd8\u6ca1\u6709\u53bb\u68c0\u67e5\u6e90\u4ee3\u7801\u770b\u770b\u6709\u6ca1\u6709\u76f8\u5173\u5b9e\u73b0\u8bf4\u660e\u3002<\/p>\n<p>Update 2011-07-25: InnoDB Plugin\u5173\u4e8eGroup commit\u4ee3\u7801\u5728storage\/innobase\/trx\/trx0trx.c\u4e2d\u5b9e\u73b0\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u9605\u8bfb\u3002<\/p>\n<p>Update(2011-11-06):\u5f53sync_binlog = 0\uff0cMySQL\u5e76\u4e0d\u80fdGroup commit\u3002<\/p>\n<p>Update(2011-12-20):\u5f53\u6253\u5f00\u4e8c\u8fdb\u5236\u65e5\u5fd7\u65f6\uff0cMySQL\u5982\u4f55\u63d0\u4ea4\u4e8b\u52a1(\u8fd9\u662f\u4e00\u4e2a\u4e24\u9636\u6bb5\u63d0\u4ea4)\uff1a<\/p>\n<blockquote><p>\n    binlog_prepare (do nothing)<br \/>\n    innodb_prepare<br \/>\n    &#8230;<br \/>\n    binlog_commit<br \/>\n    innobase_commit\n<\/p><\/blockquote>\n<div class=\"myt2\">\u53c2\u8003\u6587\u732e<\/div>\n<p>1. <a href=\"http:\/\/mysqlmusings.blogspot.com\/2010\/04\/binary-log-group-commit-implementation.html\">Binary Log Group Commit &#8211; An Implementation Proposal<\/a><\/p>\n<p>2. <a href=\"http:\/\/www.chriscalender.com\/?p=99\">Ease of Switching to the InnoDB Plugin and the Numerous Benefits<\/a><\/p>\n<p>3. <a href=\"http:\/\/ronaldbradford.com\/blog\/eventually-consistent-group-commit-2010-06-01\/\">Eventually consistent Group Commit <\/a><\/p>\n<p>4. <a href=\"http:\/\/www.mysqlperformanceblog.com\/2009\/08\/11\/innodb-plugin-1-0-4-released-great-job-innobase\/\">Innodb plugin 1.0.4 released \u2013 great job Innobase<\/a><\/p>\n<p>5. <a href=\"http:\/\/www.percona.com\/docs\/wiki\/percona-xtradb:specs:fix_broken_group_commit\">The followings are just my current understanding about broken group commit<\/a><\/p>\n<p>6. Fixing MySQL group commit <a href=\"http:\/\/kristiannielsen.livejournal.com\/12254.html\">part 1<\/a> | <a href=\"http:\/\/kristiannielsen.livejournal.com\/12408.html\">part 2<\/a> | <a href=\"http:\/\/kristiannielsen.livejournal.com\/12553.html\">part 3<\/a> | <a href=\"http:\/\/kristiannielsen.livejournal.com\/12810.html\">part 4<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f30\u8ba1\u76f8\u5173\u7684\u4e1c\u897f\u4e00\u7bc7\u6587\u7ae0\u662f\u8bb2\u4e0d\u6e05\u695a\u7684\u3002 \u8fd9\u4e2a\u95ee\u9898\u7531\u6765\u5df2\u4e45\uff0cKristian Nielsen\u8fde\u7eed\u5199\u4e86\u56db\u7bc7\u6587\u7ae0\u300aFixing MySQL group commit\u300b(part 1 | part 2 | part 3 | part 4 )\u6df1\u5165\u7ec6\u81f4\u7684\u5206\u6790\u4e86\u201c\u6545\u4e8b\u201d\u7684\u524d\u56e0\u540e\u679c\u3002\u672c\u6587\u5b8c\u5168\u6ca1\u6709\u4efb\u4f55\u65b0\u610f\uff0c\u4ec5\u505a\u4e00\u4e2a\u5c0f\u7684\u603b\u7ed3\u3002\u8fd9\u91cc\u4f1a\u5148\u4ecb\u7ecd\u4e00\u4e0b\u4ec0\u4e48\u662f\u201cGroup Commit\u201d\uff0cMySQL\/InnoDB\u91cc\u9762\u7684Group Commit\u4e3a\u4ec0\u4e48\u5f15\u8d77\u5982\u6b64\u5927\u7684\u5173\u6ce8\uff0c\u73b0\u5728\u662f\u600e\u4e48\u89e3\u51b3\u95ee\u9898\u7684\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6],"tags":[59,120,118],"class_list":["post-2260","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-group-commit","tag-innodb","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=2260"}],"version-history":[{"count":33,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2260\/revisions"}],"predecessor-version":[{"id":2937,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2260\/revisions\/2937"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=2260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=2260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=2260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}