{"id":201175,"date":"2025-05-10T09:09:03","date_gmt":"2025-05-10T01:09:03","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201175\/"},"modified":"2025-05-10T09:09:03","modified_gmt":"2025-05-10T01:09:03","slug":"%e8%a7%a3%e5%86%b3redis%e5%90%af%e5%8a%a8%e8%ad%a6%e5%91%8a%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201175\/","title":{"rendered":"\u89e3\u51b3Redis\u542f\u52a8\u8b66\u544a\u95ee\u9898"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u89e3\u51b3Redis\u542f\u52a8\u8b66\u544a\u95ee\u9898<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6765\u5230golang\u5b66\u4e60\u7f51\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6570\u636e\u5e93\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300a\u89e3\u51b3Redis\u542f\u52a8\u8b66\u544a\u95ee\u9898\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\u89e3\u51b3\u3001Redis\u542f\u52a8\u3001\u8b66\u544a\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p>\u5982\u679c\u542f\u52a8\u524d\u4e0d\u5bf9linux\u5185\u6838\u505a\u4efb\u4f55\u66f4\u6539\uff0c\u90a3\u4e48redis\u542f\u52a8\u4f1a\u62a5\u51fa\u8b66\u544a\uff0c\u5171\u4e09\u4e2a\uff1a\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20221231\/167244570963af7f0d3d304.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u7b2c\u4e00\u4e2a\u8b66\u544a<\/strong>\uff1aThe TCP backlog setting of 511 cannot be enforced because \/proc\/sys\/net\/core\/somaxconn is set to the lower value of 128.<\/p>\n<p>\u610f\u601d\u662f\uff1aTCP &nbsp;backlog\u8bbe\u7f6e\u503c\uff0c511\u6ca1\u6709\u6210\u529f\uff0c\u56e0\u4e3a \/proc\/sys\/net\/core\/somaxconn\u8fd9\u4e2a\u8bbe\u7f6e\u7684\u662f\u66f4\u5c0f\u7684128.<\/p>\n<p>\u4e34\u65f6\u89e3\u51b3\u65b9\u6cd5\uff1a\uff08\u5373\u4e0b\u6b21\u542f\u52a8\u8fd8\u9700\u8981\u4fee\u6539\u6b64\u503c\uff09<\/p>\n<p><code>echo 511 &gt; \/proc\/sys\/net\/core\/somaxconn<\/code><\/p>\n<p>\u6c38\u4e45\u89e3\u51b3\u65b9\u6cd5\uff1a\uff08\u5373\u4ee5\u540e\u542f\u52a8\u8fd8\u9700\u8981\u4fee\u6539\u6b64\u503c\uff09<\/p>\n<p>\u5c06\u5176\u5199\u5165\/etc\/rc.local\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>baklog\u53c2\u6570\u5b9e\u9645\u63a7\u5236\u7684\u662f\u5df2\u7ecf3\u6b21\u63e1\u624b\u6210\u529f\u7684\u8fd8\u5728accept queue\u7684\u5927\u5c0f\u3002<\/p>\n<p>\u53c2\u8003linux\u91cc\u7684backlog\u8be6\u89e3<\/p>\n<p><strong>\u7b2c\u4e8c\u4e2a\u8b66\u544a<\/strong>\uff1aovercommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add &#8216;vm.overcommit_memory = 1&#8217; to\/etc\/sysctl.conf and then reboot or run the command &#8216;sysctl vm.overcommit_memory=1&#8217; for this to take effect.<\/p>\n<p>\u610f\u601d\u662f\uff1aovercommit_memory\u53c2\u6570\u8bbe\u7f6e\u4e3a0\uff01\u5728\u5185\u5b58\u4e0d\u8db3\u7684\u60c5\u51b5\u4e0b\uff0c\u540e\u53f0\u7a0b\u5e8fsave\u53ef\u80fd\u5931\u8d25\u3002\u5efa\u8bae\u5728\u6587\u4ef6 \/etc\/sysctl.conf \u4e2d\u5c06overcommit_memory\u4fee\u6539\u4e3a1\u3002<\/p>\n<p>\u4e34\u65f6\u89e3\u51b3\u65b9\u6cd5\uff1a<code>echo \"vm.overcommit_memory=1\" &gt; \/etc\/sysctl.conf<\/code><\/p>\n<p>\u6c38\u4e45\u89e3\u51b3\u65b9\u6cd5\uff1a\u5c06\u5176\u5199\u5165\/etc\/sysctl.conf\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u53c2\u8003\uff1a\u6709\u5173linux\u4e0bredis overcommit_memory\u7684\u95ee\u9898<\/p>\n<p><strong>\u7b2c\u4e09\u4e2a\u8b66\u544a<\/strong>\uff1ayou have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue run the command &#8216;echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled&#8217; as root, and add it to your \/etc\/rc.local in order to retain thesetting after a reboot. Redis must be restarted after THP is disabled.<\/p>\n<p>\u610f\u601d\u662f\uff1a\u4f60\u4f7f\u7528\u7684\u662f\u900f\u660e\u5927\u9875\uff0c\u53ef\u80fd\u5bfc\u81f4redis\u5ef6\u8fdf\u548c\u5185\u5b58\u4f7f\u7528\u95ee\u9898\u3002\u6267\u884c <code>echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled<\/code> \u4fee\u590d\u8be5\u95ee\u9898\u3002<\/p>\n<p>\u4e34\u65f6\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p><code>echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled<\/code>\u3002<\/p>\n<p>\u6c38\u4e45\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<p>\u5c06\u5176\u5199\u5165\/etc\/rc.local\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u53c2\u8003\u900f\u660e\u5927\u9875\u4ecb\u7ecd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u51b3Redis\u542f\u52a8\u8b66\u544a\u95ee\u9898 \u6536\u85cf&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201175","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201175"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201175\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}