{"id":4666,"date":"2021-12-07T21:59:37","date_gmt":"2021-12-08T05:59:37","guid":{"rendered":"https:\/\/www.xh86.me\/?p=4666"},"modified":"2021-12-07T22:13:57","modified_gmt":"2021-12-08T06:13:57","slug":"%e8%ae%b0%e4%b8%80%e6%ac%a1%e5%8d%95%e6%9c%ba%e7%b3%bb%e7%bb%9f%e7%9a%84%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%ef%bc%9a%e6%9c%80%e5%90%8e%e7%ab%9f%e6%98%af-tcp-%e7%9a%84%e9%94%85","status":"publish","type":"post","link":"https:\/\/www.xh86.me\/?p=4666","title":{"rendered":"\u8bb0\u4e00\u6b21\u5355\u673a\u7cfb\u7edf\u7684\u6027\u80fd\u4f18\u5316\uff1a\u6700\u540e\u7adf\u662f TCP \u7684\u9505"},"content":{"rendered":"<div class=\"wxsyncmain\">\n<h3 style=\"margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\"><span style=\"color: #444444;\">\u524d\u8a00<\/span><\/h3>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important; text-align: left;\"><span style=\"font-size: 15px; color: #444444;\">\u8fd9\u7bc7\u6587\u7ae0\u7684\u4e3b\u9898\u662f\u8bb0\u5f55\u4e00\u6b21 Python \u7a0b\u5e8f\u7684\u6027\u80fd\u4f18\u5316\uff0c\u5728\u4f18\u5316\u7684\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u95ee\u9898\uff0c\u4ee5\u53ca\u5982\u4f55\u53bb\u89e3\u51b3\u7684\u3002\u4e3a\u5927\u5bb6\u63d0\u4f9b\u4e00\u4e2a\u4f18\u5316\u7684\u601d\u8def\uff0c\u9996\u5148\u8981\u58f0\u660e\u7684\u4e00\u70b9\u662f\uff0c\u6211\u7684\u65b9\u5f0f\u4e0d\u662f\u552f\u4e00\u7684\uff0c\u5927\u5bb6\u5728\u6027\u80fd\u4f18\u5316\u4e4b\u8def\u4e0a\u9047\u5230\u7684\u95ee\u9898\u90fd\u7edd\u5bf9\u4e0d\u6b62\u4e00\u4e2a\u89e3\u51b3\u65b9\u6848\u3002<\/span><\/section>\n<h3 style=\"margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\"><span style=\"color: #444444;\">\u5982\u4f55\u4f18\u5316<\/span><\/h3>\n<p style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px; color: #444444;\">\u9996\u5148\u5927\u5bb6\u8981\u660e\u786e\u7684\u4e00\u70b9\u662f\uff0c\u8131\u79bb\u9700\u6c42\u8c08\u4f18\u5316\u90fd\u662f\u800d\u6d41\u6c13\uff0c\u6240\u4ee5\u6709\u8c01\u8ddf\u4f60\u8bf4\u5728xx\u673a\u5668\u4e0a\u5b9e\u73b0\u4e86\u767e\u4e07\u5e76\u53d1\uff0c\u57fa\u672c\u4e0a\u53ef\u4ee5\u8ba4\u4e3a\u662f\u4e0d\u61c2\u88c5\u61c2\u4e86\uff0c\u5355\u7eaf\u7684\u5e76\u53d1\u6570\u5b8c\u5168\u662f\u65e0\u610f\u4e49\u7684\u3002\u5176\u6b21\uff0c\u6211\u4eec\u4f18\u5316\u4e4b\u524d\u5fc5\u987b\u8981\u6709\u4e00\u4e2a\u76ee\u6807\uff0c\u9700\u8981\u4f18\u5316\u5230\u4ec0\u4e48\u7a0b\u5ea6\uff0c\u6ca1\u6709\u660e\u786e\u76ee\u6807\u7684\u4f18\u5316\u662f\u4e0d\u53ef\u63a7\u7684\u3002\u518d\u7136\u540e\uff0c\u6211\u4eec\u5fc5\u987b\u660e\u786e\u7684\u627e\u51fa\u6027\u80fd\u74f6\u9888\u5728\u54ea\u91cc\uff0c\u800c\u4e0d\u80fd\u6f2b\u65e0\u76ee\u7684\u7684\u4e00\u901a\u4e71\u641e\u3002<\/span><\/p>\n<h3 style=\"margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">\u9700\u6c42\u63cf\u8ff0<\/h3>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u8fd9\u4e2a\u9879\u76ee\u662f\u6211\u5728\u4e0a\u5bb6\u516c\u53f8\u8d1f\u8d23\u4e00\u4e2a\u5355\u72ec\u7684\u6a21\u5757\uff0c\u672c\u6765\u662f\u96c6\u6210\u5728\u4e3b\u7ad9\u4ee3\u7801\u4e2d\u7684\uff0c\u540e\u6765\u56e0\u4e3a\u5e76\u53d1\u592a\u5927\uff0c\u4e3a\u4e86\u9632\u6b62\u51fa\u73b0\u95ee\u9898\u540e\u62d6\u7d2f\u4e3b\u7ad9\u670d\u52a1\uff0c\u6240\u6709\u7531\u6211\u4e00\u4e2a\u4eba\u8d1f\u8d23\u62c6\u5206\u51fa\u6765\u3002\u5bf9\u8fd9\u4e2a\u6a21\u5757\u7684\u62c6\u5206\u8981\u6c42\u662f\uff0c\u538b\u529b\u6d4b\u8bd5 QPS \u4e0d\u80fd\u4f4e\u4e8e3\u4e07\uff0c\u6570\u636e\u5e93\u8d1f\u8f7d\u4e0d\u80fd\u8d85\u8fc750%\uff0c\u670d\u52a1\u5668\u8d1f\u8f7d\u4e0d\u80fd\u8d85\u8fc770%\uff0c\u5355\u6b21\u8bf7\u6c42\u65f6\u957f\u4e0d\u80fd\u8d85\u8fc770ms\uff0c\u9519\u8bef\u7387\u4e0d\u80fd\u8d85\u8fc75%\u3002<\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><strong><span style=\"font-size: 15px;\">\u73af\u5883\u7684\u914d\u7f6e\u5982\u4e0b\uff1a<\/span><\/strong><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u670d\u52a1\u5668\uff1a4\u68388G\u5185\u5b58\uff0cCentOS7\u7cfb\u7edf\uff0cSSD \u786c\u76d8<br \/>\n\u6570\u636e\u5e93\uff1aMySQL 5.7\uff0c\u6700\u5927\u8fde\u63a5\u6570 800<br \/>\n\u7f13\u5b58: Redis\uff0c1G \u5bb9\u91cf\u3002<\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u4ee5\u4e0a\u73af\u5883\u90fd\u662f\u8d2d\u4e70\u81ea\u817e\u8baf\u4e91\u7684\u670d\u52a1\u3002<\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u538b\u6d4b\u5de5\u5177\uff1alocust\uff0c\u4f7f\u7528\u817e\u8baf\u7684\u5f39\u6027\u4f38\u7f29\u5b9e\u73b0\u5206\u5e03\u5f0f\u7684\u538b\u6d4b\u3002<\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><strong><span style=\"font-size: 15px;\">\u9700\u6c42\u63cf\u8ff0\u5982\u4e0b\uff1a<\/span><\/strong><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u7528\u6237\u8fdb\u5165\u9996\u9875\uff0c\u4ece\u6570\u636e\u5e93\u4e2d\u67e5\u8be2\u662f\u5426\u6709\u5408\u9002\u7684\u5f39\u7a97\u914d\u7f6e\uff0c\u5982\u679c\u6ca1\u6709\uff0c\u5219\u7ee7\u7eed\u7b49\u5f85\u4e0b\u4e00\u6b21\u8bf7\u6c42\u3001\u5982\u679c\u6709\u5408\u9002\u7684\u914d\u7f6e\uff0c\u5219\u8fd4\u56de\u7ed9\u524d\u7aef\u3002\u8fd9\u91cc\u5f00\u59cb\u5219\u6709\u591a\u4e2a\u6761\u4ef6\u5206\u652f\uff0c\u5982\u679c\u7528\u6237\u70b9\u51fb\u4e86\u5f39\u7a97\uff0c\u5219\u8bb0\u5f55\u7528\u6237\u70b9\u51fb\uff0c\u5e76\u4e14\u5728\u914d\u7f6e\u7684\u65f6\u95f4\u5185\u4e0d\u518d\u8fd4\u56de\u914d\u7f6e\uff0c\u5982\u679c\u7528\u6237\u672a\u70b9\u51fb\uff0c\u521924\u5c0f\u65f6\u540e\u7ee7\u7eed\u8fd4\u56de\u672c\u6b21\u914d\u7f6e\uff0c\u5982\u679c\u7528\u6237\u70b9\u51fb\u4e86\uff0c\u4f46\u662f\u540e\u7eed\u6ca1\u6709\u914d\u7f6e\u4e86\uff0c\u5219\u63a5\u7740\u7b49\u5f85\u4e0b\u4e00\u6b21\u3002<\/span><\/section>\n<h3 style=\"margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">\u91cd\u70b9\u5206\u6790<\/h3>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u6839\u636e\u9700\u6c42\uff0c\u6211\u4eec\u77e5\u9053\u4e86\u6709\u51e0\u4e2a\u91cd\u8981\u7684\u70b9\uff0c1\u3001\u9700\u8981\u627e\u51fa\u5408\u9002\u7528\u6237\u7684\u5f39\u7a97\u914d\u7f6e\uff0c2\u3001\u9700\u8981\u8bb0\u5f55\u7528\u6237\u4e0b\u4e00\u6b21\u8fd4\u56de\u914d\u7f6e\u7684\u65f6\u95f4\u5e76\u8bb0\u5f55\u5230\u6570\u636e\u5e93\u4e2d\uff0c3\u3001\u9700\u8981\u8bb0\u5f55\u7528\u6237\u5bf9\u8fd4\u56de\u7684\u914d\u7f6e\u6267\u884c\u4e86\u4ec0\u4e48\u64cd\u4f5c\u5e76\u8bb0\u5f55\u5230\u6570\u636e\u5e93\u4e2d\u3002<\/span><\/section>\n<h3 style=\"margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">\u8c03\u4f18<\/h3>\n<p style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u4e0a\u8ff0\u4e09\u4e2a\u91cd\u70b9\u90fd\u5b58\u5728\u6570\u636e\u5e93\u7684\u64cd\u4f5c\uff0c\u4e0d\u53ea\u6709\u8bfb\u5e93\uff0c\u8fd8\u6709\u5199\u5e93\u64cd\u4f5c\u3002\u4ece\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5982\u679c\u4e0d\u52a0\u7f13\u5b58\u7684\u8bdd\uff0c\u6240\u6709\u7684\u8bf7\u6c42\u90fd\u538b\u5230\u6570\u636e\u5e93\uff0c\u52bf\u5fc5\u4f1a\u5360\u6ee1\u5168\u90e8\u8fde\u63a5\u6570\uff0c\u51fa\u73b0\u62d2\u7edd\u8bbf\u95ee\u7684\u9519\u8bef\uff0c\u540c\u65f6\u56e0\u4e3a SQL \u6267\u884c\u8fc7\u6162\uff0c\u5bfc\u81f4\u8bf7\u6c42\u65e0\u6cd5\u53ca\u65f6\u8fd4\u56de\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u9996\u5148\u8981\u505a\u7684\u5c31\u662f\u8bb2\u5199\u5e93\u64cd\u4f5c\u5265\u79bb\u5f00\u6765\uff0c\u63d0\u5347\u6bcf\u4e00\u6b21\u8bf7\u6c42\u54cd\u5e94\u901f\u5ea6\uff0c\u4f18\u5316\u6570\u636e\u5e93\u8fde\u63a5\u3002\u6574\u4e2a\u7cfb\u7edf\u7684\u67b6\u6784\u56fe\u5982\u4e0b\uff1a<\/span><\/p>\n<p style=\"margin: 0px 0px 1.2em !important;\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/12\/wxsync-2021-12-15d96f2f06238be02ca917eff75ea038.jpeg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" class=\"rich_pages wxw-img\" style=\"width: 569px; height: 588px;\" data-original=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/12\/wxsync-2021-12-15d96f2f06238be02ca917eff75ea038.jpeg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" data-croporisrc=\"https:\/\/mmbiz.qpic.cn\/mmbiz_png\/N34tfh8WYkg5wgozicSuhwMVTpgZmOgmzIB55uXC1YlKiaXcmgjaCmC7hTsDMRqLFIeLaPzWUazGYqjw6Kxib4Ffw\/640?wx_fmt=png\" data-cropx1=\"11.195501730103807\" data-cropx2=\"719\" data-cropy1=\"0\" data-cropy2=\"731.4394463667819\" data-ratio=\"1.0338983050847457\" data-type=\"jpeg\" data-w=\"708\" \/><\/div><\/p>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u5c06\u5199\u5e93\u64cd\u4f5c\u653e\u5230\u4e00\u4e2a\u5148\u8fdb\u5148\u51fa\u7684\u6d88\u606f\u961f\u5217\u4e2d\u6765\u505a\uff0c\u4e3a\u4e86\u51cf\u5c11\u590d\u6742\u5ea6\uff0c\u4f7f\u7528\u4e86Redis \u7684 list \u6765\u505a\u8fd9\u4e2a\u6d88\u606f\u961f\u5217\u3002<\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u7136\u540e\u8fdb\u884c\u538b\u6d4b\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a<\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">QPS \u5728 6000 \u5de6\u53f3 502 \u9519\u8bef\u5927\u5e45\u4e0a\u5347\u81f3 30%\uff0c\u670d\u52a1\u5668 CPU \u5728 60%-70% \u4e4b\u95f4\u6765\u56de\u8df3\u52a8\uff0c\u6570\u636e\u5e93\u8fde\u63a5\u6570\u88ab\u5360\u6ee1 TCP \u8fde\u63a5\u6570\u4e3a 6000 \u5de6\u53f3\uff0c\u5f88\u660e\u663e\uff0c\u95ee\u9898\u8fd8\u662f\u51fa\u5728\u6570\u636e\u5e93\uff0c\u7ecf\u8fc7\u6392\u67e5 SQL \u8bed\u53e5\uff0c\u67e5\u8be2\u5230\u539f\u56e0\u5c31\u662f\u627e\u51fa\u5408\u9002\u7528\u6237\u7684\u914d\u7f6e\u64cd\u4f5c\u65f6\u6bcf\u6b21\u8bf7\u6c42\u90fd\u8981\u8bfb\u53d6\u6570\u636e\u5e93\u6240\u5bfc\u81f4\u7684\u8fde\u63a5\u6570\u88ab\u7528\u5b8c\u3002\u56e0\u4e3a\u6211\u4eec\u7684\u8fde\u63a5\u6570\u53ea\u6709 800\uff0c\u4e00\u65e6\u8bf7\u6c42\u8fc7\u591a\uff0c\u52bf\u5fc5\u4f1a\u5bfc\u81f4\u6570\u636e\u5e93\u74f6\u9888\u3002\u597d\u4e86\uff0c\u95ee\u9898\u627e\u5230\u4e86\uff0c\u6211\u4eec\u7ee7\u7eed\u4f18\u5316\uff0c\u66f4\u65b0\u7684\u67b6\u6784\u5982\u4e0b\uff1a<\/span><\/section>\n<p style=\"margin: 0px 0px 1.2em !important;\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/12\/wxsync-2021-12-77cc94c2e62eb6c500947873846f63b0.jpeg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" class=\"rich_pages wxw-img\" style=\"width: 562px; height: 593px;\" data-original=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2021\/12\/wxsync-2021-12-77cc94c2e62eb6c500947873846f63b0.jpeg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" data-croporisrc=\"https:\/\/mmbiz.qpic.cn\/mmbiz_png\/N34tfh8WYkg5wgozicSuhwMVTpgZmOgmzzRJ1EiagkShtvMlAL4KCH8IH0lWV1NrH8CfQvCcjToCTlXibZAQAz8rQ\/640?wx_fmt=png\" data-cropx1=\"19.764705882352942\" data-cropx2=\"714\" data-cropy1=\"0\" data-cropy2=\"732.529411764706\" data-ratio=\"1.0532374100719424\" data-type=\"jpeg\" data-w=\"695\" \/><\/div><\/p>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u6211\u4eec\u5c06\u5168\u90e8\u7684\u914d\u7f6e\u90fd\u52a0\u8f7d\u5230\u7f13\u5b58\u4e2d\uff0c\u53ea\u6709\u5728\u7f13\u5b58\u4e2d\u6ca1\u6709\u914d\u7f6e\u7684\u65f6\u5019\u624d\u4f1a\u53bb\u8bfb\u53d6\u6570\u636e\u5e93\u3002<\/span><\/section>\n<p style=\"margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u63a5\u4e0b\u6765\u6211\u4eec\u518d\u6b21\u538b\u6d4b\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a<\/span><\/p>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">QPS \u538b\u5230 2\u4e07\u5de6\u53f3\u7684\u65f6\u5019\u5c31\u4e0a\u4e0d\u53bb\u4e86\uff0c\u670d\u52a1\u5668 CPU \u5728 60%-80% \u4e4b\u95f4\u8df3\u52a8\uff0c\u6570\u636e\u5e93\u8fde\u63a5\u6570\u4e3a300\u4e2a\u5de6\u53f3\uff0c\u6bcf\u79d2TPC\u8fde\u63a5\u6570\u4e3a1.5\u4e07\u5de6\u53f3\u3002<\/span><\/section>\n<p style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u8fd9\u4e2a\u95ee\u9898\u662f\u56f0\u6270\u6211\u6bd4\u8f83\u4e45\u7684\u4e00\u4e2a\u95ee\u9898\uff0c\u56e0\u4e3a\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec2\u4e07\u7684 QPS\uff0c\u4f46\u662fTCP \u8fde\u63a5\u6570\u5374\u5e76\u6ca1\u6709\u8fbe\u52302\u4e07\uff0c\u6211\u731c\u6d4b\uff0cTCP\u8fde\u63a5\u6570\u5c31\u662f\u5f15\u53d1\u74f6\u9888\u7684\u95ee\u9898\uff0c\u4f46\u662f\u56e0\u4e3a\u4ec0\u4e48\u539f\u56e0\u6240\u5f15\u53d1\u7684\u6682\u65f6\u65e0\u6cd5\u627e\u51fa\u6765\u3002<\/span><\/p>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u8fd9\u4e2a\u65f6\u5019\u731c\u6d4b\uff0c\u65e2\u7136\u662f\u65e0\u6cd5\u5efa\u7acb TCP \u8fde\u63a5\uff0c\u662f\u5426\u6709\u53ef\u80fd\u662f\u670d\u52a1\u5668\u9650\u5236\u4e86 socket \u8fde\u63a5\u6570\uff0c\u9a8c\u8bc1\u731c\u6d4b\uff0c\u6211\u4eec\u770b\u4e00\u4e0b\uff0c\u5728\u7ec8\u7aef\u8f93\u5165 <\/span><code style=\"font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; background-color: #f8f8f8; border-radius: 3px; display: inline; border: 1px solid #eaeaea;\"><span style=\"font-size: 15px;\">ulimit -n<\/span><\/code><span style=\"font-size: 15px;\"> \u547d\u4ee4\uff0c\u663e\u793a\u7684\u7ed3\u679c\u4e3a65535\uff0c\u770b\u5230\u8fd9\u91cc\uff0c\u89c9\u5f97 socket \u8fde\u63a5\u6570\u5e76\u4e0d\u662f\u9650\u5236\u6211\u4eec\u7684\u539f\u56e0\uff0c\u4e3a\u4e86\u9a8c\u8bc1\u731c\u6d4b\uff0c\u5c06 socket \u8fde\u63a5\u6570\u8c03\u5927\u4e3a100001.<\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\"><strong>\u518d\u6b21\u8fdb\u884c\u538b\u6d4b\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a<\/strong><\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">QPS\u538b\u52302.2\u4e07\u5de6\u53f3\u7684\u65f6\u5019\u5c31\u4e0a\u4e0d\u53bb\u4e86\uff0c\u670d\u52a1\u5668cpu\u572860%-80%\u4e4b\u95f4\u8df3\u52a8\uff0c\u6570\u636e\u5e93\u8fde\u63a5\u6570\u4e3a300\u4e2a\u5de6\u53f3\uff0c\u6bcf\u79d2 TCP \u8fde\u63a5\u6570\u4e3a1.7\u4e07\u5de6\u53f3\u3002<\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u867d\u7136\u6709\u4e00\u70b9\u63d0\u5347\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u5b9e\u8d28\u6027\u7684\u53d8\u5316\uff0c\u63a5\u4e0b\u6765\u7684\u51e0\u5929\u65f6\u95f4\uff0c\u6211\u53d1\u73b0\u90fd\u65e0\u6cd5\u627e\u5230\u4f18\u5316\u7684\u65b9\u6848\uff0c\u90a3\u51e0\u5929\u786e\u5b9e\u5f88\u96be\u53d7\uff0c\u627e\u4e0d\u51fa\u6765\u4f18\u5316\u7684\u65b9\u6848\uff0c\u8fc7\u4e86\u51e0\u5929\uff0c\u518d\u6b21\u5c06\u95ee\u9898\u68b3\u7406\u4e86\u4e00\u904d\uff0c\u53d1\u73b0\uff0c\u867d\u7136socket\u8fde\u63a5\u6570\u8db3\u591f\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u5168\u90e8\u88ab\u7528\u4e0a\uff0c\u731c\u6d4b\uff0c\u6bcf\u6b21\u8bf7\u6c42\u8fc7\u540e\uff0ctcp\u8fde\u63a5\u5e76\u6ca1\u6709\u7acb\u5373\u88ab\u91ca\u653e\uff0c\u5bfc\u81f4socket\u65e0\u6cd5\u91cd\u7528\u3002\u7ecf\u8fc7\u67e5\u627e\u8d44\u6599\uff0c\u627e\u5230\u4e86\u95ee\u9898\u6240\u5728\uff0c<\/span><\/section>\n<blockquote style=\"margin: 1.2em 0px; border-left: 4px solid #dddddd; padding: 0px 1em; color: #777777; quotes: none;\">\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\">TCP \u94fe\u63a5\u5728\u7ecf\u8fc7\u56db\u6b21\u63e1\u624b\u7ed3\u675f\u8fde\u63a5\u540e\u5e76\u4e0d\u4f1a\u7acb\u5373\u91ca\u653e\uff0c\u800c\u662f\u5904\u4e8e timewait \u72b6\u6001\uff0c\u4f1a\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\uff0c\u4ee5\u9632\u6b62\u5ba2\u6237\u7aef\u540e\u7eed\u7684\u6570\u636e\u672a\u88ab\u63a5\u6536\u3002<\/section>\n<\/blockquote>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important; text-align: left;\"><span style=\"font-size: 15px;\">\u597d\u4e86\uff0c\u95ee\u9898\u627e\u5230\u4e86\uff0c\u6211\u4eec\u8981\u63a5\u7740\u4f18\u5316\uff0c\u9996\u5148\u60f3\u5230\u7684\u5c31\u662f\u8c03\u6574 TCP \u94fe\u63a5\u7ed3\u675f\u540e\u7b49\u5f85\u65f6\u95f4\uff0c\u4f46\u662f Linux \u5e76\u6ca1\u6709\u63d0\u4f9b\u8fd9\u4e00\u5185\u6838\u53c2\u6570\u7684\u8c03\u6574\uff0c\u5982\u679c\u8981\u6539\uff0c\u5fc5\u987b\u8981\u81ea\u5df1\u91cd\u65b0\u7f16\u8bd1\u5185\u6838\uff0c\u5e78\u597d\u8fd8\u6709\u53e6\u4e00\u4e2a\u53c2\u6570 <\/span><code style=\"font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 0px 0.15em; padding: 0px 0.3em; white-space: pre-wrap; background-color: #f8f8f8; border-radius: 3px; display: inline; border: 1px solid #eaeaea;\"><span style=\"font-size: 15px;\">net.ipv4.tcp_max_tw_buckets<\/span><\/code><span style=\"font-size: 15px;\">\uff0c timewait \u7684\u6570\u91cf\uff0c\u9ed8\u8ba4\u662f180000\u3002\u6211\u4eec\u8c03\u6574\u4e3a 6000\uff0c\u7136\u540e\u6253\u5f00 timewait \u5feb\u901f\u56de\u6536\uff0c\u548c\u5f00\u542f\u91cd\u7528\uff0c\u5b8c\u6574\u7684\u53c2\u6570\u4f18\u5316\u5982\u4e0b\uff1a<\/span><\/section>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\" data-lang=\"shell\"><code><span class=\"code-snippet_outer\">#timewait \u7684\u6570\u91cf\uff0c\u9ed8\u8ba4\u662f 180000\u3002<\/span><\/code><code><span class=\"code-snippet_outer\">net.ipv4.tcp_max_tw_buckets = 6000<\/span><\/code><code><span class=\"code-snippet_outer\">\r\n<\/span><\/code><code><span class=\"code-snippet_outer\">net.ipv4.ip_local_port_range = 1024 65000<\/span><\/code><code><span class=\"code-snippet_outer\">\r\n<\/span><\/code><code><span class=\"code-snippet_outer\">#\u542f\u7528 timewait \u5feb\u901f\u56de\u6536\u3002<\/span><\/code><code><span class=\"code-snippet_outer\">net.ipv4.tcp_tw_recycle = 1#\u5f00\u542f\u91cd\u7528\u3002\u5141\u8bb8\u5c06 TIME-WAIT sockets \u91cd\u65b0\u7528\u4e8e\u65b0\u7684 TCP \u8fde\u63a5\u3002<\/span><\/code><code><span class=\"code-snippet_outer\">net.ipv4.tcp_tw_reuse = 1<\/span><\/code><\/pre>\n<\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u6211\u4eec\u518d\u6b21\u538b\u6d4b\uff0c\u7ed3\u679c\u663e\u793a\uff1aQPS 5\u4e07\uff0c\u670d\u52a1\u5668 CPU 70%\uff0c\u6570\u636e\u5e93\u8fde\u63a5\u6b63\u5e38\uff0cTCP \u8fde\u63a5\u6b63\u5e38\uff0c\u54cd\u5e94\u65f6\u95f4\u5e73\u5747\u4e3a 60ms\uff0c\u9519\u8bef\u7387\u4e3a 0%\u3002<\/span><\/section>\n<h3 style=\"margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em;\">\u7ed3\u8bed<\/h3>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">\u5230\u6b64\u4e3a\u6b62\uff0c\u6574\u4e2a\u670d\u52a1\u7684\u5f00\u53d1\u3001\u8c03\u4f18\u3001\u548c\u538b\u6d4b\u5c31\u7ed3\u675f\u4e86\u3002\u56de\u987e\u8fd9\u4e00\u6b21\u8c03\u4f18\uff0c\u5f97\u5230\u4e86\u5f88\u591a\u7ecf\u9a8c\uff0c\u6700\u91cd\u8981\u7684\u662f\uff0c\u6df1\u523b\u7406\u89e3\u4e86web\u5f00\u53d1\u4e0d\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u4e2a\u4f53\uff0c\u800c\u662f\u7f51\u7edc\u3001\u6570\u636e\u5e93\u3001\u7f16\u7a0b\u8bed\u8a00\u3001\u64cd\u4f5c\u7cfb\u7edf\u7b49\u591a\u95e8\u5b66\u79d1\u7ed3\u5408\u7684\u5de5\u7a0b\u5b9e\u8df5\uff0c\u8fd9\u5c31\u8981\u6c42web\u5f00\u53d1\u4eba\u5458\u6709\u7262\u56fa\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u5426\u5219\u51fa\u73b0\u4e86\u95ee\u9898\u8fd8\u4e0d\u77e5\u9053\u600e\u4e48\u5206\u6790\u67e5\u627e\u3002<\/span><\/section>\n<section style=\"line-height: 1.75em; margin: 0px 0px 1.2em !important;\"><span style=\"font-size: 15px;\">ps\uff1a\u670d\u52a1\u7aef\u5f00\u542f\u4e86 tcp_tw_recycle \u548c tcp_tw_reuse\u662f\u4f1a\u5bfc\u81f4\u4e00\u4e9b\u95ee\u9898\u7684\uff0c\u6211\u4eec\u4e3a\u4e86\u4f18\u5316\u9009\u62e9\u727a\u7272\u4e86\u4e00\u90e8\u5206\uff0c\u83b7\u5f97\u53e6\u4e00\u90e8\u5206\uff0c\u8fd9\u4e5f\u662f\u6211\u4eec\u8981\u660e\u786e\u7684.<\/span><\/section>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u8fd9\u7bc7\u6587\u7ae0\u7684\u4e3b\u9898\u662f\u8bb0\u5f55\u4e00\u6b21 Python \u7a0b\u5e8f\u7684\u6027\u80fd\u4f18\u5316\uff0c\u5728\u4f18\u5316\u7684\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u95ee\u9898\uff0c\u4ee5\u53ca\u5982\u4f55\u53bb\u89e3\u51b3\u7684\u3002\u4e3a\u5927 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-4666","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/4666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4666"}],"version-history":[{"count":1,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/4666\/revisions"}],"predecessor-version":[{"id":4858,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/4666\/revisions\/4858"}],"wp:attachment":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}