{"id":2047,"date":"2010-05-26T21:53:08","date_gmt":"2010-05-26T13:53:08","guid":{"rendered":"http:\/\/www.orczhou.com\/?p=2047"},"modified":"2010-05-26T21:53:08","modified_gmt":"2010-05-26T13:53:08","slug":"innodb-plugin-make-buffer-cache-scan-resistant","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2010\/05\/innodb-plugin-make-buffer-cache-scan-resistant\/","title":{"rendered":"InnoDB Plugin\u7279\u6027\u4ecb\u7ecd\uff1a\u8ba9Buffer Pool\u4e0d\u88ab\u6c61\u67d3"},"content":{"rendered":"<p>\u8f83\u4e4bMyISAM\u7684\u4e00\u4e2a\u5f88\u5927\u7684\u4f18\u52bf\u662f\uff0cInnoDB\u4f1a\u7f13\u5b58\u6570\u636e\u5757\u3002\u5982\u679c\u7cfb\u7edf\u4e2d\u7684\u6570\u636e\u91cf\u5e76\u4e0d\u5927\uff0c\u6216\u8005\u6216\u8005\u6d3b\u8dc3\u6570\u636e\u91cf\u5e76\u4e0d\u5927\u65f6\uff0cInnoDB\u4f1a\u5c06\u8fd9\u4e9b\u6570\u636e\u5757\u5168\u90e8\u7f13\u5b58\u5230Buffer Pool\uff08\u5185\u5b58\uff09\u4e2d\uff0c\u8fd9\u6837\u53ef\u4ee5\u6700\u5927\u9650\u5ea6\u7684\u63d0\u9ad8\u63d0\u4f9b\u7684\u54cd\u5e94\u901f\u5ea6\uff0c\u7279\u522b\u662f\u8bfb\u53d6\u3002\u5f53\u7528\u6237\u8bf7\u6c42\u9700\u8981\u67e5\u8be2\u6570\u636e\u5757\u65f6\uff0cInnoDB\u4f1a\u9996\u5148\u5728Buffer Pool\u4e2d\u67e5\u627e\u6570\u636e\uff0c\u5982\u679cBuffer Pool\u4e2d\u6ca1\u6709\u8be5\u6570\u636e\u5757\u65f6\uff0cInnoDB\u4f1a\u4ece<strong>\u78c1\u76d8<\/strong>\u4e0aLoad\u5bf9\u5e94\u7684\u6570\u636e\u5757\uff0c\u5e76\u901a\u8fc7<a href=\"http:\/\/en.wikipedia.org\/wiki\/Cache_algorithms#Least_Recently_Used\">LRU<\/a>\u7b97\u6cd5\u66ff\u4ee3\u5f53\u524dBuffer Pool\u7684\u7f13\u5b58\u5757\u3002<\/p>\n<p><font color=\"red\">1. Buffer Pool\u4e2dLRU\u7f3a\u70b9\u3001\u7ec6\u8282<\/font><\/p>\n<p>\u8fd9\u6837LRU\u7b97\u6cd5\u7684\u4e00\u4e2a\u7f3a\u70b9\u662f\uff0c\u5982\u679c\u6709\u67d0\u4e00\u4e2a\u67e5\u8be2\u505a\u4e86\u4e00\u6b21\u5168\u8868\u626b\u63cf\uff08\u4f8b\u5982\u5907\u4efd\uff0c\u4e34\u65f6DDL\u7b49\uff09\uff0c\u90fd\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6574\u4e2aBuffer Pool\u4e2dLRU\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5757\u90fd\u88ab\u66ff\u6362\u4e86\uff0c\u751a\u81f3\u5f88\u591a\u70ed\u70b9\u6570\u636e\u4e5f\u4f1a\u88ab\u66ff\u6362\uff0c\u800c\u8fd9\u4e9b\u65b0\u8fdb\u7684\u6570\u636e\u5757\u53ef\u80fd\u5728\u8fd9\u4e00\u6b21\u67e5\u8be2\u4e4b\u540e\u5c31\u518d\u4e5f\u4e0d\u4f1a\u88ab\u8bfb\u5230\u4e86\u3002\u6211\u4eec\u4e5f\u79f0\u8fd9\u79cd\u60c5\u51b5\u4e3a\u201cBuffer Pool\u88ab\u6c61\u67d3\u201d\u4e86\u3002<\/p>\n<p>\u5728InnoDB\u5219\u5f15\u5165\u4e86\u4e00\u4e9b\u65b0\u7684\u673a\u5236\u6765\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u3002\u7b97\u6cd5\u4ecd\u7136\u662fLRU\u7b97\u6cd5\uff0c\u4f46\u662f\u52a0\u4e0a\u4e86\u4e2d\u70b9\u7b56\u7565\uff08\u7c7b\u4f3c\u4e8eMyISAM\u7684k<a href=\"http:\/\/www.orczhou.com\/index.php\/2010\/01\/myisam-key-buffer-2\/\">ey buffer\u4e2d\u7684midpoint strategy<\/a>\uff09\u3002\u540c\u65f6\u5f15\u5165\u4e86\u53c2\u6570<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/innodb-parameters.html#sysvar_innodb_old_blocks_time\">innodb_old_blocks_time<\/a>\u6765\u63a7\u5236Buffer Pool\u4e0d\u88ab\u6c61\u67d3\u3002<\/p>\n<p>LRU\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5206\u4e3a\u4e24\u90e8\u5206\uff1aSublist of new\u548cSublist of old\u3002\u540e\u8005\u5305\u542b\u8bbf\u95ee\u6700\u8fd1\u6ca1\u6709\u8bbf\u95ee\u7684\u6570\u636e\u5757\uff08\u94fe\u8868\u8d8a\u540e\u9762\u7684\u6570\u636e\u5757\uff0c\u6700\u8fd1\u8d8a\u6ca1\u6709\u88ab\u8bbf\u95ee\uff09\u3002\u9ed8\u8ba4\u60c5\u51b5\uff0c\u524d\u8005\u536063%\uff085\/8\uff09\uff0c\u540e\u800537%\uff083\/8\uff09\u3002<\/p>\n<p><a href=\"http:\/\/www.flickr.com\/photos\/26825745@N06\/4641793786\/\" title=\"BufferPoolLRU by orczhou, on Flickr\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm5.static.flickr.com\/4043\/4641793786_547798279e_o.png\" width=\"597\" height=\"326\" alt=\"BufferPoolLRU\" \/><\/a><!--more--><\/p>\n<p>\u5f53\u6570\u636e\u5757\u9700\u8981\u4ece\u6570\u636e\u6587\u4ef6\u4e2d\u8bfb\u53d6\u65f6\uff0c\u9996\u5148\u4f1a\u653e\u5230old sublist\u7684\u5934\u90e8\uff08midpoint\uff09\u3002\u7136\u540e\uff0c\u5982\u679c\u6709\u5bf9\u8fd9\u4e2a\u6570\u636e\u5757\u7684\u8bbf\u95ee\uff0c\u90a3\u4e48\u5c31\u5c06\u8fd9\u4e2a\u6570\u636e\u5757\u653e\u5230new sublist\u7684\u9996\u90e8\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u4e00\u4e2a\u6570\u636e\u5757\u88ab\u53d6\u51fa\u540e\uff0c\u7acb\u523b\u4f1a\u6709\u8bfb\u53d6\uff0c\u4e5f\u5c31\u5f88\u5feb\u4f1a\u88ab\u653e\u5230new sublist\u7684\u5934\u90e8\u3002\u4e00\u79cd\u7cdf\u7cd5\u7684\u60c5\u51b5\u662f\uff0c\u5982\u679c\u662fmysqldump\u8bbf\u95ee\u5168\u90e8\u6570\u636e\u5757\uff0c\u4e5f\u5c31\u4f1a\u5bfc\u81f4\u6240\u6709\u7684\u6570\u636e\u5757\u88ab\u653e\u5230new sublist\u3002\u8fd9\u6837Buffer Pool\u4e5f\u5c31\u5168\u90e8\u88ab\u6c61\u67d3\u4e86\u3002<\/p>\n<p><font color=\"red\">2. Buffer Pool\u4e2dLRU\u961f\u5217\u5982\u4f55\u9632\u6b62\u6c61\u67d3<\/font><\/p>\n<p>InnoDB Plugin\u901a\u8fc7\u5f15\u5165\u5982\u4e0b\u7684\u53c2\u6570\u6765\u9632\u6b62\u201c\u6c61\u67d3\u201d\uff1a<\/p>\n<p><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/innodb-parameters.html#sysvar_innodb_old_blocks_pct\">innodb_old_blocks_pct<\/a>\uff1a \u63a7\u5236old sublist\u5728LRU\u961f\u5217\u7684\u957f\u5ea6<\/p>\n<p><a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/innodb-parameters.html#sysvar_innodb_old_blocks_time\">innodb_old_blocks_time<\/a>\uff1a\u8be5\u53c2\u6570\u51b3\u5b9a\u4e86\uff0c\u5f53Block\u88ab\u63d2\u5165\u5230midpoint\uff08old sublist\uff09\u540e\uff0c\u5fc5\u987b\u8981\u5728old sublist\u505c\u7559\u8d85\u8fc7<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/innodb-parameters.html#sysvar_innodb_old_blocks_time\">innodb_old_blocks_time<\/a>\uff08ms\uff09\u65f6\u95f4\u540e\uff0c\u624d\u6709\u53ef\u80fd\u88ab\u8f6c\u79fb\u5230new sublist\u3002\u4f8b\u5982\uff0c\u5c06innodb_old_blocks_time\u8bbe\u7f6e\u4e3a1000\uff08\u53731s\uff09\uff0c\u5f53\u51fa\u73b0Table scan\u51fa\u73b0\u65f6\uff0cInnoDB\u5148\u5c06\u6570\u636e\u5757\u8f7d\u5165\u5230midpoint\uff08old sublist\uff09\u4e0a\uff0c\u7a0b\u5e8f\u8bfb\u53d6\u6570\u636e\u5757\uff0c\u56e0\u4e3a\u8fd9\u65f6\uff0c\u6570\u636e\u5757\u5728old sublist\u4e2d\u7684\u505c\u7559\u65f6\u95f4\u8fd8\u4e0d\u5230innodb_old_blocks_time\uff0c\u6240\u4ee5\u4e0d\u4f1a\u88ab\u8f6c\u79fb\u5230new sublist\u4e2d\u3002\u8fd9\u5c31\u907f\u514d\u4e86Buffer Pool\u88ab\u6c61\u67d3\u7684\u60c5\u51b5\u3002\u66f4\u9177\u7684\u662f\uff0c\u8fd9\u4e2a\u53c2\u6570\u662f\u52a8\u6001\u8c03\u6574\u7684\uff0c\u6240\u4ee5\u5728\u505a\u610f\u5916\u7684Table scan\u65f6\uff0c\u52a8\u6001\u8c03\u6574\u4e00\u4e0b\u8be5\u53c2\u6570\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p><font color=\"red\">3. \u9632\u6c61\u67d3\u7684\u6548\u7387\u89c2\u5bdf<\/font><\/p>\n<p>\u53ef\u4ee5\u6839\u636eSHOW INNODB STATUS\\G\u4e2dBuffer Pool\u6bb5\u5f00\u770b\u770b\u76f8\u5173\u6548\u7387\uff1a<\/p>\n<div class=\"mycode\">Total memory allocated 1107296256; in additional pool allocated 0<br \/>\nDictionary memory allocated 80360<br \/>\nBuffer pool size   65535<br \/>\nFree buffers       0<br \/>\nDatabase pages     63920<br \/>\nOld database pages 23600<br \/>\nModified db pages  34969<br \/>\nPending reads 32<br \/>\nPending writes: LRU 0, flush list 0, single page 0<br \/>\nPages made young 414946, not young 2930673<br \/>\n1274.75 youngs\/s, 16521.90 non-youngs\/s<br \/>\nPages read 486005, created 3178, written 160585<br \/>\n2132.37 reads\/s, 3.40 creates\/s, 323.74 writes\/s<br \/>\nBuffer pool hit rate 950 \/ 1000, young-making rate 30 \/ 1000 not 392 \/ 1000<br \/>\nPages read ahead 1510.10\/s, evicted without access 0.00\/s<br \/>\nLRU len: 63920, unzip_LRU len: 0<br \/>\nI\/O sum[43690]:cur[221], unzip sum[0]:cur[0]<\/div>\n<p>\u89e3\u91ca\uff1aOld database pages \u8868\u793aLRU\u5217\u8868\u4e2dold sublist\u4e2d\u7684\u6570\u636e\u5757\u6570\u91cf\u3002<\/p>\n<p>Pages made young and not young\u8868\u793aold sublist\u4e2d\u6709\u591a\u5c11\u6570\u636e\u5757\u662f\uff08\u6ca1\uff09\u88ab\u8f6c\u79fb\u5230new sublist\u3002<\/p>\n<p>youngs\/s and non-young\/s \u4ece\u4e0a\u6b21\u6267\u884cSHOW INNODB STATUS\u5230\u73b0\u5728\u4e3a\u6b62\uff0c\u8bbf\u95eeOld sublist\u65f6\u6709\u591a\u5c11\u5c06\u6570\u636e\u5757\u8f6c\u79fb\u5230new sublist\uff0c\u6709\u591a\u5c11\u662f\u6ca1\u6709\u8f6c\u79fb\u7684\uff08\u8fd9\u91cc\u53ef\u4ee5\u770b\u51fa\u53c2\u6570<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/innodb-parameters.html#sysvar_innodb_old_blocks_time\">innodb_old_blocks_time<\/a>\u7684\u6548\u7387\uff09\u3002<\/p>\n<p>young-making rate and not \u53cd\u6620\u7684\u662f\u5168\u90e8Buffer Pool\u8bbf\u95ee\u4e2d\uff0c\u5c06\uff08\u6ca1\u6709\u5c06\uff09old sublist\u4e2d\u8f6c\u79fbnew sublist\u7684\u6bd4\u7387\u3002<\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<p>\u30101\u3011. <a href=\"http:\/\/www.innodb.com\/doc\/innodb_plugin-1.0\/innodb-performance.html#innodb-performance-midpoint_insertion\">Making Buffer Cache Scan Resistant<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f83\u4e4bMyISAM\u7684\u4e00\u4e2a\u5f88\u5927\u7684\u4f18\u52bf\u662f\uff0cInnoDB\u4f1a\u7f13\u5b58\u6570\u636e\u5757\u3002\u5982\u679c\u7cfb\u7edf\u4e2d\u7684\u6570\u636e\u91cf\u5e76\u4e0d\u5927\uff0c\u6216\u8005\u6216\u8005\u6d3b\u8dc3\u6570\u636e\u91cf\u5e76\u4e0d\u5927\u65f6\uff0cInnoDB\u4f1a\u5c06\u8fd9\u4e9b\u6570\u636e\u5757\u5168\u90e8\u7f13\u5b58\u5230Buffer Pool\uff08\u5185\u5b58\uff09\u4e2d\uff0c\u8fd9\u6837\u53ef\u4ee5\u6700\u5927\u9650\u5ea6\u7684\u63d0\u9ad8\u63d0\u4f9b\u7684\u54cd\u5e94\u901f\u5ea6\uff0c\u7279\u522b\u662f\u8bfb\u53d6\u3002\u5f53\u7528\u6237\u8bf7\u6c42\u9700\u8981\u67e5\u8be2\u6570\u636e\u5757\u65f6\uff0cInnoDB\u4f1a\u9996\u5148\u5728Buffer Pool\u4e2d\u67e5\u627e\u6570\u636e\uff0c\u5982\u679cBuffer Pool\u4e2d\u6ca1\u6709\u8be5\u6570\u636e\u5757\u65f6\uff0cInnoDB\u4f1a\u4ece\u78c1\u76d8\u4e0aLoad\u5bf9\u5e94\u7684\u6570\u636e\u5757\uff0c\u5e76\u901a\u8fc7LRU\u7b97\u6cd5\u66ff\u4ee3\u5f53\u524dBuffer Pool\u7684\u7f13\u5b58\u5757\u3002 1. Buffer Pool\u4e2dLRU\u7f3a\u70b9\u3001\u7ec6\u8282 \u8fd9\u6837LRU\u7b97\u6cd5\u7684\u4e00\u4e2a\u7f3a\u70b9\u662f\uff0c\u5982\u679c\u6709\u67d0\u4e00\u4e2a\u67e5\u8be2\u505a\u4e86\u4e00\u6b21\u5168\u8868\u626b\u63cf\uff08\u4f8b\u5982\u5907\u4efd\uff0c\u4e34\u65f6DDL\u7b49\uff09\uff0c\u90fd\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6574\u4e2aBuffer Pool\u4e2dLRU\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5757\u90fd\u88ab\u66ff\u6362\u4e86\uff0c\u751a\u81f3\u5f88\u591a\u70ed\u70b9\u6570\u636e\u4e5f\u4f1a\u88ab\u66ff\u6362\uff0c\u800c\u8fd9\u4e9b\u65b0\u8fdb\u7684\u6570\u636e\u5757\u53ef\u80fd\u5728\u8fd9\u4e00\u6b21\u67e5\u8be2\u4e4b\u540e\u5c31\u518d\u4e5f\u4e0d\u4f1a\u88ab\u8bfb\u5230\u4e86\u3002\u6211\u4eec\u4e5f\u79f0\u8fd9\u79cd\u60c5\u51b5\u4e3a\u201cBuffer Pool\u88ab\u6c61\u67d3\u201d\u4e86\u3002 \u5728InnoDB\u5219\u5f15\u5165\u4e86\u4e00\u4e9b\u65b0\u7684\u673a\u5236\u6765\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u3002\u7b97\u6cd5\u4ecd\u7136\u662fLRU\u7b97\u6cd5\uff0c\u4f46\u662f\u52a0\u4e0a\u4e86\u4e2d\u70b9\u7b56\u7565\uff08\u7c7b\u4f3c\u4e8eMyISAM\u7684key buffer\u4e2d\u7684midpoint strategy\uff09\u3002\u540c\u65f6\u5f15\u5165\u4e86\u53c2\u6570innodb_old_blocks_time\u6765\u63a7\u5236Buffer Pool\u4e0d\u88ab\u6c61\u67d3\u3002 LRU\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5206\u4e3a\u4e24\u90e8\u5206\uff1aSublist of new\u548cSublist of old\u3002\u540e\u8005\u5305\u542b\u8bbf\u95ee\u6700\u8fd1\u6ca1\u6709\u8bbf\u95ee\u7684\u6570\u636e\u5757\uff08\u94fe\u8868\u8d8a\u540e\u9762\u7684\u6570\u636e\u5757\uff0c\u6700\u8fd1\u8d8a\u6ca1\u6709\u88ab\u8bbf\u95ee\uff09\u3002\u9ed8\u8ba4\u60c5\u51b5\uff0c\u524d\u8005\u536063%\uff085\/8\uff09\uff0c\u540e\u800537%\uff083\/8\uff09\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":[52],"class_list":["post-2047","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-innodb-plugin"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2047","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=2047"}],"version-history":[{"count":7,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2047\/revisions"}],"predecessor-version":[{"id":2054,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2047\/revisions\/2054"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=2047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=2047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=2047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}