{"id":201647,"date":"2025-05-10T11:37:23","date_gmt":"2025-05-10T03:37:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201647\/"},"modified":"2025-05-10T11:37:23","modified_gmt":"2025-05-10T03:37:23","slug":"redis%e5%86%85%e5%ad%98%e7%a2%8e%e7%89%87%e5%8e%9f%e7%90%86%e6%b7%b1%e5%85%a5%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201647\/","title":{"rendered":"Redis\u5185\u5b58\u788e\u7247\u539f\u7406\u6df1\u5165\u5206\u6790"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Redis\u5185\u5b58\u788e\u7247\u539f\u7406\u6df1\u5165\u5206\u6790<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u600e\u4e48\u5165\u95e8\u6570\u636e\u5e93\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762golang\u5b66\u4e60\u7f51\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aRedis\u5185\u5b58\u788e\u7247\u539f\u7406\u6df1\u5165\u5206\u6790\u300b\uff0c\u6d89\u53ca\u5230\u5185\u5b58\u3001Redis\u5185\u5b58\u788e\u7247\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p>\u7b54\u6848\u662f\uff1a\u5b83\u53ef\u80fd\u4ecd\u7136\u5360\u7528\u5927\u7ea65GB\u5185\u5b58\uff0c\u5373\u4f7fRedis\u6570\u636e\u53ea\u5360\u7528\u5927\u7ea63GB\u3002<\/p>\n<p>\u5982\u679c<code>maxmemory<\/code>\u4e0d\u8bbe\u7f6e\u8be5\u53c2\u6570\uff0cRedis\u4e0d\u4f1a\u89e6\u53d1\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\u5220\u9664\u6570\u636e\u3002<\/p>\n<p>Redis\u4f1a\u7ee7\u7eed\u4e3a\u65b0\u5199\u5165\u7684\u6570\u636e\u5206\u914d\u5185\u5b58\u3002\u5206\u914d\u5931\u8d25\u4f1a\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u62a5\u9519\uff0c\u5f53\u7136\u4e0d\u4f1a\u5bfc\u81f4\u5b95\u673a\u3002<\/p>\n<p>\u6ce8\uff1a\u8bbe\u7f6e<code>maxmemory<\/code>\u53c2\u6570\uff0c\u6267\u884c\u547d\u4ee4<code>CONFIG SET maxmemory 100mb<\/code>\uff0c\u6216\u5728<code>redis.conf<\/code> \u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6emaxmemory 100mb\u3002<\/p>\n<p>\u4f7f\u7528top\u547d\u4ee4\u67e5\u770b\u6570\u636e\u662f\u5426\u5df2\u7ecf\u5220\u9664\uff0c\u4e3a\u4ec0\u4e48\u5b83\u4ecd\u7136\u5360\u7528\u8fd9\u4e48\u591a\u5185\u5b58\uff1f<\/p>\n<h2>\u91ca\u653e\u7684\u5185\u5b58\u53bb\u4e86\u54ea\u91cc\uff1f<\/h2>\n<p>\u5f53\u6211\u4eec\u4f7f\u7528top\u547d\u4ee4\u67e5\u770b\u7cfb\u7edf\u4f7f\u7528\u60c5\u51b5\u65f6\uff0c\u4f1a\u53d1\u73b0\u5185\u5b58\u4f9d\u7136\u5f88\u9ad8\uff0cRedis\u5e76\u6ca1\u6709\u771f\u6b63\u91ca\u653e\u5185\u5b58\u3002\u90a3\u4e48\u5185\u5b58\u90fd\u53bb\u54ea\u513f\u4e86\uff1f\u8fd9\u65f6\u5019\u6211\u4eec\u5c31\u9700\u8981\u4f7f\u7528<code>info memory<\/code>\u547d\u4ee4\u83b7\u53d6Redis\u5185\u5b58\u76f8\u5173\u7684\u6307\u6807\u3002<\/p>\n<pre>127.0.0.1:6379&gt; info memory\n# Memory\nused_memory:1132832           \/\/ Redis Amount of memory used to store data\nused_memory_human:1.08M       \/\/ Returns the total amount of memory in human readable form\nused_memory_rss:2977792       \/\/ From the perspective of the operating system, the total physical memory occupied by the process\nused_memory_rss_human:2.84M   \/\/ used_memory_rss Readability mode display\nused_memory_peak:1183808      \/\/ The maximum value of memory used, representing the peak value of used_memory\nused_memory_peak_human:1.13M  \/\/ Returns the value of used_memory_peak in a human readable format\nused_memory_lua:37888         \/\/ Lua The amount of memory consumed by the engine\u3002\nused_memory_lua_human:37.00K\nmaxmemory:2147483648          \/\/ The maximum memory value that can be used, in bytes.\nmaxmemory_human:2.00G         \/\/ readable form\nmaxmemory_policy:noeviction   \/\/ Memory Retirement Policy\nmem_fragmentation_ratio:2.79  \/\/ The ratio of used_memory_rss &amp; used_memory represents the memory fragmentation rate\n<\/pre>\n<p>Redis\u8fdb\u7a0b\u5185\u5b58\u6d88\u8017\u4e3b\u8981\u7531\u4ee5\u4e0b\u51e0\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n<ul>\n<li>\u5185\u5b58\u88abRedis\u81ea\u5df1\u542f\u52a8\u5360\u7528<\/li>\n<li>\u5b58\u50a8\u5bf9\u8c61\u6570\u636e\u5185\u5b58<\/li>\n<li>\u7f13\u51b2\u533a\u5185\u5b58\uff1a\u4e3b\u8981\u7531<code>client-output-buffer-limit<\/code>\u5ba2\u6237\u7aef\u8f93\u51fa\u7f13\u51b2\u533a\u3001<code>copy backlog<\/code>\u7f13\u51b2\u533a\u3001<code>AOF<\/code>\u7f13\u51b2\u533a\u7ec4\u6210<\/li>\n<li>\u5185\u5b58\u788e\u7247<\/li>\n<\/ul>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167729413363f97a350d5b1.png\" class=\"aligncenter\"><\/p>\n<p>Redis\u81ea\u8eab\u7684\u7a7a\u8fdb\u7a0b\u5360\u7528\u7684\u5185\u5b58\u5f88\u5c0f\uff0c\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\uff0c\u800c\u5bf9\u8c61\u5185\u5b58\u662f\u6700\u5927\u7684\uff0c\u91cc\u9762\u5b58\u653e\u4e86\u6240\u6709\u7684\u6570\u636e\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f, \u5982\u679c\u7f13\u51b2\u533a\u6709\u5927\u6d41\u91cf\u7684\u573a\u666f\u5f88\u5bb9\u6613\u5931\u63a7\uff0c\u5bfc\u81f4Redis\u5185\u5b58\u4e0d\u7a33\u5b9a\u3002<\/p>\n<p>\u5185\u5b58\u788e\u7247\u8fc7\u591a\u5bfc\u81f4\u6709\u53ef\u7528\u7a7a\u95f4\u4e0d\u8db3\uff0c\u65e0\u6cd5\u5b58\u50a8\u6570\u636e\u3002\u5185\u5b58\u788e\u7247<code>Fragmentation<\/code> = <code>used_memory_rss<\/code> \u5b9e\u9645\u4f7f\u7528\u7684\u7269\u7406\u5185\u5b58\uff08RSS \u503c\uff09\u9664\u4ee5 <code>used_memory<\/code> \u5b9e\u9645\u5b58\u50a8\u7684\u6570\u636e\u5185\u5b58\u3002<\/p>\n<h2>\u4ec0\u4e48\u662f\u5185\u5b58\u788e\u7247\uff1f<\/h2>\n<p>\u5185\u5b58\u788e\u7247\u4f1a\u5bfc\u81f4\u5185\u5b58\u7a7a\u95f4\u7a7a\u95f2\uff0c\u4f46\u65e0\u6cd5\u5b58\u50a8\u6570\u636e\u3002\u6bd4\u5982\u4f60\u548c\u5973\u670b\u53cb\u53bb\u7535\u5f71\u9662\u770b\u7535\u5f71\uff0c\u4f60\u4eec\u80af\u5b9a\u662f\u8981\u5728\u4e00\u8d77\u7684\u3002<\/p>\n<p>\u5047\u8bbe\u73b0\u5728\u6709 8 \u4e2a\u5ea7\u4f4d\uff0c\u5df2\u552e\u51fa 4 \u5f20\u7968\uff0c\u8fd8\u6709 4 \u5f20\u53ef\u4f9b\u8d2d\u4e70\u3002\u4e0d\u8fc7\u5de7\u5408\u7684\u662f\uff0c\u4e70\u7968\u7684\u4eba\u5f88\u5947\u602a\uff0c\u90fd\u662f\u9694\u4e00\u4e2a\u5ea7\u4f4d\u4e70\u7968\u3002\u5373\u4f7f\u8fd8\u67094\u4e2a\u5ea7\u4f4d\uff0c\u4e5f\u4e0d\u80fd\u4e70\u987a\u5e8f\u8fde\u63a5\u4e24\u4e2a\u5ea7\u4f4d\u7684\u7968\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167729413363f97a3553dd5.png\" class=\"aligncenter\"><\/p>\n<h2>\u4ec0\u4e48\u5bfc\u81f4\u5185\u5b58\u788e\u7247\uff1f<\/h2>\n<p>\u4e3b\u8981\u6709\u4e24\u4e2a\u539f\u56e0\uff1a<\/p>\n<ul>\n<li>\u5185\u5b58\u5206\u914d\u5668\u7684\u5206\u914d\u7b56\u7565<\/li>\n<li>\u952e\u503c\u5bf9\u7684\u5927\u5c0f\u4e0d\u540c\uff0c\u5220\u9664\u64cd\u4f5c<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u6211\u4eec\u5c31\u5b9e\u9645\u53d1\u751f\u7684\u539f\u56e0\u8fdb\u884c\u63a2\u8ba8\u3002<\/p>\n<p><strong>1. \u5185\u5b58\u5206\u914d\u5668\u7684\u5206\u914d\u7b56\u7565<\/strong><\/p>\n<p>Redis \u9ed8\u8ba4\u7684\u5185\u5b58\u5206\u914d\u5668\u4f7f\u7528<code>jemalloc<\/code>\uff0c\u53ef\u9009\u7684\u5206\u914d\u5668\u6709\uff1a<code>glibc<\/code>\uff0c<code>tcmalloc<\/code>\u3002<\/p>\n<p>\u5185\u5b58\u5206\u914d\u5668\u4e0d\u80fd\u6309\u9700\u5206\u914d\uff0c\u800c\u662f\u4f7f\u7528\u56fa\u5b9a\u8303\u56f4\u7684\u5185\u5b58\u5757\u8fdb\u884c\u5206\u914d\u3002<\/p>\n<p>\u6bd4\u59828\u5b57\u8282\u300116\u5b57\u8282\u2026\u2026\u30012KB\u30014KB\uff0c\u5f53\u7533\u8bf7\u5185\u5b58\u6700\u63a5\u8fd1\u56fa\u5b9a\u503c\u65f6\uff0c<code>jemalloc<\/code>\u4f1a\u5206\u914d\u6700\u63a5\u8fd1\u56fa\u5b9a\u503c\u7684\u7a7a\u95f4\u3002\u8fd9\u6837\u5c31\u4f1a\u51fa\u73b0\u5185\u5b58\u788e\u7247\u3002<\/p>\n<p>\u6bd4\u5982\u7a0b\u5e8f\u53ea\u9700\u89811.5KB\uff0c\u800c\u5185\u5b58\u5206\u914d\u5668\u4f1a\u5206\u914d2KB\u7684\u7a7a\u95f4\uff0c\u90a3\u4e48\u8fd90.5KB\u5c31\u662f\u788e\u7247\u3002\u8fd9\u6837\u505a\u7684\u76ee\u7684\u662f\u51cf\u5c11\u5185\u5b58\u5206\u914d\u7684\u6b21\u6570\u3002\u6bd4\u5982\u4f60\u7533\u8bf722\u4e2a\u5b57\u8282\u7684\u7a7a\u95f4\u6765\u5b58\u653e\u6570\u636e\uff0cjemalloc\u5c31\u4f1a\u5206\u914d32\u4e2a\u5b57\u8282\u3002\u5982\u679c\u540e\u9762\u9700\u8981\u5199\u516510\u4e2a\u5b57\u8282\uff0c\u5219\u4e0d\u9700\u8981\u5411\u64cd\u4f5c\u7cfb\u7edf\u7533\u8bf7\u7a7a\u95f4\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e4b\u524d\u8bf7\u6c42\u7684 32 \u4e2a\u5b57\u8282\u3002<\/p>\n<p>\u5f53\u4e00\u4e2a\u952e\u88ab\u5220\u9664\u65f6\uff0cRedis \u4e0d\u4f1a\u7acb\u5373\u5c06\u5185\u5b58\u5f52\u8fd8\u7ed9\u64cd\u4f5c\u7cfb\u7edf\u3002\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u662f\u56e0\u4e3a\u5e95\u5c42\u5185\u5b58\u5206\u914d\u5668\u7684\u7ba1\u7406\u3002\u4f8b\u5982\uff0c\u5927\u591a\u6570\u5df2\u5220\u9664\u7684\u952e\u4ecd\u4e0e\u5176\u4ed6\u6709\u6548\u952e\u5206\u914d\u5728\u540c\u4e00\u5185\u5b58\u9875\u4e2d\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u4e3a\u4e86\u91cd\u7528\u7a7a\u95f2\u5185\u5b58\u5757\uff0c\u5206\u914d\u5668\u5220\u9664\u4e86\u539f\u59cb 5 GB \u6570\u636e\u4e2d\u7684 2 GB\u3002\u518d\u6b21\u5411\u5b9e\u4f8b\u6dfb\u52a0\u6570\u636e\u65f6\uff0cRedis\u7684RSS\u4f1a\u4fdd\u6301\u7a33\u5b9a\uff0c\u4e0d\u4f1a\u589e\u52a0\u592a\u591a\u3002\u56e0\u4e3a\u5185\u5b58\u5206\u914d\u5668\u57fa\u672c\u4e0a\u91cd\u65b0\u4f7f\u7528\u4e86\u4e4b\u524d\u5220\u9664\u91ca\u653e\u76842GB\u5185\u5b58\u3002<\/p>\n<p><strong>2.\u952e\u503c\u5bf9\u5927\u5c0f\u4e0d\u540c\uff0c\u5220\u9664\u64cd\u4f5c<\/strong><\/p>\n<p>\u7531\u4e8e\u5185\u5b58\u5206\u914d\u5668\u662f\u6309\u7167\u56fa\u5b9a\u7684\u5927\u5c0f\u5206\u914d\u5185\u5b58\uff0c\u56e0\u6b64\u5206\u914d\u7684\u5185\u5b58\u7a7a\u95f4\u901a\u5e38\u4f1a\u5927\u4e8e\u5b9e\u9645\u6570\u636e\u5360\u7528\u7684\u5927\u5c0f\uff0c\u8fd9\u4f1a\u9020\u6210\u788e\u7247\uff0c\u964d\u4f4e\u5185\u5b58\u7684\u5b58\u50a8\u6548\u7387\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u952e\u503c\u5bf9\u7684\u9891\u7e41\u4fee\u6539\u548c\u5220\u9664\u5bfc\u81f4\u5185\u5b58\u7a7a\u95f4\u7684\u6269\u5927\u548c\u91ca\u653e\u3002\u4f8b\u5982\uff0c\u5982\u679c\u539f\u6765\u5360\u752832\u4e2a\u5b57\u8282\u7684\u5b57\u7b26\u4e32\u73b0\u5728\u4fee\u6539\u4e3a\u5360\u752820\u4e2a\u5b57\u8282\u7684\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u91ca\u653e\u768412\u4e2a\u5b57\u8282\u5c31\u662f\u7a7a\u95f2\u7a7a\u95f4\u3002<\/p>\n<p>\u5982\u679c\u4e0b\u4e00\u6b21\u6570\u636e\u5b58\u50a8\u8bf7\u6c42\u9700\u8981\u7533\u8bf7\u4e00\u4e2a13\u5b57\u8282\u7684\u5b57\u7b26\u4e32\uff0c\u521a\u521a\u91ca\u653e\u768412\u5b57\u8282\u7a7a\u95f4\u5c31\u4e0d\u80fd\u4f7f\u7528\uff0c\u9020\u6210\u788e\u7247\u3002<\/p>\n<p>\u5206\u7247\u6700\u5927\u7684\u95ee\u9898\uff1a\u7a7a\u95f4\u603b\u91cf\u8db3\u591f\u5927\uff0c\u4f46\u662f\u8fd9\u4e9b\u5185\u5b58\u5e76\u4e0d\u8fde\u7eed\uff0c\u53ef\u80fd\u5b58\u4e0d\u4e0b\u6570\u636e\u3002<\/p>\n<blockquote>\n<p>mem_fragmentation_ratio = used_memory_rss\/ used_memory<\/p>\n<\/blockquote>\n<h2>\u5982\u4f55\u89e3\u51b3\uff1f<\/h2>\n<p>\u9996\u5148\u8981\u5224\u65ad\u662f\u5426\u53d1\u751f\u4e86\u5185\u5b58\u788e\u7247\uff0c\u91cd\u70b9\u770b<code>info memory<\/code>\u547d\u4ee4\u6267\u884c\u540e\u7684<code>mem_fragmentation_ratio<\/code>\u6307\u6807\uff0c\u8868\u793a\u5185\u5b58\u788e\u7247\u7387\u3002<\/p>\n<p>\u5982\u679c<code>1 \uff0c\u53ef\u4ee5\u8ba4\u4e3a\u662f\u5408\u7406\u7684\uff0c\u5982\u679c\u5927\u4e8e1.5\uff0c\u8bf4\u660e\u788e\u7247\u5df2\u7ecf\u8d85\u8fc7\u4e8650%\uff0c\u6211\u4eec\u9700\u8981\u91c7\u53d6\u4e00\u4e9b\u63aa\u65bd\u6765\u89e3\u51b3\u788e\u7247\u8fc7\u591a\u7684\u95ee\u9898\u3002<\/code><\/p>\n<p><strong>1. \u91cd\u542f<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u91cd\u65b0\u542f\u52a8\u3002\u5982\u679c\u672a\u542f\u7528\u6301\u4e45\u6027\uff0c\u6570\u636e\u5c06\u4e22\u5931\u3002<\/p>\n<p>\u5982\u679c\u5f00\u542f\u6301\u4e45\u5316\uff0c\u9700\u8981\u4f7f\u7528RDB\u6216\u8005AOF\u6765\u6062\u590d\u6570\u636e\u3002\u5982\u679c\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u6570\u636e\u91cf\u5927\u4f1a\u5bfc\u81f4\u6062\u590d\u9636\u6bb5\u957f\u65f6\u95f4\u65e0\u6cd5\u63d0\u4f9b\u670d\u52a1\uff0c\u9ad8\u53ef\u7528\u6027\u4f1a\u5927\u5927\u964d\u4f4e\u3002<\/p>\n<p><strong>2.\u81ea\u52a8\u6e05\u7406\u5185\u5b58\u788e\u7247<\/strong><\/p>\n<p>Redis\u57284.0\u7248\u672c\u4e4b\u540e\uff0c\u63d0\u4f9b\u4e86\u5185\u5b58\u788e\u7247\u6e05\u7406\u673a\u5236\u3002<\/p>\n<p>\u5bf9\u4e8eRedis\u6765\u8bf4\uff0c\u5f53\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u88ab\u5206\u5272\u6210\u82e5\u5e72\u4e2a\u4e0d\u8fde\u7eed\u7684\u7a7a\u95f4\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u9996\u5148\u5c06\u6570\u636e\u79fb\u52a8\u62fc\u63a5\u5728\u4e00\u8d77\uff0c\u91ca\u653e\u6389\u539f\u6765\u6570\u636e\u5360\u7528\u7684\u7a7a\u95f4\uff0c\u5f62\u6210\u4e00\u4e2a\u8fde\u7eed\u7684\u7a7a\u95f2\u5185\u5b58\u7a7a\u95f4\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230225\/167729413363f97a35b7415.png\" class=\"aligncenter\"><\/p>\n<p>\u56fe\u7247\u7531\u4f5c\u8005\u63d0\u4f9b<\/p>\n<p>\u81ea\u52a8\u6e05\u7406\u867d\u7136\u597d\uff0c\u4f46\u4e5f\u4e0d\u8981\u4e71\u6765\u3002\u64cd\u4f5c\u7cfb\u7edf\u9700\u8981\u6d88\u8017\u8d44\u6e90\u5c06\u6570\u636e\u79fb\u52a8\u5230\u65b0\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u91ca\u653e\u539f\u6765\u7684\u7a7a\u95f4\u3002<\/p>\n<p>Redis \u64cd\u4f5c\u6570\u636e\u7684\u6307\u4ee4\u662f\u5355\u7ebf\u7a0b\u7684\uff0c\u6240\u4ee5\u5728\u6570\u636e\u590d\u5236\u548c\u79fb\u52a8\u65f6\uff0c\u53ea\u6709\u6e05\u7406\u788e\u7247\u540e\u624d\u80fd\u5904\u7406\u8bf7\u6c42\uff0c\u4f1a\u9020\u6210\u6027\u80fd\u635f\u5931\u3002<\/p>\n<p><strong>\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u5982\u4f55\u51cf\u5c11\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u6765\u5b9e\u73b0\u81ea\u52a8\u6e05\u7406\u788e\u7247\uff1f<\/strong><\/p>\n<p>\u95ee\u5f97\u597d\uff0c\u7528\u4e0b\u9762\u4e24\u4e2a\u53c2\u6570\u6765\u63a7\u5236\u5185\u5b58\u788e\u7247\u6e05\u7406\u548c\u7ed3\u675f\u7684\u65f6\u673a\uff0c\u907f\u514d\u5360\u7528\u8fc7\u591aCPU\uff0c\u51cf\u5c11\u6e05\u7406\u788e\u7247\u5bf9Redis\u5904\u7406\u8bf7\u6c42\u7684\u6027\u80fd\u5f71\u54cd\u3002<\/p>\n<p>\u542f\u7528\u81ea\u52a8\u5185\u5b58\u788e\u7247\u6574\u7406\uff1a<\/p>\n<pre>CONFIG SET activedefrag yes\n<\/pre>\n<p>\u8fd9\u53ea\u662f\u4e3a\u4e86\u542f\u7528\u81ea\u52a8\u6e05\u6d01\u3002\u5f53\u6e05\u7406\u9700\u8981\u540c\u65f6\u6ee1\u8db3\u4ee5\u4e0b\u4e24\u4e2a\u6761\u4ef6\u65f6\uff0c\u5c31\u4f1a\u51fa\u53d1\u6e05\u7406\u64cd\u4f5c\u3002<\/p>\n<ul>\n<li><strong>\u6e05\u7406\u6761\u4ef6<\/strong><\/li>\n<\/ul>\n<p><code>active-defrag-ignore-bytes 200mb<\/code>\uff1a\u5185\u5b58\u788e\u7247\u5360\u7528\u5185\u5b58\u8fbe\u5230200MB\uff0c\u5f00\u59cb\u6e05\u7406\uff1b<\/p>\n<p><code>active-defrag-threshold-lower 20<\/code>: \u5185\u5b58\u788e\u7247\u7a7a\u95f4\u8d85\u8fc7\u7cfb\u7edf\u5206\u914d\u7ed9Redis\u7a7a\u95f4\u768420%\uff0c\u5f00\u59cb\u6e05\u7406\u3002<\/p>\n<ul>\n<li><strong>\u907f\u514d\u6027\u80fd\u5f71\u54cd<\/strong><\/li>\n<\/ul>\n<p>\u6e05\u7406\u65f6\u95f4\u662f\u6709\u7684\uff0c\u9700\u8981\u63a7\u5236\u6e05\u7406\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u3002\u4e00\u4e8c\u8bbe\u7f6e\u5148\u5206\u914d\u6e05\u7406\u788e\u7247\u5360\u7528\u7684CPU\u8d44\u6e90\uff0c\u4fdd\u8bc1\u788e\u7247\u53ef\u4ee5\u6b63\u5e38\u6e05\u7406\uff0c\u907f\u514d\u5bf9Redis\u5904\u7406\u8bf7\u6c42\u9020\u6210\u6027\u80fd\u5f71\u54cd\u3002<\/p>\n<p><code>active-defrag-cycle-min 20<\/code>\uff1a\u81ea\u52a8\u788e\u7247\u6574\u7406\u8fc7\u7a0b\u4e2d\u5360\u7528CPU\u65f6\u95f4\u6bd4\u4f8b\u4e0d\u4f4e\u4e8e20%\uff0c\u4ee5\u4fdd\u8bc1\u6e05\u7406\u4efb\u52a1\u6b63\u5e38\u8fdb\u884c\u3002<\/p>\n<p><code>active-defrag-cycle-max 50<\/code>\uff1a\u81ea\u52a8\u6e05\u7406\u8fdb\u7a0b\u5360\u7528CPU\u65f6\u95f4\u6bd4\u4f8b\u4e0d\u80fd\u9ad8\u4e8e50%\u3002\u5982\u679c\u8d85\u8fc7\uff0c\u4f1a\u7acb\u5373\u505c\u6b62\u6e05\u7406\uff0c\u907f\u514d\u963b\u585e Redis \u9020\u6210\u9ad8\u5ef6\u8fdf\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u5982\u679c\u53d1\u73b0Redis\u5b58\u50a8\u6570\u636e\u5360\u7528\u7684\u5185\u5b58\u6bd4\u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u7ed9Redis\u7684\u5185\u5b58\u5c0f\u5f88\u591a\uff0c\u4f46\u662f\u6570\u636e\u65e0\u6cd5\u4fdd\u5b58\uff0c\u90a3\u4e48\u53ef\u80fd\u662f\u5185\u5b58\u788e\u7247\u5f88\u591a\u3002\u4f7f\u7528<code>info memory<\/code>\u547d\u4ee4\u67e5\u770b\u5185\u5b58\u788e\u7247<code>mem_fragmentation_ratio<\/code>\u6307\u6807\u662f\u5426\u6b63\u5e38\u3002<\/p>\n<p>\u7136\u540e\u6211\u4eec\u542f\u7528\u81ea\u52a8\u6e05\u7406\u5e76\u5408\u7406\u8bbe\u7f6e\u6e05\u7406\u65f6\u95f4\u548cCPU\u8d44\u6e90\u5360\u7528\u3002\u8be5\u673a\u5236\u6d89\u53ca\u5185\u5b58\u590d\u5236\uff0c\u8fd9\u5bf9 Redis \u6027\u80fd\u6784\u6210\u6f5c\u5728\u98ce\u9669\u3002\u5982\u679cRedis\u6027\u80fd\u53d8\u6162\uff0c\u68c0\u67e5\u662f\u5426\u662f\u6e05\u7406\u788e\u7247\u5bfc\u81f4\u7684\u3002\u5982\u679c\u662f\u8fd9\u6837\uff0c\u51cf\u5c0f\u914d\u7f6e<code>active-defrag-cycle-max<\/code>\u7684\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u5185\u5b58\u788e\u7247\u539f\u7406\u6df1\u5165\u5206\u6790 &#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-201647","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201647","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=201647"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201647\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}