{"id":1143,"date":"2011-12-08T14:35:00","date_gmt":"2011-12-08T06:35:00","guid":{"rendered":"\/?p=1143"},"modified":"2011-12-08T14:35:00","modified_gmt":"2011-12-08T14:35:00","slug":"1143","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/mysql\/1143.html","title":{"rendered":"MongoDB\u3001HandlerSocket\u548cMySQL\u6027\u80fd\u6d4b\u8bd5\u53ca\u5176\u7ed3\u679c\u5206\u6790"},"content":{"rendered":"

MongoDB\u6027\u80fd\u8fd8\u662f\u5341\u5206\u5f3a\u608d\u7684\uff0c\u4f46HandlerSocket\u53ef\u4ee5\u4e0e\u4f20\u7edfMySQL\u540c\u65f6\u4f7f\u7528MySQL\u6570\u636e\u5e93\uff0c\u4e92\u76f8\u4e0d\u51b2\u7a81\uff0c\u800c\u4e14\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<\/b><\/p>\n


<\/span><\/p>\n

\u4e00\u3001\u6d4b\u8bd5\u73af\u5883<\/span>
1\u3001\u6d4b\u8bd5\u670d\u52a1\u5668\u72b6\u51b5
\u5171\u6d89\u53ca4\u53f0\u6d4b\u8bd5\u670d\u52a1\u5668\uff1a<\/p>\n

\u538b\u529b\u6d4b\u8bd5\u670d\u52a1\u5668
Web\u670d\u52a1\u5668
MongoDB\u670d\u52a1\u5668<\/p>\n

MySQL\u670d\u52a1\u5668\u3002<\/p>\n

 <\/p>\n

\u673a\u5668\u914d\u7f6e\u4e3a\uff1a
CPU\uff1aIntel(R) Core(TM)2 Duo CPU     E7200  @ 2.53GHz
RAM\uff1a8G DDR2 667
\u78c1\u76d8\uff1aSATA<\/p>\n

\u64cd\u4f5c\u7cfb\u7edf\uff1aRedhat 5.5<\/p>\n

 <\/p>\n

1. \u538b\u529b\u6d4b\u8bd5\u670d\u52a1\u5668
\u5b89\u88c5Webbench 1.5\uff0c\u901a\u8fc7Webbench\u6765\u538bWeb\u670d\u52a1\u5668\u3002<\/p>\n

 <\/p>\n

2. Web\u670d\u52a1\u5668
Nginx 0.8.54 + PHP 5.3.3 (php-fpm)\uff0c\u5b89\u88c5\u6709Mongodb\u548cHandlerSocket\u7684php\u9a71\u52a8\u3002
Mongodb\u7684php\u9a71\u52a8\u4e3a\uff1amongodb-mongo-php-driver-1.1.1-19-gc584231.tar.gz
HandlerSocket\u7684php\u9a71\u52a8\u4e3a\uff1aphp-handlersocket-0.0.7.tar.gz
\u901a\u8fc7Php\u7a0b\u5e8f\u6765\u8c03\u7528Mongodb\u548cHandlerSocket\u3002<\/p>\n

 <\/p>\n

3. MongoDB\u670d\u52a1\u5668
MongoDB\u7248\u672c\uff1a1.6.5<\/p>\n

 <\/p>\n

4. MySQL\u670d\u52a1\u5668
MySQL\u7248\u672c\uff1a5.1.53
HandlerSocket\u7248\u672c\uff1a1.0.6-60-gf51e061
MySQL\u5b58\u50a8\u5f15\u64ce\uff1aInnodb\uff0c\u8c03\u6574\u4e86innodb\u7684Thread Pool Size\u4e3a2G<\/p>\n

2\u3001\u6d4b\u8bd5\u7a0b\u5e8f\u548c\u6d4b\u8bd5\u6570\u636e\u63d0\u53d6
1. \u4e3a\u4e86\u907f\u514d\u6253\u5f00\u8fde\u63a5\u548cHttp\u670d\u52a1\u5668\u6210\u4e3a\u74f6\u9888\uff0c\u5728\u6d4b\u8bd5\u7a0b\u5e8f\u91cc\u8bbe\u7f6e\u4e3a\u6bcf1000\u4e2a\u8bf7\u6c42\u516c\u7528\u540c\u4e00\u4e2a\u8fde\u63a5\uff0c\u540c\u65f6\u8bbe\u7f6e\u4e3a\u6bcf\u4e2a\u9875\u9762\u8bf7\u6c42\u6267\u884c1000\u6b21\u6570\u636e\u8bf7\u6c42\u3002
2. \u6d4b\u8bd5\u7684\u6570\u636e\uff0c\u5305\u62ecQPS\u3001CPU\u3001IO\u7b49\u65b9\u9762\u7684\u6570\u636e\uff0c\u4ece\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u7684\u547d\u4ee4\uff08\u5982vmstat\u3001iostat\u7b49\uff09\u6216\u8005Mongodb\u3001Mysql\u63d0\u4f9b\u7684\u547d\u4ee4\uff08\u5982mongostat\u3001mysqladmin\u7b49\uff09\u6765\u83b7\u53d6\u3002<\/p>\n

\u4e8c\u3001\u6d4b\u8bd5\u7ed3\u679c<\/span>
1\u3001100\u4e07\u6761\u8bb0\u5f55
1. \u67e5\u8be2<\/p>\n

<\/p>\n

 <\/p>\n

 <\/p>\n

2. \u63d2\u5165<\/p>\n

<\/p>\n

<\/p>\n

<\/p>\n

2\u30011000\u4e07\u6761\u8bb0\u5f55
1. \u67e5\u8be2<\/p>\n

<\/p>\n

<\/p>\n

2. \u63d2\u5165<\/p>\n

<\/p>\n

<\/p>\n

<\/p>\n

 <\/p>\n

3\u30012000\u4e07\u6761\u8bb0\u5f55<\/p>\n

1. \u67e5\u8be2<\/p>\n

<\/p>\n

<\/p>\n

 
2. \u63d2\u5165<\/p>\n

 <\/p>\n

<\/p>\n

<\/p>\n

4\u30015000\u4e07\u6761\u8bb0\u5f55
1. \u67e5\u8be2<\/p>\n

<\/p>\n

<\/p>\n

 <\/p>\n

2. \u63d2\u5165 <\/p>\n

<\/p>\n

<\/p>\n

<\/p>\n

\u4e09\u3001\u6d4b\u8bd5\u5206\u6790\u603b\u7ed3<\/span><\/p>\n

1\u3001 I\/O\u8bfb\u5199\u60c5\u51b5
\u4ece\u63d2\u5165\u60c5\u51b5\u4e0b\u7684TPS\u6570\u636e\u53ef\u4ee5\u770b\u51fa\uff0c MySQL\u3001HandlerSocket\u548cMongodb\u7684\u6570\u636e\u6709\u6bd4\u8f83\u660e\u663e\u7684\u5dee\u522b\uff0c\u8fd9\u4e3b\u8981\u8ddf\u4ed6\u4eec\u7684\u5185\u90e8\u5b9e\u73b0\u548c\u6d4b\u8bd5\u65b9\u5f0f\u6709\u5173\u7cfb\u3002<\/p>\n

 <\/p>\n

\u6d4b\u8bd5\u573a\u666f\u4e0bMySQL\u91c7\u7528\u7684\u662f\u5355\u6761Insert\u7684\u65b9\u5f0f\uff0c\u6240\u4ee5\u53ef\u4ee5\u770b\u51faQPS\u6570\u548cTPS\u6570\u662f\u57fa\u672c\u4e00\u81f4\u7684\uff0c\u4e5f\u5c31\u662f\u6bcf\u4e2aInsert\u64cd\u4f5c\uff0c\u90fd\u5bf9\u5e94\u6709\u4e00\u6b21I\/O\u5199\u5165\u64cd\u4f5c\u3002\u53ef\u4ee5\u4eceMySQL\u6570\u636e\u5e93\u672c\u8eab\u505a\u4e00\u4e9b\u4f18\u5316\uff0c\u8fd9\u6b21\u6d4b\u8bd5\u6ca1\u6709\u8986\u76d6\u5230\u8fd9\u79cd\u573a\u666f\u3002<\/p>\n

 <\/p>\n

HandlerSocket\u5185\u90e8\u91c7\u7528\u7684\u662fBulk Insert\u64cd\u4f5c\uff0c\u6240\u4ee5\uff0c\u53ef\u4ee5\u770b\u51faQPS\u6570\u660e\u663e\u5927\u4e8eTPS\u6570\uff0c\u6279\u91cf\u7684\u63d2\u5165\u64cd\u4f5c\u660e\u663e\u63d0\u9ad8\u4e86\u6574\u4f53\u6027\u80fd\u3002<\/p>\n

 <\/p>\n

Mongodb\u5185\u90e8\u91c7\u7528\u5408\u5e76\u64cd\u4f5c\u7684\u65b9\u5f0f\uff0c\u91c7\u7528\u6570\u636e\u5148\u5b58\u653e\u5230\u5185\u5b58\u4e2d\uff0c\u7136\u540e\u518dFlush\u5230\u78c1\u76d8\u4e0a\u7684\u65b9\u5f0f\u3002\u6240\u4ee5\uff0c\u4ece\u6d4b\u8bd5\u6570\u636e\u53ef\u4ee5\u770b\u51fa\uff0cTPS\u66f2\u7ebf\u5761\u5ea6\u975e\u5e38\u5927\uff1a\u6709\u65f6\u5019TPS\u662f\u96f6\uff0c\u8fd9\u65f6\u5019\u662f\u8fd8\u653e\u5230\u5185\u5b58\u4e2d\uff0c\u8fd8\u6ca1\u6709Flush\u5230\u78c1\u76d8\u4e0a\uff1b\u6709\u65f6\u5019TPS\u975e\u5e38\u9ad8\uff0c\u540c\u65f6\u8fd9\u65f6\u5019CPU\u4e5f\u975e\u5e38\u9ad8\uff0c\u51e0\u4e4e\u662f100%\uff0c\u8fd9\u65f6\u5019\u662f\u5728\u505aFlush\u5230\u78c1\u76d8\u7684\u64cd\u4f5c\u3002\u57fa\u4e8e\u6b64\u79cd\u673a\u5236\uff0c\u4ee5\u540e\u4f1a\u518d\u505a\u4e00\u4e9b\u66f4\u7ec6\u5316\u7684\u4f18\u5316\u548c\u6d4b\u8bd5\uff0c\u56e0\u4e3a\u8fd9\u6837\u6709\u53ef\u80fd\u4f1a\u5b58\u5728\u51e0\u79cd\u95ee\u9898\uff1a
\u7b2c\u4e00\uff0c \u53ef\u80fd\u4f1a\u5bfc\u81f4\u67d0\u4e2a\u65f6\u95f4\u6bb5IO\u548cCPU\u7684\u538b\u529b\u975e\u5e38\u5927\uff0c\u751a\u81f3\u8fbe\u5230\u5cf0\u503c\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u670d\u52a1\u7684\u6574\u4f53\u5065\u5eb7\u72b6\u6001\u5c06\u9762\u4e34\u7740\u4e00\u4e9b\u6311\u6218\u3002
\u7b2c\u4e8c\uff0c \u5982\u679c\u670d\u52a1\u5668\u91cd\u542f\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u6570\u636e\u4e22\u5931\u7684\u60c5\u51b5\uff0c\u5185\u5b58\u4e2d\u7684\u6570\u636e\u8fd8\u6ca1\u6709Flush\u5230\u78c1\u76d8\u7684\u4f1a\u4e22\u5931\u3002\u5f53\u7136\u8fd9\u79cd\u60c5\u51b5\u662f\u4e24\u9762\u6027\u7684\uff0c\u56e0\u4e3a\u91c7\u7528\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4ece\u6d4b\u8bd5\u7ed3\u679c\u4e5f\u53ef\u4ee5\u770b\u51fa\uff0c\u6574\u4f53\u7684\u5199\u5165\u6027\u80fd\u6bd4MySQL\u548cHandlerSocket\u90fd\u9ad8\uff0c\u8fd9\u662f\u4e00\u79cd\u53d6\u820d\uff0c\u5c31\u770b\u5177\u4f53\u4e1a\u52a1\u662f\u5426\u53ef\u4ee5\u63a5\u53d7\u8fd9\u6837\u7684\u4ee5\u9ad8\u6027\u80fd\u6362\u53d6\u6570\u636e\u53ef\u9760\u6027\uff0c\u6709\u4e9b\u4e1a\u52a1\u53ef\u80fd\u662f\u53ef\u4ee5\u63a5\u53d7\u7684\uff0c\u6bd4\u5982Feed\u3002<\/p>\n

2\u3001 CPU\u5360\u7528\u60c5\u51b5
\u4ece\u67e5\u8be2\u60c5\u51b5\u4e0b\u7684CPU\u6570\u636e\u53ef\u4ee5\u770b\u51fa\uff0cMySQL\u548cMongodb\u51e0\u4e4e\u90fd\u63a5\u8fd1100%\uff0c\u800cHandlerSocket\u7531\u4e8e\u7701\u53bb\u4e86\u5404\u79cdSql Parser\u548c\u76f8\u5173\u7684\u64cd\u4f5c\uff0cCPU\u5360\u7528\u7387\u4fdd\u6301\u572840%-60%\u4e4b\u95f4\uff0c\u5728\u4e00\u4e2a\u6bd4\u8f83\u5408\u7406\u7684\u8303\u56f4\u5185\u3002<\/p>\n

 <\/p>\n

\u4ece\u63d2\u5165\u60c5\u51b5\u4e0b\u7684CPU\u6570\u636e\u53ef\u4ee5\u770b\u51fa\uff0cHandlerSocket\u7684CPU\u5360\u7528\u7387\u8fd8\u662f\u4fdd\u6301\u572840%-60%\u4e4b\u95f4\uff0c\u4f4e\u4e8eMySQL\u548cMongodb\u3002MySQL\u548cMongodb\u5927\u90e8\u5206\u60c5\u51b5\u4fdd\u6301\u572850%-90%\u4e4b\u95f4\u3002<\/p>\n

 <\/p>\n

3\u3001 QPS\u60c5\u51b5
\u4ece\u67e5\u8be2\u60c5\u51b5\u4e0b\u7684QPS\u6570\u636e\u53ef\u4ee5\u770b\u51fa\uff0cHandlerSocket\u548cMongodb\u7684\u67e5\u8be2\u6027\u80fd\u51e0\u4e4e\u5dee\u4e0d\u591a\uff0c\u90fd\u8fbe\u52303\u4e07\u4ee5\u4e0a\uff0c\u5e76\u4e14\u968f\u7740\u6570\u636e\u91cf\u7684\u589e\u957f\uff0c\u6027\u80fd\u6ca1\u6709\u56de\u843d\uff0c\u8fd8\u662f\u4fdd\u6301\u57283\u4e07\u4ee5\u4e0a\u3002\u76ee\u524d\u53ea\u662f\u6700\u5927\u6d4b\u8bd5\u52305000\u4e07\u6570\u636e\u7684\u60c5\u51b5\uff0c\u66f4\u9ad8\u7684\u6570\u503c\u8fd9\u6b21\u6d4b\u8bd5\u8fd8\u6ca1\u6709\u8986\u76d6\u5230\u3002\u800cMySQL\u7684\u6027\u80fd\u76f8\u6bd4\u4e4b\u4e0b\u5219\u5dee\u4e00\u4e9b\uff0c\u4e00\u822c\u572818000\u523025000\u4e4b\u95f4\u3002\u5f53\u7136\u8fd9\u6b21\u6ca1\u6709\u592a\u591a\u7684\u9488\u5bf9MySQL\u505a\u4f18\u5316\uff0c\u53ea\u662f\u589e\u5927\u4e86innodb_thread_pool\u5927\u5c0f\u548c\u6bcf\u6b21\u5206\u914d\u7684\u6570\u636e\u5757\u7684\u5927\u5c0f\uff0c\u5982\u679c\u9488\u5bf9MySQL\u505a\u4f18\u5316\uff0c\u53ef\u80fd\u80fd\u540c\u65f6\u63d0\u9ad8HandlerSocket\u548cMySQL\u7684\u6027\u80fd\u3002<\/p>\n

 <\/p>\n

\u4ece\u63d2\u5165\u60c5\u51b5\u4e0b\u7684QPS\u6570\u636e\u53ef\u4ee5\u770b\u51fa\uff0cMongodb\u660e\u663e\u5360\u6709\u6bd4\u8f83\u5927\u7684\u4f18\u52bf\uff0c\u8fd9\u6839\u4e4b\u524d\u8bf4\u7684\u5b83\u7684\u5b9e\u73b0\u65b9\u5f0f\u6709\u5173\u3002\u968f\u7740\u6570\u636e\u91cf\u7684\u589e\u957f\uff0cQPS\u90fd\u76f8\u5e94\u7684\u5728\u51cf\u5c11\uff0c\u8fd9\u65b9\u9762\uff0cMySQL\u7684\u5e45\u5ea6\u6700\u5927\uff0c\u6570\u636e\u91cf\u5230\u8fbe5000\u4e07\u4ee5\u4e0a\u65f6\uff0cMySQL\u7684\u63d2\u5165\u6027\u80fd\u4e3a2000-3000\uff0c\u800cHandlerSocket\u80fd\u4fdd\u6301\u57281\u4e07\u4ee5\u4e0a\uff0cMongodb\u4e3a2\u4e07\u4ee5\u4e0a\u3002<\/p>\n

 <\/p>\n

\u4f5c\u8005\uff1a\u6d2a\u5c0f\u519b
<\/span><\/a>\u51fa\u5904\uff1a
http:\/\/www.cnblogs.com\/inrie<\/a><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"

MongoDB\u6027\u80fd\u8fd8\u662f\u5341\u5206\u5f3a\u608d\u7684\uff0c\u4f46HandlerSocket\u53ef\u4ee5\u4e0e\u4f20\u7edfMySQL\u540c\u65f6\u4f7f\u7528MySQL\u6570\u636e\u5e93\uff0c\u4e92\u76f8\u4e0d\u51b2\u7a81\uff0c\u800c\u4e14\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<\/b><\/p>\n


<\/span><\/p>\n

\u4e00\u3001\u6d4b\u8bd5\u73af\u5883<\/span>
1\u3001\u6d4b\u8bd5\u670d\u52a1\u5668\u72b6\u51b5
\u5171\u6d89\u53ca4\u53f0\u6d4b\u8bd5\u670d\u52a1\u5668\uff1a<\/p>\n

\u538b\u529b\u6d4b\u8bd5\u670d\u52a1\u5668
Web\u670d\u52a1\u5668
MongoDB\u670d\u52a1\u5668<\/p>\n

MySQL\u670d\u52a1\u5668\u3002<\/p>\n

 <\/p>\n

\u673a\u5668\u914d\u7f6e\u4e3a\uff1a
CPU\uff1aIntel(R) Core(TM)2 Duo CPU     E7200  @ 2.53GHz<\/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\/1143"}],"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=1143"}],"version-history":[{"count":0,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1143\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}