{"id":1142,"date":"2011-12-08T13:45:00","date_gmt":"2011-12-08T05:45:00","guid":{"rendered":"\/?p=1142"},"modified":"2011-12-08T13:45:00","modified_gmt":"2011-12-08T13:45:00","slug":"1142","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/mysql\/1142.html","title":{"rendered":"HandlerSocket: \u4eceMySQL\u5230NoSQL\u7684\u8fc7\u6e21\u66ff\u4ee3\u65b9\u6848\uff1f"},"content":{"rendered":"

       HandlerSocket\u662fMySQL\u7684\u4e00\u4e2aPlugin\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u76f4\u63a5\u8ddfMySQL\u7684Storage Engine Layer(\u6bd4\u5982InnoDB\uff09\u4ea4\u4e92\uff0c\u800c\u4e0d\u9700\u8981\u901a\u8fc7MySQL\u7684Parser Layer\u3002\u4ece\u6027\u80fd\u89d2\u5ea6\u6709\u5f88\u5927\u7684\u63d0\u5347\u3002<\/span><\/p>\n

       HandlerSocket\u7279\u522b\u9002\u7528\u4e8e\u6d77\u91cf\u6570\u636e\u3001\u9ad8\u5e76\u53d1\u7684\u5177\u6709\u7b80\u5355\u4e1a\u52a1\u6a21\u578b\u7684\u5e94\u7528\uff0c\u6bd4\u5982\u5fae\u535a\u3001Feed\u3002\u53ef\u4ee5\u7528\u6765\u66ff\u4ee3\u4f20\u7edfMemcached+MySQL\u7684\u65b9\u5f0f\uff0c\u800c\u4e14\u6027\u80fd\u4e0a\u4e5f\u63a5\u8fd1\u4e8e\u76ee\u524d\u4e3b\u6d41\u7684NoSQL\u4ea7\u54c1\uff0c\u6240\u4ee5\u8fd8\u662f\u6709\u6bd4\u8f83\u5927\u7684\u4f18\u52bf\u3002\u4f46\u662f\u9700\u8981\u6e05\u695a\u7406\u6027\u7684\u770b\u5f85\u8fd9\u4e2a\u95ee\u9898\uff0c\u7531\u4e8e\u76ee\u524d\u8fd8\u521a\u53d1\u5e03\u4e0d\u4e45\uff0c\u8fd8\u8fdc\u6ca1\u6709Memcached+MySQL\u6210\u719f\uff0c\u6240\u4ee5\uff0c\u8fd8\u662f\u9700\u8981\u66f4\u591a\u7684\u529f\u80fd\u548c\u6027\u80fd\u6d4b\u8bd5\uff0c\u66f4\u591a\u5730\u53bb\u7814\u7a76\u5b83\u7684\u6e90\u4ee3\u7801\uff0c\u8fd9\u6837\u624d\u80fd\u66f4\u52a0\u653e\u5fc3\u7684\u4f7f\u7528\u3002\u73b0\u5728\u7684Memcached+MySQL\u7684\u65b9\u5f0f\u8fd8\u662f\u5f88\u597d\u7684\u65b9\u5f0f\uff0c\u6211\u89c9\u5f97\u8fd8\u5c06\u4f1a\u957f\u4e45\u4e0b\u53bb\uff0cHandlerSocket+MySQL\u7684\u51fa\u73b0\uff0c\u662f\u7ed9\u5927\u5bb6\u591a\u4e86\u4e00\u4e2a\u9009\u62e9\u3002 <\/p>\n<\/p>\n

\u4e00\u3001HandlerSocket\u6574\u4f53\u67b6\u6784<\/strong><\/p>\n

HandlerSocket\u8bbe\u8ba1\u4e3aMySQL\u7684\u4e00\u4e2aplugin\uff0c\u4f5c\u4e3amysqld\u8fdb\u7a0b\u7684daemon\u5b58\u5728\uff0c\u4e0eClient\u901a\u8fc7TCP\/IP\u4ea4\u4e92\uff0c\u8fdb\u884cCRUD\u76f8\u5173\u7684\u64cd\u4f5c\u3002\u57fa\u4e8e\u6b64\u539f\u56e0\uff0c\u4e0d\u4ec5\u53ef\u4ee5\u901a\u8fc7HandlerSocket\u64cd\u4f5c\u5b58\u50a8\u5c42\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4f20\u7edf\u7684MySQL\u7684\u65b9\u5f0f\u6765\u64cd\u4f5c\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9e\u73b0\uff1a\u7b80\u5355\u5feb\u901f\u7684\u64cd\u4f5c\u901a\u8fc7HandlerSocket\u6765\u5b9e\u73b0\uff0c\u800c\u5bf9\u4e8e\u4e00\u4e9b\u590d\u6742\u7684\u64cd\u4f5c\uff0c\u8fd8\u662f\u901a\u8fc7\u4f20\u7edf\u7684MySQL\u65b9\u5f0f\u6765\u5b9e\u73b0\u3002<\/p>\n

 <\/p>\n

HandlerSocket\u7684\u7ed3\u6784\u56fe\u5982\u4e0b\uff08\u56fe\u7247\u6765\u81ea\u4f5c\u8005Blog\uff09\uff1a<\/p>\n

<\/p>\n

 <\/p>\n

\u8fd9\u91cc\u5206\u4e24\u6761\u4e3b\u7ebf\u6765\u5206\u6790\u4e0a\u56fe\uff1a
1. MySQL Client -> MySQL Upper Layer -> Storage Engine Layer
\u8fd9\u662f\u4f20\u7edf\u7684\u4f7f\u7528MySQL\u7684\u65b9\u5f0f\uff0cMySQL\u5ba2\u6237\u7aef\u901a\u8fc73306\u7aef\u53e3\u4e0eUpper\u5c42\u4ea4\u4e92\uff0c\u5728Upper\u5c42\u505aSQL\u89e3\u6790\u3001\u6253\u5f00\u8868\u3001\u67e5\u8be2\u8ba1\u5212\u4f18\u5316\u3001\u5173\u95ed\u8868\u7b49\u64cd\u4f5c\uff0c\u7136\u540e\u63d0\u4ea4\u5230Storage\u5c42\u3002<\/p>\n

2. HandlerSocket Client -> HandlerSocket daemon plugin -> Storage Engine Layer
\u8fd9\u662f\u91c7\u7528HandlerSocket\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7\u6bd4\u8f83MySQL Upper Layer\u548cHandlerSocket daemon plugin\uff0c\u53ef\u4ee5\u660e\u663e\u770b\u51fa\uff0cHandlerSocket\u51cf\u5c11\u4e86\u5f88\u591a\u64cd\u4f5c\uff0c\u8fd9\u6b63\u662f\u6027\u80fd\u5f97\u4ee5\u63d0\u9ad8\u7684\u6700\u91cd\u8981\u7684\u5173\u952e\u70b9\u3002\u8fd9\u91cc\u4f7f\u7528\u7684\u662f9998\u548c9999\u4e24\u4e2a\u7aef\u53e3\uff0c9998\u4f5c\u4e3a\u8bfb\u7684\u7aef\u53e3\uff0c\u4e0d\u80fd\u505a\u5199\u5165\u64cd\u4f5c\uff0c9999\u4e3a\u5199\u7684\u7aef\u53e3\uff0c\u53ef\u4ee5\u505a\u8bfb\u53d6\u64cd\u4f5c\uff0c\u4f46\u662f\u4e0d\u5efa\u8bae\u4f7f\u7528\uff0c\u56e0\u4e3a\u57289999\u7aef\u53e3\u505a\u8bfb\u53d6\u64cd\u4f5c\uff0c\u4ece\u6027\u80fd\u89d2\u5ea6\u770b\uff0c\u6bd4\u8d77\u57289998\u7aef\u53e3\u4e0a\u5dee\u4e00\u4e9b\u3002<\/p>\n

 <\/p>\n

\u4e0b\u56fe\u66f4\u5177\u4f53\u7684\u5217\u51fa\u4e86\u8c03\u7528\u5173\u7cfb\u548c\u7ed3\u6784\uff1a<\/p>\n

<\/p>\n

 <\/p>\n

\u6ce8\u610f\u76ee\u524d\u7248\u672c\u7684HandlerSocket\u6682\u65f6\u53ea\u652f\u6301Innodb\uff0c\u76f8\u4fe1\u540e\u7eed\u7248\u672c\u80af\u5b9a\u4f1a\u652f\u6301\u5176\u4ed6\u7684Storage Engine\u3002<\/p>\n

\u4e8c\u3001HandlerSocket\u7279\u70b9
<\/strong>HandlerSocket\u76f8\u6bd4MySQL\u53ca\u5176\u5176\u4ed6\u7684NoSQL\u4ea7\u54c1\uff0c\u5177\u6709\u4e00\u4e9b\u4f18\u52bf\uff1a<\/p>\n

1. \u7531\u4e8e\u7701\u53bb\u4e86MySQL\u7684SQL\u5c42\u76f8\u5173\u7684\u64cd\u4f5c\uff0c\u5927\u5927\u7684\u51cf\u5c11\u4e86CPU\u5f00\u9500\u3002<\/p>\n

2. \u91c7\u7528\u5408\u5e76\u64cd\u4f5c\u7684\u65b9\u5f0f\uff0c\u5408\u5e76\u591a\u4e2a\u8bf7\u6c42\u540c\u65f6\u6267\u884c\uff0c\u51cf\u5c11\u4e86CPU\u5f00\u9500\u548c\u964d\u4f4eI\/O\u64cd\u4f5c\u6b21\u6570\u3002\u5173\u4e8e\u8fd9\u4e2a\u5176\u4ed6\u7684\u4e00\u4e9bNoSQL\u4ea7\u54c1\u4e5f\u6709\u8fd9\u6837\u7684\u673a\u5236\uff0c\u6bd4\u5982Mongodb\u3002<\/p>\n

3. \u7531\u4e8e\u57fa\u4e8e\u7b80\u5355\u7684\u6587\u672c\u534f\u8bae\uff0c\u80fd\u8282\u7701\u4e0d\u5c11\u7f51\u7edc\u6d41\u91cf\uff0c\u63d0\u9ad8\u7f51\u7edc\u541e\u5410\u91cf\u3002\u5927\u90e8\u5206\u7684NoSQL\u4ea7\u54c1\u90fd\u6709\u8fd9\u4e2a\u4f18\u52bf\uff0c\u4e0d\u5c11\u662f\u517c\u5bb9Memcached\u534f\u8bae\uff0c\u5f53\u7136\u66f4\u591a\u7684\u662f\u91c7\u7528\u4e13\u6709\u7684\u534f\u8bae\u3002<\/p>\n

4. \u80fd\u540c\u65f6\u4f7f\u7528\u4f20\u7edfMySQL\u548cHandlerSocket\u7684\u65b9\u5f0f\u8bbf\u95eeMySQL\u6570\u636e\u5e93\uff0c\u4e92\u76f8\u4e0d\u51b2\u7a81\u3002\u8fd9\u4e2a\u4f18\u52bf\u5176\u5b9e\u633a\u7a81\u51fa\u7684\uff0c\u662fHandlerSocket \u7684\u6838\u5fc3\u7ade\u4e89\u529b\u4e4b\u4e00\u3002 <\/strong><\/p>\n

5. \u652f\u6301\u8f83\u5927\u7684\u5e76\u53d1\u8fde\u63a5\uff0c\u53ef\u4ee5\u901a\u8fc7my.cnf\u7684handlersocket_threads\u6765\u914d\u7f6e\u8fde\u63a5\u6570\u3002<\/p>\n

6. \u8fd8\u53ef\u4ee5\u7ee7\u7eed\u4f7f\u7528MySQL\u7684Master-Slave\u3001Replication\u7b49\u6210\u719f\u7684\u673a\u5236\uff0c\u7cfb\u7edf\u8fd0\u7ef4\u4e0e\u4f20\u7edf\u7684MySQL\u8fd0\u7ef4\u4e00\u81f4\u3002\u8fd9\u4e5f\u662fHandlerSocket\u76f8\u6bd4\u5176\u4ed6NoSQL\u4ea7\u54c1\u5177\u6709\u7684\u6700\u5927\u7684\u4f18\u52bf\u3002<\/strong><\/p>\n

7. \u907f\u514d\u6709\u53cc\u91cd\u7f13\u5b58\uff0c\u6bd4\u5982\u5bf9\u4e8eMemcached+MySQL\u7684\u5e94\u7528\u6765\u8bf4\uff0c\u5728Memcached\u548cMySQL\u4e2d\u90fd\u5b58\u6709\u6570\u636e\uff0c\u9700\u8981\u53cc\u500d\u7684\u5185\u5b58\u8d44\u6e90\uff0c\u540c\u65f6\u4e5f\u53ef\u80fd\u4f1a\u6709\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002\u800c\u91c7\u7528HandlerSocket\u5219\u53ef\u4ee5\u907f\u514d\u8fd9\u6837\u7684\u95ee\u9898\u3002\u5177\u4f53\u7684\u5728\u63a5\u4e0b\u6765\u7684\u5e94\u7528\u573a\u666f\u91cc\u4ecb\u7ecd\u3002<\/p>\n

8. \u5177\u6709\u8f83\u9ad8\u7684\u8bfb\u5199\u6027\u80fd\uff0c\u5728CPU Bound\u7684\u573a\u666f\u4e2d\uff0c\u8bfb\u53d6\u6027\u80fd\u4e00\u822c\u662f\u540c\u7b49\u73af\u5883\u4e0bMySQL\u76843-7.5\u500d\u3002\u540c\u65f6\u5199\u5165\u6027\u80fd\u4e5f\u80fd\u8fbe\u52303-5\u500d\u3002<\/p>\n

 <\/p>\n

\u5177\u6709\u8fd9\u4e9b\u4f18\u52bf\u7684\u540c\u65f6\uff0c\u4e5f\u8981\u770b\u5230\u5b83\u76ee\u524d\u5b58\u5728\u7684\u5f85\u6539\u8fdb\u6216\u8005\u5e94\u8be5\u6ce8\u610f\u7684\u95ee\u9898\uff1a
1. \u7531\u4e8e\u91c7\u7528\u5408\u5e76\u64cd\u4f5c\u7684\u65b9\u5f0f\uff0c\u8fd9\u6837\u505a\u727a\u7272\u4e86\u54cd\u5e94\u65f6\u95f4\uff0c\u54cd\u5e94\u65f6\u95f4\u76f8\u6bd4MySQL\u6765\u8bf4\u5927\u4e00\u4e9b\u3002<\/p>\n

2. \u6ca1\u6709\u5b89\u5168\u76f8\u5173\u7684\u4fdd\u8bc1\uff0c\u7edd\u5927\u90e8\u5206NoSQL\u4ea7\u54c1\u90fd\u6709\u8fd9\u6837\u7684\u95ee\u9898\u3002\u7531\u4e8e\u91c7\u7528\u8fd9\u6837\u4ea7\u54c1\u7684\u5e94\u7528\u7684\u6570\u636e\u4e00\u822c\u90fd\u4e0d\u662f\u6838\u5fc3\u6570\u636e\uff0c\u6bd4\u5982\u4e0d\u4f1a\u6d89\u53ca\u5230\u8d26\u6237\u4fe1\u606f\u3001\u7528\u6237\u4fe1\u606f\u7b49\u7684\uff0c\u6240\u4ee5\uff0c\u5b89\u5168\u6027\u65b9\u9762\u7684\u6682\u65f6\u5e94\u8be5\u90fd\u4e0d\u662f\u4ec0\u4e48\u5927\u95ee\u9898\u3002<\/p>\n

3. \u5728I\/O Bound\u7684\u573a\u666f\u4e2d\uff0c\u6027\u80fd\u7684\u63d0\u5347\u53ef\u80fd\u4e0d\u662f\u5f88\u660e\u663e\u3002\u5728\u8fd9\u79cd\u573a\u666f\u4e0b\uff0c\u6027\u80fd\u7684\u63d0\u5347\u4e3b\u8981\u4f9d\u9760\u7684\u662f\u5408\u5e76\u64cd\u4f5c\uff0c\u51cf\u5c11I\/O\u64cd\u4f5c\u6b21\u6570\uff0c\u4f46\u662f\u63d0\u9ad8\u7684\u5e45\u5ea6\u6709\u9650\u3002<\/p>\n

4. \u7531\u4e8e2010\u5e7411\u6708\u4efd\u521a\u53d1\u5e03\uff0c\u76ee\u524d\u7248\u672c\u8fd8\u6709\u90e8\u5206Bug\u5f85\u4fee\u590d\uff0c\u6bd4\u5982\u901a\u8fc7HandlerSocket\u505aUpdate\u64cd\u4f5c\u540e\uff0c\u6ca1\u6709\u6e05\u9664Query Cache\uff0c\u8fd9\u53ef\u80fd\u51fa\u73b0\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002<\/p>\n

5. \u76ee\u524d\u53ea\u652f\u63015.1\u548c5.5\u7684Innodb\u5b58\u50a8\u5f15\u64ce\uff0c\u4ee5\u540e\u5e94\u8be5\u4f1a\u652f\u6301\u5176\u4ed6\u5b58\u50a8\u5f15\u64ce\u3002<\/strong><\/p>\n

 <\/p>\n

\u4e09\u3001HandlerSocket\u5e94\u7528\u573a\u666f
<\/strong>HandlerSocket\u76ee\u524d\u5df2\u7ecf\u5728DeNA\u7684\u751f\u4ea7\u73af\u5883\u4e0a\u4f7f\u7528\uff0c\u636e\u4f5c\u8005\u4ecb\u7ecd\uff0c\u8fd0\u884c\u72b6\u6001\u5f88\u4e0d\u9519\uff0c\u8282\u7701\u4e86\u4e0d\u5c11Memcached\u548cMySQL Slave\u670d\u52a1\u5668\uff0c\u540c\u65f6\u7f51\u7edc\u4f20\u8f93\u91cf\u4e5f\u51cf\u5c11\u4e86\u3002\u5230\u76ee\u524d\u4e3a\u6b62\u8fd8\u6ca1\u6709\u53d1\u73b0\u4ec0\u4e48\u6027\u80fd\u95ee\u9898\uff0c\u6bd4\u5982\u54cd\u5e94\u65f6\u95f4\u6bd4\u8f83\u957f\u7b49\u3002<\/p>\n

\u7eb5\u89c2\u76ee\u524d\u7edd\u5927\u90e8\u5206\u5927\u578b\u4e92\u8054\u7f51\u5e94\u7528\uff0c\u57fa\u672c\u4e0a\u91c7\u7528\u7684\u90fd\u662fMemcached+MySQL\u7684\u65b9\u5f0f\u3002\u8fd9\u662f\u4e00\u79cd\u5f88\u6210\u719f\u5e76\u4e14\u5f88\u6709\u6548\u7684\u65b9\u5f0f\uff0c\u57fa\u672c\u90fd\u6210\u4e86\u6807\u51c6\u65b9\u5f0f\u3002\u7531\u4e8eHandlerSocket\u5728Innodb Buffer Pool\u547d\u4e2d\u7387\u5f88\u9ad8\u7684\u60c5\u51b5\u4e0b\u6027\u80fd\u4e0d\u4f1a\u900a\u8272\u4e8eMemcached\uff0c\u6240\u4ee5\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u91c7\u7528HandlerSocket+MySQL\u6765\u66ff\u4ee3Memcached+MySQL\u3002\u8fd9\u6837\u6709\u4ee5\u4e0b\u51e0\u4e2a\u4f18\u52bf\uff1a<\/p>\n

1. \u91c7\u7528Memcached+MySQL\uff0c\u9700\u8981\u4fdd\u5b58\u4e24\u4efd\u6570\u636e\uff1aMemcached\u548cMySQL\u672c\u8eab\u7684\u7f13\u5b58\uff0c\u9700\u8981\u53cc\u500d\u7684\u5185\u5b58\u8d44\u6e90\u3002\u800cHandlerSocket+MySQL\u7684\u65b9\u5f0f\uff0c\u53ea\u9700\u8981\u4fdd\u5b58\u4e00\u4efd\u7f13\u5b58\u6570\u636e\u3002<\/p>\n

2. \u91c7\u7528Memcached+MySQL\uff0c\u9700\u8981\u4fdd\u6301Memcached\u4e0eMySQL\u7684\u6570\u636e\u4e00\u81f4\u6027\uff0c\u6709\u65f6\u5019\u53ef\u80fd\u4f1a\u51fa\u73b0\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\uff0c\u800c\u5982\u679c\u7528HandlerSocket+MySQL\u5c31\u6ca1\u8fd9\u60c5\u51b5\u3002<\/p>\n

3. \u91c7\u7528Memcached+MySQL\uff0c\u8fd8\u6709\u4e00\u4e2a\u8fd9\u6837\u7684\u5e94\u7528\u90fd\u975e\u5e38\u5c0f\u5fc3\u548c\u7279\u522b\u6ce8\u610f\u7684\u95ee\u9898\uff0c\u5c31\u662f\u96ea\u5d29\u6548\u5e94\u3002\u65b0\u5e94\u7528\u4e0a\u7ebf\u7684\u65f6\u5019\u9700\u8981\u5148\u505a\u597d\u5404\u79cd\u9884\u70ed\uff0c\u5c3d\u91cf\u51cf\u5c11\u77ac\u95f4\u8d85\u7ea7\u5927\u7684I\/O\u538b\u529b\u3002\u524d\u6bb5\u65f6\u95f4\u65b0\u6d6a\u5fae\u535a\u51fa\u73b0\u4e00\u6b21\u6bd4\u8f83\u4e25\u91cd\u7684\u6545\u969c\uff0c\u636e\u4e0d\u5b8c\u5168\u53ef\u9760\u6d88\u606f\u8bc1\u5b9e\uff0c\u5c31\u662f\u96ea\u5d29\u6548\u5e94\u5f15\u8d77\u7684\uff0c\u5f53\u65f6\u6709\u90e8\u5206Memcached\u670d\u52a1\u5668\u51fa\u73b0\u6545\u969c\u6216\u8005\u5931\u6548\uff0c\u5bfc\u81f4DB\u670d\u52a1\u5668\u538b\u529b\u77ac\u95f4\u589e\u5927\uff0c\u652f\u6491\u4e0d\u4f4f\u3002\u5f53\u7136\u4e86\uff0cHandlerSocket\u5e94\u7528\u4e0d\u662f\u4e0d\u9700\u8981\u9884\u70ed\uff0c\u4e5f\u662f\u9700\u8981\u7684\uff0c\u4f46\u662f\u5728\u9762\u5bf9\u8fd9\u6837\u7684\u95ee\u9898\u7684\u65f6\u5019\uff0c\u5b83\u7684\u652f\u6491\u80fd\u529b\u6bd4\u8d77MySQL+Memcached\u7684\u80fd\u529b\u5f3a\u3002<\/p>\n

\u56db\u3001HandlerSocket\u6027\u80fd<\/strong><\/p>\n<\/p>\n

HandlerSocket\u4f5c\u8005\u6d4b\u8bd5HandlerSocket\u5728\u67e5\u8be2\u60c5\u51b5\u4e0bQPS\u4e3a75K\uff0cMemcached\u4e3a40K\uff0cMySQL\u4e3a10K\u3002\u4f46\u662f\u9700\u8981\u6ce8\u610f\u5230\u5b83\u7684\u6d4b\u8bd5\u573a\u666f\uff0c\u4e00\u822c\u7684\u5e94\u7528\u662f\u5f88\u96be\u6709\u8fd9\u6837\u7684\u573a\u666f\u7684\uff0c\u6240\u4ee5\u8bf4\u4e00\u822c\u5e94\u7528\u662f\u5f88\u96be\u8fbe\u52307.5\u500d\u4e8eMySQL\u7684\u60c5\u51b5\uff0c\u4f46\u662f\u6027\u80fd\u7684\u5927\u5e45\u5ea6\u63d0\u9ad8\u662f\u4e0d\u5bb9\u7f6e\u7591\u7684\u3002\u4f5c\u8005\u7684\u6d4b\u8bd5\u573a\u666f\u5982\u4e0b\uff1a
1. \u5173\u95edMySQL\u7684query cache\uff1a\u4e5f\u5c31\u662fMySQL\u7684\u6bcf\u6b21\u64cd\u4f5c\u90fd\u9700\u8981\u6267\u884csql\u89e3\u6790\u7b49\u90a3\u4e00\u7cfb\u5217\u64cd\u4f5c\u3002<\/p>\n

2. CPU Bound\u800c\u975eI\/O Bound\uff1aInnoDB Buffer Pool\u8bbe\u7f6e\u4e3a\u6bd4\u8f83\u5927\uff0c\u547d\u4e2d\u7387\u63a5\u8fd1100%\u3002<\/p>\n

\u6240\u4ee5\uff0c\u5e94\u8be5\u66f4\u5ba2\u89c2\u7684\u6765\u770b\u5f85\u6d4b\u8bd5\u6570\u636e\u3002\u5bf9\u4e8eCPU Bound\u800c\u975eI\/O Bound\u7c7b\u578b\u7684\u5e94\u7528\uff0c\u5728InnoDB_Buffer_Pool\u63a5\u8fd1100%\u547d\u4e2d\u7387\u7684\u65f6\u5019\uff0cHandlerSocket\u53ef\u4ee5\u5c06\u67e5\u8be2\u6027\u80fd\u63d0\u9ad87.5\u500d\u3002\u8fd9\u4e00\u70b9\u5176\u5b9e\u4e0d\u96be\u7406\u89e3\uff0c\u56e0\u4e3aHandlerSocket\u4e3b\u8981\u6027\u80fd\u4f18\u5316\u70b9\u5728\u4e8e\u8282\u7701\u4e86SQL\u5c42\u7684\u5f00\u9500\uff0cSQL\u5c42\u7684\u5f00\u9500\u4e3b\u8981\u662fCPU\u7684\u5f00\u9500\u3002\u800c\u5982\u679c\u5bf9\u4e8e\u4e00\u4e2aI\/O Bound\u7684\u5e94\u7528\u6765\u8bf4\uff0cHandlerSocket\u7684\u67e5\u8be2\u6027\u80fd\u53ef\u80fd\u5c31\u8fbe\u4e0d\u52307.5\u500d\u4e86\uff0c\u53ef\u80fd\u8ddd\u79bb7.5\u500d\u6709\u6bd4\u8f83\u5927\u7684\u5dee\u8ddd\uff0c\u6240\u4ee5\uff0c\u5bf9\u4e8eHandlerSocket\u7684\u5e94\u7528\u6765\u8bf4\uff0c\u5e94\u8be5\u5c3d\u91cf\u63d0\u9ad8InnoDB_Buffer_Pool\u7684\u5927\u5c0f\uff0c\u591a\u591a\u76ca\u5584\u3002<\/p>\n

 <\/p>\n

\u6211\u4e5f\u505a\u8fc7\u4e00\u4e9b\u57fa\u51c6\u6d4b\u8bd5\uff0c\u57fa\u672c\u4e0a\u5728\u63d2\u5165\u7684\u60c5\u51b5\u4e0b\uff0cHandlerSocket\u7684\u6027\u80fd\u80fd\u8fbe\u5230\u540c\u7b49\u73af\u5883\u7684MySQL\u76843-5\u500d\uff0c\u6570\u636e\u91cf\u8d8a\u5927\u65f6\u5019\u8d8a\u660e\u663e\uff0c\u7279\u522b\u662f\u8fbe\u52305000\u4e07\u4ee5\u540e\u3002\u5728\u67e5\u8be2\u60c5\u51b5\u4e0b\uff0cHandlerSocket\u662f\u540c\u7b49\u73af\u5883\u4e0bMySQL\u76841.5-2\u500d\uff0c\u8fd9\u8ddf\u4f5c\u8005\u7684\u6d4b\u8bd5\u76847.5\u500d\u6709\u6bd4\u8f83\u5927\u7684\u51fa\u5165\uff0c\u8fd9\u4e5f\u662f\u4e0a\u9762\u6211\u7279\u522b\u63d0\u5230\u7684\uff0c\u4f5c\u8005\u7684\u6d4b\u8bd5\u6570\u636e\u662f\u5728Innodb_Buffer_Pool\u8db3\u591f\u5927\u5e76\u4e14\u547d\u4e2d\u7387\u5f88\u9ad8\u7684\u60c5\u51b5\uff0c\u7531\u4e8e\u6211\u505a\u57fa\u51c6\u6d4b\u8bd5\u7684\u673a\u5668\u6761\u4ef6\u6709\u9650\uff0c\u6ca1\u6709\u8db3\u591f\u5927\u7684Buffer Pool\uff0c\u547d\u4e2d\u7387\u4e0d\u662f\u5f88\u9ad8\uff0c\u6240\u4ee5\uff0cI\/O\u5f00\u9500\u4e0d\u5c0f\uff0c\u8fd9\u4e5f\u9a8c\u8bc1\u4e86\u4e0a\u9762\u63d0\u5230\u7684\uff0c\u5bf9\u4e8eI\/O Bound\u7684\u573a\u666f\uff0c\u6027\u80fd\u7684\u63d0\u5347\u4e0d\u4f1a\u7279\u522b\u7684\u660e\u663e\uff0c\u6240\u4ee5\u5e94\u8be5\u5c3d\u91cf\u589e\u5927InnoDB_Buffer_Pool\u7684\u5927\u5c0f\uff0c\u5c3d\u91cf\u63a5\u8fd1\u4e8e\u6570\u636e\u7684\u5927\u5c0f\u3002\u800c\u4e14\u6211\u5728\u6d4b\u8bd5\u7684\u65f6\u5019\uff0c\u6ca1\u6709\u5173\u95edQuery Cache\uff0c\u6240\u4ee5\u5bf9\u4e8eMySQL\u7684\u6d4b\u8bd5\u573a\u666f\u6765\u8bf4\uff0c\u80fd\u91cd\u7528\u5230\u6267\u884c\u8ba1\u5212\u548cCache\u6570\u636e\u7b49\u3002<\/p>\n

 <\/p>\n

\u4e0a\u9762\u8bf4\u5230\u4e86\uff0cHandlerSocket\u5177\u6709\u4e0d\u5c11\u7684\u4f18\u70b9\uff0c\u6027\u80fd\u4e5f\u6709\u5f88\u5927\u7684\u63d0\u5347\uff0c\u4f46\u662f\u4e5f\u9700\u8981\u7406\u6027\u7684\u6765\u770b\u5f85\uff0c\u6709\u4e00\u4e9b\u9700\u8981\u7279\u522b\u6ce8\u610f\u7684\u4e8b\u9879\uff0c\u5728\u505a\u51b3\u7b56\u7684\u65f6\u5019\uff0c\u5e94\u8be5\u6574\u4f53\u4e0a\u7684\u8003\u8651\uff0c\u6211\u8fd9\u91cc\u7b80\u5355\u7684\u603b\u7ed3\u4e00\u4e0b\u3002
1. \u5e94\u8be5\u5c3d\u91cf\u8fbe\u5230CPU-Bound\u573a\u666f\uff0c\u800c\u975eIO-Bound\uff0c\u8fd9\u6837\u624d\u80fd\u66f4\u597d\u7684\u53d1\u6325\u51faHandlerSocket\u7684\u4f18\u52bf\u3002\u5177\u4f53\u505a\u6cd5\u662f\u589e\u5927\u5185\u5b58\uff0c\u5c3d\u91cf\u63d0\u9ad8InnoDB_Buffer_Pool\u5927\u5c0f\u3002<\/p>\n

2. \u7531\u4e8e\u91c7\u7528\u5408\u5e76\u64cd\u4f5c\uff0c\u54cd\u5e94\u65f6\u95f4\u4f1a\u6709\u4e0d\u540c\u7a0b\u5ea6\u7684\u589e\u52a0\uff0c\u5e94\u8be5\u8003\u8651\u597d\u662f\u5426\u6ee1\u8db3\u4f60\u7684\u5e94\u7528\u573a\u666f\u3002\u53ef\u4ee5\u7ee7\u7eed\u5173\u6ce8\u540e\u7eed\u7248\u672c\u4f18\u5316\u7b56\u7565\uff0c\u6bd4\u5982\u53ef\u80fd\u6709\u4e9b\u670b\u53cb\u4f1a\u60f3\u8981\u8fd9\u6837\u7684\uff1a\u8bfb\u53d6\u7684\u65f6\u5019\u4e0d\u662f\u5408\u5e76\u64cd\u4f5c\uff0c\u4f46\u662f\u5199\u5165\u662f\u5408\u5e76\u64cd\u4f5c\uff0c\u5f53\u7136\u8fd9\u6837\u7684\u60c5\u51b5\u8bfb\u53d6\u7684\u603b\u4f53\u6027\u80fd\u4f1a\u6709\u4e0d\u540c\u7a0b\u5ea6\u964d\u4f4e\uff0c\u4e0d\u8fc7\u4e00\u5207\u4e0d\u5c31\u662f\u5728\u6743\u8861\u561b\uff1f\u8fd8\u662f\u770b\u5177\u4f53\u5e94\u7528\u573a\u666f\u3002<\/p>\n

 <\/p>\n

\u4e94\u3001HandlerSocket\u6027\u80fd\u4f18\u5316
<\/strong>\u524d\u9762\u4e5f\u63d0\u5230\u4e86\uff0cHandlerSocket\u6027\u80fd\u76f8\u6bd4\u4f20\u7edfMySQL\u6709\u4e86\u6bd4\u8f83\u663e\u8457\u7684\u63d0\u9ad8\uff0c\u4f46\u662f\u8981\u60f3\u66f4\u597d\u7684\u53d1\u6325\u51fa\u5b83\u7684\u4f18\u52bf\uff0c\u9700\u8981\u505a\u4e00\u4e9b\u76f8\u5173\u7684\u4f18\u5316\u3002<\/p>\n

 <\/p>\n

\u6027\u80fd\u4f18\u5316\u4e3b\u8981\u4ece\u4ee5\u4e0b\u4e09\u65b9\u9762\u8003\u8651\uff0c\u5f53\u7136\u9664\u4e86\u8fd9\u4e09\u65b9\u9762\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u4f18\u5316\u65b9\u5f0f\uff0c\u6bd4\u5982\u4f18\u5316\u64cd\u4f5c\u7cfb\u7edf\uff0c\u4f7f\u7528Direct IO\u7b49\uff0c\u8fd9\u91cc\u8bf4\u7684\u8fd9\u4e09\u65b9\u9762\u662f\u76f8\u5bf9\u6bd4\u8f83\u5bb9\u6613\u505a\u5230\u5e76\u4e14\u5b9e\u73b0\u6280\u672f\u6210\u672c\u4e5f\u4e0d\u9ad8\u7684\u65b9\u5f0f\uff1a
1. \u786c\u4ef6\u73af\u5883
\u524d\u9762\u4e5f\u63d0\u5230\u4e86\uff0c\u5e94\u8be5\u5c3d\u91cf\u63d0\u9ad8Innodb Buffer Pool\u7684\u5927\u5c0f\uff0c\u5bf9\u5e94\u5230\u786c\u4ef6\u4e0a\uff0c\u5c31\u662f\u8981\u5c3d\u91cf\u589e\u52a0\u5185\u5b58\u7684\u5927\u5c0f\uff0c\u6700\u7406\u60f3\u7684\u60c5\u51b5\u4e0b\u662f\u5185\u5b58\u5927\u5c0f\u4e0e\u6570\u636e\u5927\u5c0f\u4e00\u6837\u3002\u5982\u679c\u6709\u8d44\u6e90\uff0c\u4e5f\u53ef\u4ee5\u8003\u8651\u91c7\u7528SSD\uff0c\u8fd9\u6709\u4e2a\u57fa\u4e8eSSD\u7684\u6d4b\u8bd5\u6570\u636e\uff08http:\/\/www.percona.com\/docs\/wiki\/benchmark:handlersocket:ssd:start<\/a>\uff09\uff0c\u6027\u80fd\u8fd8\u662f\u975e\u5e38\u7ed9\u529b\u7684\u3002<\/p>\n

2. \u5ba2\u6237\u7aef\u4f18\u5316
\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u7aef\u57fa\u4e8eSocket\u901a\u4fe1\uff0c\u6253\u5f00\u5173\u95ed\u8fde\u63a5\u3001OpenIndex\u7b49\u64cd\u4f5c\u90fd\u662f\u6bd4\u8f83\u8017\u8d39\u8d44\u6e90\u7684\u64cd\u4f5c\uff0c\u5e94\u8be5\u5c3d\u91cf\u907f\u514d\u9891\u7e41\u7684\u505a\u8fd9\u4e9b\u64cd\u4f5c\u3002\u6240\u4ee5\uff0c\u5728\u5ba2\u6237\u7aef\u5e94\u8be5\u8981\u505a\u8fde\u63a5\u6c60\uff0c\u540c\u65f6\u5e94\u8be5\u91c7\u7528\u4e00\u4e9b\u66f4\u597d\u7684\u901a\u4fe1\u6a21\u578b\uff0c\u6bd4\u5982Linux\u4e0b\u57fa\u4e8eepoll\u548cNIO\u7b49\u3002\u6bd4\u5982\uff0c\u8fd9\u4e2aJava\u5ba2\u6237\u7aef\uff08
http:\/\/code.google.com\/p\/hs4j\/<\/a>\uff09\u8fd9\u65b9\u9762\u5c31\u505a\u5f97\u4e0d\u9519\u3002<\/p>\n

3. HandlerSocket\u548cInnodb\u914d\u7f6e
HandlerSocket\u914d\u7f6e\uff1a
\/\/\u8bfb\u7ebf\u7a0b\u7684\u4e2a\u6570\uff0c\u63a8\u8350\u4e3a\u903b\u8f91CPU\u4e2a\u6570\uff0c\u6bd4\u5982\u8d85\u7ebf\u7a0b\u7684\u5e94\u8be5*2
handlersocket_threads = 16
\/\/\u5199\u7ebf\u7a0b\u7684\u4e2a\u6570\uff0c\u76ee\u524d\u7684\u7248\u672c\u63a8\u8350\u8bbe\u7f6e\u4e3a1
handlersocket_thread_wr = 1
\/\/\u8bfb\u8bf7\u6c42\u7684\u76d1\u542c\u7aef\u53e3
handlersocket_port = 9998
\/\/\u5199\u8bf7\u6c42\u7684\u76d1\u542c\u7aef\u53e3
handlersocket_port_wr = 9999<\/p>\n

 <\/p>\n

Innodb\u914d\u7f6e\uff1a
\/\/Innodb Buffer Pool\u5927\u5c0f\uff0c\u63a8\u8350\u8d8a\u5927\u8d8a\u597d
innodb_buffer_pool_size
\/\/Innodb\u65e5\u5fd7\u6587\u4ef6\u5927\u5c0f\uff0c\u6839\u636e\u9700\u6c42\u8bbe\u7f6e\uff0c\u5728\u5141\u8bb8\u7684\u60c5\u51b5\u4e0b\u8d8a\u5927\u4e5f\u8d8a\u597d
innodb_log_file_size, innodb_log_files_in_group
\/\/mysqld\u8fdb\u7a0b\u53ef\u4ee5\u6253\u5f00\u7684\u6587\u4ef6\u6570\uff0c\u63a8\u8350\u4e3a65535
open_files_limit = 65535
\/\/\u8bbe\u7f6e\u4e3a1\u80fd\u63d0\u9ad8\u6027\u80fd\uff0c\u4f46\u662f\u76f8\u5e94\u7684\u4e5f\u4f1a\u6d88\u8017\u5185\u5b58\uff0c\u9700\u8981\u6743\u8861\u597d
innodb_adaptive_hash_index = 1<\/p>\n<\/p>\n

================================================================================<\/p>\n

\u9879\u76ee\u5730\u5740\uff1a<\/p>\n

\u6587\u5e93\u8d44\u6599\uff1ahttp:\/\/wenku.baidu.com\/view\/c1898218a8114431b90dd88d.html<\/a><\/p>\n

\u53c2\u8003\u8d44\u6599\uff1ahttp:\/\/www.cnblogs.com\/inrie\/archive\/2011\/01\/28\/1946998.html<\/a><\/p>\n<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"

       HandlerSocket\u662fMySQL\u7684\u4e00\u4e2aPlugin\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u76f4\u63a5\u8ddfMySQL\u7684Storage Engine Layer(\u6bd4\u5982InnoDB\uff09\u4ea4\u4e92\uff0c\u800c\u4e0d\u9700\u8981\u901a\u8fc7MySQL\u7684Parser Layer\u3002\u4ece\u6027\u80fd\u89d2\u5ea6\u6709\u5f88\u5927\u7684\u63d0\u5347\u3002<\/span><\/p>\n

       HandlerSocket\u7279\u522b\u9002\u7528\u4e8e\u6d77\u91cf\u6570\u636e\u3001\u9ad8\u5e76\u53d1\u7684\u5177\u6709\u7b80\u5355\u4e1a\u52a1\u6a21\u578b\u7684\u5e94\u7528\uff0c\u6bd4\u5982\u5fae\u535a\u3001Feed\u3002\u53ef\u4ee5\u7528\u6765\u66ff\u4ee3\u4f20\u7edfMemcached+MySQL\u7684\u65b9\u5f0f\uff0c\u800c\u4e14\u6027\u80fd\u4e0a\u4e5f\u63a5\u8fd1\u4e8e\u76ee\u524d\u4e3b\u6d41\u7684NoSQL\u4ea7\u54c1\uff0c\u6240\u4ee5\u8fd8\u662f\u6709\u6bd4\u8f83\u5927\u7684\u4f18\u52bf\u3002\u4f46\u662f\u9700\u8981\u6e05\u695a\u7406\u6027\u7684\u770b\u5f85\u8fd9\u4e2a\u95ee\u9898\uff0c\u7531\u4e8e<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1142"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1142"}],"version-history":[{"count":0,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1142\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}