{"id":1447,"date":"2012-03-17T14:37:01","date_gmt":"2012-03-17T06:37:01","guid":{"rendered":"http:\/\/doophp.sinaapp.com\/?p=1447"},"modified":"2012-03-17T14:37:15","modified_gmt":"2012-03-17T06:37:15","slug":"apache-mpm-tuning","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/architecture\/apache-mpm-tuning.html","title":{"rendered":"Apache\u5e76\u53d1\u63a7\u5236\u53c2\u6570\u76d1\u63a7\u4e0eMPM\u914d\u7f6e\u8c03\u4f18"},"content":{"rendered":"
\u5728\u652f\u6301POSIX\u7ebf\u7a0b\u7684Unix\u7cfb\u7edf\u4e0a\uff0cApache\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684MPM\uff08Multi -Processing Modules\uff0c\u591a\u9053\u5904\u7406\u6a21\u5757\uff09\u8fd0\u884c\u5728\u4e00\u79cd\u591a\u8fdb\u7a0b\u4e0e\u591a\u7ebf\u7a0b\u76f8\u6df7\u5408\u7684\u6a21\u5f0f\u4e0b\uff0c\u589e\u5f3a\u90e8\u5206\u914d\u7f6e\u7684\u53ef\u6269\u5145\u6027\u80fd\u3002<\/p>\n
\u6beb\u4e0d\u5938\u5f20\u5730\u8bf4\uff0cMPM\u7684\u5f15\u5165\u662fApache 2.0\u6700\u91cd\u8981\u7684\u53d8\u5316\u3002\u5927\u5bb6\u77e5\u9053\uff0cApache\u662f\u57fa\u4e8e\u6a21\u5757\u5316\u7684\u8bbe\u8ba1\uff0c\u800cApache 2.0\u66f4\u6269\u5c55\u4e86\u6a21\u5757\u5316\u8bbe\u8ba1\u5230Web\u670d\u52a1\u5668\u7684\u6700\u57fa\u672c\u529f\u80fd\u3002\u670d\u52a1\u5668\u88c5\u8f7d\u4e86\u4e00\u79cd\u591a\u9053\u5904\u7406\u6a21\u5757\uff0c\u8d1f\u8d23\u7ed1\u5b9a\u672c\u673a\u7f51\u7edc\u7aef\u53e3\u3001\u63a5\u53d7\u8bf7\u6c42\uff0c\u5e76\u8c03\u5ea6\u5b50\u8fdb\u7a0b\u6765\u5904\u7406\u8bf7\u6c42\u3002\u6269\u5c55\u6a21\u5757\u5316\u8bbe\u8ba1\u6709\u4e24\u4e2a\u91cd\u8981\u597d\u5904\uff1a<\/p>\n
\u5728\u7528\u6237\u7ea7\uff0cMPM\u770b\u8d77\u6765\u548c\u5176\u5b83Apache\u6a21\u5757\u975e\u5e38\u7c7b\u4f3c\u3002\u4e3b\u8981\u533a\u522b\u662f\u5728\u4efb\u610f\u65f6\u523b\u53ea\u80fd\u6709\u4e00\u79cdMPM\u88ab\u88c5\u8f7d\u5230\u670d\u52a1\u5668\u4e2d<\/p>\n
\u00a0\u6307\u5b9aMPM\u7684\u65b9\u6cd5\u00a0<\/strong><\/p>\n \u4e0b\u9762\u4ee5Red Hat Linux 9\u4e3a\u5e73\u53f0\uff0c\u8bf4\u660e\u5728Apache 2.0\u4e2d\u5982\u4f55\u6307\u5b9aMPM (Apache\u91c7\u75282.0.45)\u3002\u5148\u89e3\u538b\u7f29\u6e90\u4ee3\u7801\u5305httpd-2.0.45.tar.gz\uff0c\u751f\u6210httpd-2.0.45\u76ee\u5f55\uff08Apache 1.3\u6e90\u4ee3\u7801\u5305\u7684\u547d\u540d\u89c4\u5219\u662fapache_1.3.NN.tar.gz\uff0c\u800c2.0\u7248\u5219\u662fhttpd-2.0.NN.tar.gz\uff0c\u5176\u4e2dNN\u662f\u6b21\u7248\u672c\u53f7\uff09\u3002<\/p>\n \u8fdb\u5165httpd-2.0.45\u76ee\u5f55\uff0c\u8fd0\u884c\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n $ .\/configure –help|grep mpm<\/p><\/blockquote>\n \u663e\u793a\u5982\u4e0b\uff1a<\/strong><\/p>\n \u00a0–with-mpm=MPM<\/p>\n Choose the process model for Apache to use.<\/p>\n MPM={beos|worker|prefork|mpmt_os2| perchild|leader|threadpool}<\/p><\/blockquote>\n \u4e0a\u8ff0\u64cd\u4f5c\u7528\u6765\u9009\u62e9\u8981\u4f7f\u7528\u7684\u8fdb\u7a0b\u6a21\u578b\uff0c\u5373\u54ea\u79cdMPM\u6a21\u5757\u3002Beos\u3001mpmt_os2\u5206\u522b\u662fBeOS\u548cOS\/2\u4e0a\u7f3a\u7701\u7684MPM\uff0c perchild\u4e3b\u8981\u8bbe\u8ba1\u76ee\u7684\u662f\u4ee5\u4e0d\u540c\u7684\u7528\u6237\u548c\u7ec4\u7684\u8eab\u4efd\u6765\u8fd0\u884c\u4e0d\u540c\u7684\u5b50\u8fdb\u7a0b\u3002\u8fd9\u5728\u8fd0\u884c\u591a\u4e2a\u9700\u8981CGI\u7684\u865a\u62df\u4e3b\u673a\u65f6\u7279\u522b\u6709\u7528\uff0c\u4f1a\u6bd41.3\u7248\u4e2d\u7684SuExec \u673a\u5236\u505a\u5f97\u66f4\u597d\u3002leader\u548cthreadpool\u90fd\u662f\u57fa\u4e8eworker\u7684\u53d8\u4f53\uff0c\u8fd8\u5904\u4e8e\u5b9e\u9a8c\u6027\u9636\u6bb5\uff0c\u67d0\u4e9b\u60c5\u51b5\u4e0b\u5e76\u4e0d\u4f1a\u6309\u7167\u9884\u671f\u8bbe\u60f3\u7684\u90a3\u6837\u5de5\u4f5c\uff0c\u6240\u4ee5 Apache\u5b98\u65b9\u4e5f\u5e76\u4e0d\u63a8\u8350\u4f7f\u7528\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u4e3b\u8981\u9610\u8ff0prefork\u548cworker\u8fd9\u4e24\u79cd\u548c\u6027\u80fd\u5173\u7cfb\u6700\u5927\u7684\u4ea7\u54c1\u7ea7MPM ( \u6709\u5173\u5176\u5b83\u7684MPM\u8be6\u7ec6\u8bf4\u660e\uff0c\u8bf7\u53c2\u89c1Apache\u5b98\u65b9\u6587\u6863\uff1ahttp:\/\/httpd.apache.org\/docs-2.0\/mod\/)\u3002<\/p>\n \u67e5\u770b\u5f53\u524dApache\u7684\u5de5\u4f5c\u6a21\u5f0f<\/strong><\/p>\n #apachectl -l<\/p>\n Compiled in modules:<\/p>\n core.c<\/p>\n prefork.c<\/p>\n http_core.c<\/p>\n mod_so.c<\/p>\n<\/blockquote>\n \u3000\u3000prefork\u7684\u5de5\u4f5c\u539f\u7406\u53ca\u914d\u7f6e<\/strong><\/p>\n \u5982\u679c\u4e0d\u7528\u201c–with-mpm\u201d\u663e\u5f0f\u6307\u5b9a\u67d0\u79cdMPM\uff0cprefork\u5c31\u662fUnix\u5e73\u53f0\u4e0a\u7f3a\u7701\u7684MPM\u3002\u5b83\u6240\u91c7\u7528\u7684\u9884\u6d3e\u751f\u5b50\u8fdb\u7a0b\u65b9\u5f0f\u4e5f\u662f Apache 1.3\u4e2d\u91c7\u7528\u7684\u6a21\u5f0f\u3002prefork\u672c\u8eab\u5e76\u6ca1\u6709\u4f7f\u7528\u5230\u7ebf\u7a0b\uff0c2.0\u7248\u4f7f\u7528\u5b83\u662f\u4e3a\u4e86\u4e0e1.3\u7248\u4fdd\u6301\u517c\u5bb9\u6027\uff1b\u53e6\u4e00\u65b9\u9762\uff0cprefork\u7528\u5355\u72ec\u7684\u5b50\u8fdb\u7a0b\u6765\u5904\u7406\u4e0d\u540c\u7684\u8bf7\u6c42\uff0c\u8fdb\u7a0b\u4e4b\u95f4\u662f\u5f7c\u6b64\u72ec\u7acb\u7684\uff0c\u8fd9\u4e5f\u4f7f\u5176\u6210\u4e3a\u6700\u7a33\u5b9a\u7684MPM\u4e4b\u4e00\u3002<\/p>\n \u82e5\u4f7f\u7528prefork\uff0c\u5728make\u7f16\u8bd1\u548cmake install\u5b89\u88c5\u540e\uff0c\u4f7f\u7528\u201chttpd -l\u201d\u6765\u786e\u5b9a\u5f53\u524d\u4f7f\u7528\u7684MPM\uff0c\u5e94\u8be5\u4f1a\u770b\u5230prefork.c\uff08\u5982\u679c\u770b\u5230worker.c\u8bf4\u660e\u4f7f\u7528\u7684\u662fworker MPM\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff09\u3002\u518d\u67e5\u770b\u7f3a\u7701\u751f\u6210\u7684httpd.conf\u914d\u7f6e\u6587\u4ef6\uff0c\u91cc\u9762\u5305\u542b\u5982\u4e0b\u914d\u7f6e\u6bb5\uff1a<\/p>\n <IfModule prefork.c>;<\/p>\n StartServers 5<\/p>\n MinSpareServers 5<\/p>\n MaxSpareServers 10<\/p>\n MaxClients 150<\/p>\n MaxRequestsPerChild 0<\/p>\n <\/IfModule>;<\/p><\/blockquote>\n prefork\u7684\u5de5\u4f5c\u539f\u7406\u662f\uff0c\u63a7\u5236\u8fdb\u7a0b\u5728\u6700\u521d\u5efa\u7acb\u201cStartServers\u201d\u4e2a\u5b50\u8fdb\u7a0b\u540e\uff0c\u4e3a\u4e86\u6ee1\u8db3MinSpareServers\u8bbe\u7f6e\u7684\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u7b49\u5f85\u4e00\u79d2\u949f\uff0c\u7ee7\u7eed\u521b\u5efa\u4e24\u4e2a\uff0c\u518d\u7b49\u5f85\u4e00\u79d2\u949f\uff0c\u7ee7\u7eed\u521b\u5efa\u56db\u4e2a\u2026\u2026\u5982\u6b64\u6309\u6307\u6570\u7ea7\u589e\u52a0\u521b\u5efa\u7684\u8fdb\u7a0b\u6570\uff0c\u6700\u591a\u8fbe\u5230\u6bcf\u79d232\u4e2a\uff0c\u76f4\u5230\u6ee1\u8db3 MinSpareServers\u8bbe\u7f6e\u7684\u503c\u4e3a\u6b62\u3002\u8fd9\u5c31\u662f\u9884\u6d3e\u751f\uff08prefork\uff09\u7684\u7531\u6765\u3002\u8fd9\u79cd\u6a21\u5f0f\u53ef\u4ee5\u4e0d\u5fc5\u5728\u8bf7\u6c42\u5230\u6765\u65f6\u518d\u4ea7\u751f\u65b0\u7684\u8fdb\u7a0b\uff0c\u4ece\u800c\u51cf\u5c0f\u4e86\u7cfb\u7edf\u5f00\u9500\u4ee5\u589e\u52a0\u6027\u80fd\u3002<\/p>\n MaxSpareServers\u8bbe\u7f6e\u4e86\u6700\u5927\u7684\u7a7a\u95f2\u8fdb\u7a0b\u6570\uff0c\u5982\u679c\u7a7a\u95f2\u8fdb\u7a0b\u6570\u5927\u4e8e\u8fd9\u4e2a\u503c\uff0cApache\u4f1a\u81ea\u52a8kill\u6389\u4e00\u4e9b\u591a\u4f59\u8fdb\u7a0b\u3002\u8fd9\u4e2a\u503c\u4e0d\u8981\u8bbe\u5f97\u8fc7\u5927\uff0c\u4f46\u5982\u679c\u8bbe\u7684\u503c\u6bd4MinSpareServers\u5c0f\uff0cApache\u4f1a\u81ea\u52a8\u628a\u5176\u8c03\u6574\u4e3aMinSpareServers+1\u3002\u5982\u679c\u7ad9\u70b9\u8d1f\u8f7d\u8f83\u5927\uff0c\u53ef\u8003\u8651\u540c\u65f6\u52a0\u5927MinSpareServers\u548cMaxSpareServers\u3002<\/p>\n MaxRequestsPerChild\u8bbe\u7f6e\u7684\u662f\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u53ef\u5904\u7406\u7684\u8bf7\u6c42\u6570\u3002\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u5728\u5904\u7406\u4e86\u201cMaxRequestsPerChild\u201d \u4e2a\u8bf7\u6c42\u540e\u5c06\u81ea\u52a8\u9500\u6bc1\u30020\u610f\u5473\u7740\u65e0\u9650\uff0c\u5373\u5b50\u8fdb\u7a0b\u6c38\u4e0d\u9500\u6bc1\u3002\u867d\u7136\u7f3a\u7701\u8bbe\u4e3a0\u53ef\u4ee5\u4f7f\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u5904\u7406\u66f4\u591a\u7684\u8bf7\u6c42\uff0c\u4f46\u5982\u679c\u8bbe\u6210\u975e\u96f6\u503c\u4e5f\u6709\u4e24\u70b9\u91cd\u8981\u7684\u597d\u5904\uff1a<\/p>\n \u56e0\u6b64\uff0c\u53ef\u6839\u636e\u670d\u52a1\u5668\u7684\u8d1f\u8f7d\u6765\u8c03\u6574\u8fd9\u4e2a\u503c\u3002\u7b14\u8005\u8ba4\u4e3a10000\u5de6\u53f3\u6bd4\u8f83\u5408\u9002\u3002<\/p>\n MaxClients\u662f\u8fd9\u4e9b\u6307\u4ee4\u4e2d\u6700\u4e3a\u91cd\u8981\u7684\u4e00\u4e2a\uff0c\u8bbe\u5b9a\u7684\u662fApache\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u7684\u8bf7\u6c42\uff0c\u662f\u5bf9Apache\u6027\u80fd\u5f71\u54cd\u6700\u5927\u7684\u53c2\u6570\u3002\u5176\u7f3a\u7701\u503c 150\u662f\u8fdc\u8fdc\u4e0d\u591f\u7684\uff0c\u5982\u679c\u8bf7\u6c42\u603b\u6570\u5df2\u8fbe\u5230\u8fd9\u4e2a\u503c\uff08\u53ef\u901a\u8fc7ps -ef|grep http|wc -l\u6765\u786e\u8ba4\uff09\uff0c\u90a3\u4e48\u540e\u9762\u7684\u8bf7\u6c42\u5c31\u8981\u6392\u961f\uff0c\u76f4\u5230\u67d0\u4e2a\u5df2\u5904\u7406\u8bf7\u6c42\u5b8c\u6bd5\u3002\u8fd9\u5c31\u662f\u7cfb\u7edf\u8d44\u6e90\u8fd8\u5269\u4e0b\u5f88\u591a\u800cHTTP\u8bbf\u95ee\u5374\u5f88\u6162\u7684\u4e3b\u8981\u539f\u56e0\u3002\u7cfb\u7edf\u7ba1\u7406\u5458\u53ef\u4ee5\u6839\u636e\u786c\u4ef6\u914d\u7f6e\u548c\u8d1f\u8f7d\u60c5\u51b5\u6765\u52a8\u6001\u8c03\u6574\u8fd9\u4e2a\u503c\u3002\u867d\u7136\u7406\u8bba\u4e0a\u8fd9\u4e2a\u503c\u8d8a\u5927\uff0c\u53ef\u4ee5\u5904\u7406\u7684\u8bf7\u6c42\u5c31\u8d8a\u591a\uff0c\u4f46Apache\u9ed8\u8ba4\u7684\u9650\u5236\u4e0d\u80fd\u5927\u4e8e256\u3002\u5982\u679c\u628a\u8fd9\u4e2a\u503c\u8bbe\u4e3a\u5927\u4e8e256\uff0c\u90a3\u4e48 Apache\u5c06\u65e0\u6cd5\u8d77\u52a8\u3002\u4e8b\u5b9e\u4e0a\uff0c256\u5bf9\u4e8e\u8d1f\u8f7d\u7a0d\u91cd\u7684\u7ad9\u70b9\u4e5f\u662f\u4e0d\u591f\u7684\u3002\u5728Apache 1.3\u4e2d\uff0c\u8fd9\u662f\u4e2a\u786c\u9650\u5236\u3002\u5982\u679c\u8981\u52a0\u5927\u8fd9\u4e2a\u503c\uff0c\u5fc5\u987b\u5728\u201cconfigure\u201d\u524d\u624b\u5de5\u4fee\u6539\u7684\u6e90\u4ee3\u7801\u6811\u4e0b\u7684src\/include\/httpd.h\u4e2d\u67e5\u627e 256\uff0c\u5c31\u4f1a\u53d1\u73b0\u201c#define HARD_SERVER_LIMIT 256\u201d\u8fd9\u884c\u3002\u628a256\u6539\u4e3a\u8981\u589e\u5927\u7684\u503c\uff08\u59824000\uff09\uff0c\u7136\u540e\u91cd\u65b0\u7f16\u8bd1Apache\u5373\u53ef\u3002\u5728Apache 2.0\u4e2d\u65b0\u52a0\u5165\u4e86ServerLimit\u6307\u4ee4\uff0c\u4f7f\u5f97\u65e0\u987b\u91cd\u7f16\u8bd1Apache\u5c31\u53ef\u4ee5\u52a0\u5927MaxClients\u3002\u4e0b\u9762\u662f\u7b14\u8005\u7684prefork\u914d\u7f6e\u6bb5\uff1a<\/p>\n <IfModule prefork.c>;<\/p>\n StartServers 10<\/p>\n MinSpareServers 10<\/p>\n MaxSpareServers 15<\/p>\n ServerLimit 2000<\/p>\n MaxClients 1000<\/p>\n MaxRequestsPerChild 10000<\/p>\n <\/IfModule>;<\/p><\/blockquote>\n \u4e0a\u8ff0\u914d\u7f6e\u4e2d\uff0cServerLimit\u7684\u6700\u5927\u503c\u662f20000\uff0c\u5bf9\u4e8e\u5927\u591a\u6570\u7ad9\u70b9\u5df2\u7ecf\u8db3\u591f\u3002\u5982\u679c\u4e00\u5b9a\u8981\u518d\u52a0\u5927\u8fd9\u4e2a\u6570\u503c\uff0c\u5bf9\u4f4d\u4e8e\u6e90\u4ee3\u7801\u6811\u4e0bserver\/mpm\/prefork\/prefork.c\u4e2d\u4ee5\u4e0b\u4e24\u884c\u505a\u76f8\u5e94\u4fee\u6539\u5373\u53ef\uff1a<\/p>\n #define DEFAULT_SERVER_LIMIT 256<\/p>\n #define MAX_SERVER_LIMIT 20000<\/p><\/blockquote>\n \u3000\u3000worker\u7684\u5de5\u4f5c\u539f\u7406\u53ca\u914d\u7f6e<\/strong><\/p>\n \u76f8\u5bf9\u4e8eprefork\uff0cworker\u662f2.0 \u7248\u4e2d\u5168\u65b0\u7684\u652f\u6301\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b\u6df7\u5408\u6a21\u578b\u7684MPM\u3002\u7531\u4e8e\u4f7f\u7528\u7ebf\u7a0b\u6765\u5904\u7406\uff0c\u6240\u4ee5\u53ef\u4ee5\u5904\u7406\u76f8\u5bf9\u6d77\u91cf\u7684\u8bf7\u6c42\uff0c\u800c\u7cfb\u7edf\u8d44\u6e90\u7684\u5f00\u9500\u8981\u5c0f\u4e8e\u57fa\u4e8e\u8fdb\u7a0b\u7684\u670d\u52a1\u5668\u3002\u4f46\u662f\uff0c worker\u4e5f\u4f7f\u7528\u4e86\u591a\u8fdb\u7a0b\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u53c8\u751f\u6210\u591a\u4e2a\u7ebf\u7a0b\uff0c\u4ee5\u83b7\u5f97\u57fa\u4e8e\u8fdb\u7a0b\u670d\u52a1\u5668\u7684\u7a33\u5b9a\u6027\u3002\u8fd9\u79cdMPM\u7684\u5de5\u4f5c\u65b9\u5f0f\u5c06\u662fApache 2.0\u7684\u53d1\u5c55\u8d8b\u52bf\u3002<\/p>\n \u5728configure -with-mpm=worker\u540e\uff0c\u8fdb\u884cmake\u7f16\u8bd1\u3001make install\u5b89\u88c5\u3002\u5728\u7f3a\u7701\u751f\u6210\u7684httpd.conf\u4e2d\u6709\u4ee5\u4e0b\u914d\u7f6e\u6bb5\uff1a<\/p>\n <IfModule worker.c>;<\/p>\n StartServers 2<\/p>\n MaxClients 150<\/p>\n MinSpareThreads 25<\/p>\n MaxSpareThreads 75<\/p>\n ThreadsPerChild 25<\/p>\n MaxRequestsPerChild 0<\/p>\n <\/IfModule>;<\/p><\/blockquote>\n worker\u7684\u5de5\u4f5c\u539f\u7406\u662f\uff0c\u7531\u4e3b\u63a7\u5236\u8fdb\u7a0b\u751f\u6210\u201cStartServers\u201d\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u6bcf\u4e2a\u5b50\u8fdb\u7a0b\u4e2d\u5305\u542b\u56fa\u5b9a\u7684ThreadsPerChild \u7ebf\u7a0b\u6570\uff0c\u5404\u4e2a\u7ebf\u7a0b\u72ec\u7acb\u5730\u5904\u7406\u8bf7\u6c42\u3002\u540c\u6837\uff0c\u4e3a\u4e86\u4e0d\u5728\u8bf7\u6c42\u5230\u6765\u65f6\u518d\u751f\u6210\u7ebf\u7a0b\uff0cMinSpareThreads\u548cMaxSpareThreads\u8bbe\u7f6e\u4e86\u6700\u5c11\u548c\u6700\u591a\u7684\u7a7a\u95f2\u7ebf\u7a0b\u6570\uff1b\u800cMaxClients\u8bbe\u7f6e\u4e86\u6240\u6709\u5b50\u8fdb\u7a0b\u4e2d\u7684\u7ebf\u7a0b\u603b\u6570\u3002\u5982\u679c\u73b0\u6709\u5b50\u8fdb\u7a0b\u4e2d\u7684\u7ebf\u7a0b\u603b\u6570\u4e0d\u80fd\u6ee1\u8db3\u8d1f\u8f7d\uff0c\u63a7\u5236\u8fdb\u7a0b\u5c06\u6d3e\u751f\u65b0\u7684\u5b50\u8fdb\u7a0b\u3002<\/p>\n MinSpareThreads\u548cMaxSpareThreads\u7684\u6700\u5927\u7f3a\u7701\u503c\u5206\u522b\u662f75\u548c250\u3002\u8fd9\u4e24\u4e2a\u53c2\u6570\u5bf9Apache\u7684\u6027\u80fd\u5f71\u54cd\u5e76\u4e0d\u5927\uff0c\u53ef\u4ee5\u6309\u7167\u5b9e\u9645\u60c5\u51b5\u76f8\u5e94\u8c03\u8282\u3002<\/p>\n ThreadsPerChild\u662fworker MPM\u4e2d\u4e0e\u6027\u80fd\u76f8\u5173\u6700\u5bc6\u5207\u7684\u6307\u4ee4\u3002ThreadsPerChild\u7684\u6700\u5927\u7f3a\u7701\u503c\u662f64\uff0c\u5982\u679c\u8d1f\u8f7d\u8f83\u5927\uff0c64\u4e5f\u662f\u4e0d\u591f\u7684\u3002\u8fd9\u65f6\u8981\u663e\u5f0f\u4f7f\u7528 ThreadLimit\u6307\u4ee4\uff0c\u5b83\u7684\u6700\u5927\u7f3a\u7701\u503c\u662f20000\u3002\u4e0a\u8ff0\u4e24\u4e2a\u503c\u4f4d\u4e8e\u6e90\u7801\u6811server\/mpm\/worker\/worker.c\u4e2d\u7684\u4ee5\u4e0b\u4e24\u884c\uff1a<\/p>\n #define DEFAULT_THREAD_LIMIT 64<\/p>\n #define MAX_THREAD_LIMIT 20000<\/p><\/blockquote>\n \u8fd9\u4e24\u884c\u5bf9\u5e94\u7740ThreadsPerChild\u548cThreadLimit\u7684\u9650\u5236\u6570\u3002\u6700\u597d\u5728configure\u4e4b\u524d\u5c31\u628a64\u6539\u6210\u6240\u5e0c\u671b\u7684\u503c\u3002\u6ce8\u610f\uff0c\u4e0d\u8981\u628a\u8fd9\u4e24\u4e2a\u503c\u8bbe\u5f97\u592a\u9ad8\uff0c\u8d85\u8fc7\u7cfb\u7edf\u7684\u5904\u7406\u80fd\u529b\uff0c\u4ece\u800c\u56e0Apache\u4e0d\u8d77\u52a8\u4f7f\u7cfb\u7edf\u5f88\u4e0d\u7a33\u5b9a\u3002<\/p>\n Worker\u6a21\u5f0f\u4e0b\u6240\u80fd\u540c\u65f6\u5904\u7406\u7684\u8bf7\u6c42\u603b\u6570\u662f\u7531\u5b50\u8fdb\u7a0b\u603b\u6570\u4e58\u4ee5ThreadsPerChild\u503c\u51b3\u5b9a\u7684\uff0c\u5e94\u8be5\u5927\u4e8e\u7b49\u4e8eMaxClients\u3002\u5982\u679c\u8d1f\u8f7d\u5f88\u5927\uff0c\u73b0\u6709\u7684\u5b50\u8fdb\u7a0b\u6570\u4e0d\u80fd\u6ee1\u8db3\u65f6\uff0c\u63a7\u5236\u8fdb\u7a0b\u4f1a\u6d3e\u751f\u65b0\u7684\u5b50\u8fdb\u7a0b\u3002\u9ed8\u8ba4\u6700\u5927\u7684\u5b50\u8fdb\u7a0b\u603b\u6570\u662f16\uff0c\u52a0\u5927\u65f6\u4e5f\u9700\u8981\u663e\u5f0f\u58f0\u660eServerLimit\uff08\u6700\u5927\u503c\u662f20000\uff09\u3002\u8fd9\u4e24\u4e2a\u503c\u4f4d\u4e8e\u6e90\u7801\u6811server\/mpm\/worker\/worker.c\u4e2d\u7684\u4ee5\u4e0b\u4e24\u884c\uff1a<\/p>\n #define DEFAULT_SERVER_LIMIT 16<\/p>\n #define MAX_SERVER_LIMIT 20000<\/p><\/blockquote>\n \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u663e\u5f0f\u58f0\u660e\u4e86ServerLimit\uff0c\u90a3\u4e48\u5b83\u4e58\u4ee5ThreadsPerChild\u7684\u503c\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8eMaxClients\uff0c\u800c\u4e14MaxClients\u5fc5\u987b\u662fThreadsPerChild\u7684\u6574\u6570\u500d\uff0c\u5426\u5219Apache\u5c06\u4f1a\u81ea\u52a8\u8c03\u8282\u5230\u4e00\u4e2a\u76f8\u5e94\u503c\uff08\u53ef\u80fd\u662f\u4e2a\u975e\u671f\u671b\u503c\uff09\u3002\u4e0b\u9762\u662f\u7b14\u8005\u7684 worker\u914d\u7f6e\u6bb5\uff1a<\/p>\n <IfModule worker.c>;<\/p>\n StartServers 3<\/p>\n MaxClients 2000<\/p>\n ServerLimit 25<\/p>\n MinSpareThreads 50<\/p>\n MaxSpareThreads 200<\/p>\n ThreadLimit 200<\/p>\n ThreadsPerChild 100<\/p>\n MaxRequestsPerChild 0<\/p>\n <\/IfModule>;<\/p><\/blockquote>\n \u901a\u8fc7\u4e0a\u9762\u7684\u53d9\u8ff0\uff0c\u53ef\u4ee5\u4e86\u89e3\u5230Apache 2.0\u4e2dprefork\u548cworker\u8fd9\u4e24\u4e2a\u91cd\u8981MPM\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u5e76\u53ef\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u6765\u914d\u7f6eApache\u76f8\u5173\u7684\u6838\u5fc3\u53c2\u6570\uff0c\u4ee5\u83b7\u5f97\u6700\u5927\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n httpd\u5e76\u53d1\u8fde\u63a5\u60c5\u51b5\u67e5\u770b<\/strong><\/p>\n \u67e5\u770b\u5f53\u524d\u7684\u8fde\u63a5\u6570<\/p>\n #ps aux|grep httpd|wc -l<\/p>\n \u5b9e\u65f6\u68c0\u6d4bhttpd\u8fde\u63a5\u6570<\/p>\n #watch -n 1 -d “pgrep httpd|wc -l”<\/p>\n \u8ba1\u7b97httpd\u8fdb\u7a0b\u5360\u7528\u5185\u5728\u7684\u5e73\u5747\u6570<\/p>\n #ps aux|grep -v grep|awk ‘\/httpd\/{sum+=$6}; END{print sum\/n}’<\/p>\n \u67e5\u770bApache\u7684\u5e76\u53d1\u8bf7\u6c42\u6570\u53ca\u671fTCP\u8fde\u63a5\u72b6\u6001<\/p>\n #netstat -n | awk ‘\/^tcp\/{++S[$NF]}END{for(a in S) print a, S[a]}’<\/p>\n \u8fd4\u56de\u7ed3\u679c\u793a\u4f8b\uff1a<\/p>\n LAST_ACK 5<\/p>\n SYN_RECV 30<\/p>\n ESTABLISHED 1597<\/p>\n FIN_WAIT1 51<\/p>\n FIN_WAIT2 504<\/p>\n TIME_WAIT 1057<\/p>\n \u5176\u4e2d\u7684SYN_RECV\u8868\u793a\u6b63\u5728\u7b49\u5f85\u5904\u7406\u7684\u8bf7\u6c42\u6570\uff1bESTABLISHED\u8868\u793a\u6b63\u5e38\u6570\u636e\u4f20\u8f93\u72b6\u6001\uff1bTIME_WAIT\u8868\u793a\u5904\u7406\u5b8c\u6bd5,\u7b49\u5f85\u8d85\u65f6\u7ed3\u675f\u7684\u8bf7\u6c42\u6570.<\/p>\n \u72b6\u6001\uff1a\u63cf\u8ff0<\/p>\n CLOSED\uff1a\u65e0\u8fde\u63a5\u662f\u6d3b\u52a8\u7684\u6216\u6b63\u5728\u8fdb\u884c<\/p>\n LISTEN\uff1a\u670d\u52a1\u5668\u5728\u7b49\u5f85\u8fdb\u5165\u547c\u53eb<\/p>\n SYN_RECV\uff1a\u4e00\u4e2a\u8fde\u63a5\u8bf7\u6c42\u5df2\u7ecf\u5230\u8fbe,\u7b49\u5f85\u786e\u8ba4<\/p>\n SYN_SENT\uff1a\u5e94\u7528\u5df2\u7ecf\u5f00\u59cb,\u6253\u5f00\u4e00\u4e2a\u8fde\u63a5<\/p>\n ESTABLISHED\uff1a\u6b63\u5e38\u6570\u636e\u4f20\u8f93\u72b6\u6001<\/p>\n FIN_WAIT1\uff1a\u5e94\u7528\u8bf4\u5b83\u5df2\u7ecf\u5b8c\u6210<\/p>\n FIN_WAIT2\uff1a\u53e6\u4e00\u8fb9\u5df2\u540c\u610f\u91ca\u653e<\/p>\n ITMED_WAIT\uff1a\u7b49\u5f85\u6240\u6709\u5206\u7ec4\u6b7b\u6389<\/p>\n CLOSING\uff1a\u4e24\u8fb9\u540c\u65f6\u5c1d\u8bd5\u5173\u95ed<\/p>\n TIME_WAIT\uff1a\u53e6\u4e00\u8fb9\u5df2\u521d\u59cb\u5316\u4e00\u4e2a\u91ca\u653e<\/p>\n LAST_ACK\uff1a\u7b49\u5f85\u6240\u6709\u5206\u7ec4\u6b7b\u6389<\/p><\/blockquote>\n \u53c2\u8003\u8d44\u6599\uff1a<\/strong><\/p>\n http:\/\/bbs.chinaunix.net\/forum.php?mod=viewthread&tid=544063<\/a><\/p>\n\n