{"id":252398,"date":"2022-09-19T09:05:00","date_gmt":"2022-09-19T01:05:00","guid":{"rendered":"https:\/\/gulass.cn\/?p=252398"},"modified":"2022-09-14T22:05:44","modified_gmt":"2022-09-14T14:05:44","slug":"redis-memory","status":"publish","type":"post","link":"https:\/\/gulass.cn\/redis-memory.html","title":{"rendered":"Redis \u7684\u6570\u636e\u88ab\u5220\u9664\u8fd8\u5360\u5185\u5b58\u5417?"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5982\u679c\u4f60\u53d1\u73b0\u660e\u660e Redis \u5b58\u50a8\u6570\u636e\u7684\u5185\u5b58\u5360\u7528\u8fdc\u5c0f\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u7ed9 Redis \u7684\u5185\u5b58\uff0c\u800c\u53c8\u65e0\u6cd5\u4fdd\u5b58\u6570\u636e\uff0c\u90a3\u53ef\u80fd\u51fa\u73b0\u5927\u91cf\u5185\u5b58\u788e\u7247\u4e86\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u7ed9 Redis \u7684\u5185\u5b58\u6709 6GB\uff0c\u901a\u8fc7\u6307\u6807 used_memory_human \u53d1\u73b0\u5b58\u50a8\u6570\u636e\u53ea\u4f7f\u7528\u4e86 4GB\uff0c\u4e3a\u4f55\u4f1a\u8fd9\u6837\uff1f\u4e3a\u4f55\u65e0\u6cd5\u4fdd\u5b58\u6570\u636e\uff1f<\/p>\n

\u901a\u8fc7 CONFIG SET maxmemory 100mb\u6216\u8005\u5728 redis.conf \u914d\u7f6e\u6587\u4ef6\u8bbe\u7f6e maxmemory 100mb Redis \u5185\u5b58\u5360\u7528\u9650\u5236\u3002\u5f53\u8fbe\u5230\u5185\u5b58\u6700\u5927\u503c\uff0c\u4f1a\u89e6\u53d1\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\u5220\u9664\u6570\u636e\u3002<\/p>\n

\u9664\u6b64\u4e4b\u5916\uff0c\u5f53 key \u8fbe\u5230\u8fc7\u671f\u65f6\u95f4\uff0cRedis \u4f1a\u6709\u4ee5\u4e0b\u4e24\u79cd\u5220\u9664\u8fc7\u671f\u6570\u636e\u7684\u7b56\u7565\uff1a<\/p>\n

\u540e\u53f0\u5b9a\u65f6\u4efb\u52a1\u9009\u53d6\u90e8\u5206\u6570\u636e\u5220\u9664\uff1b
\n\u60f0\u6027\u5220\u9664\u3002
\n\u5177\u4f53\u539f\u7406\u8bf7\u79fb\u6b65\u300a\u200b\u200bRedis \u7684\u8fc7\u671f\u6570\u636e\u5220\u9664\u90a3\u4e9b\u4e8b\u200b\u200b\u300b\u3002<\/p>\n

\u5047\u8bbe Redis \u5b9e\u4f8b\u4fdd\u5b58\u4e86 5GB \u7684\u6570\u636e\uff0c\u73b0\u5728\u5220\u9664\u4e86 2GB \u6570\u636e\uff0cRedis \u8fdb\u7a0b\u5360\u7528\u7684\u5185\u5b58\u4e00\u5b9a\u4f1a\u964d\u4f4e\u4e48\uff1f\uff08\u4e5f\u53eb\u505a RSS\uff0c\u8fdb\u7a0b\u6d88\u8017\u5185\u5b58\u9875\u6570\uff09\u3002<\/p>\n

\u7b54\u6848\u662f\uff1a\u53ef\u80fd\u4f9d\u7136\u5360\u7528\u4e86\u5927\u7ea6 5GB \u7684\u5185\u5b58\uff0c\u5373\u4f7f Redis \u7684\u6570\u636e\u53ea\u5360\u7528\u4e86 3GB \u5de6\u53f3\u3002<\/p>\n

\u5927\u5bb6\u4e00\u5b9a\u8981\u8bbe\u7f6emaxmemory\uff0c\u5426\u5219 Redis \u4f1a\u7ee7\u7eed\u4e3a\u65b0\u5199\u5165\u7684\u6570\u636e\u5206\u914d\u5185\u5b58\uff0c\u65e0\u6cd5\u5206\u914d\u5c31\u4f1a\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u62a5\u9519\uff0c\u5f53\u7136\u4e0d\u4f1a\u5bfc\u81f4\u5b95\u673a\u3002<\/p>\n

\u91ca\u653e\u7684\u5185\u5b58\u53bb\u54ea\u4e86<\/strong><\/div>\n

\u660e\u660e\u5220\u9664\u4e86\u6570\u636e\uff0c\u4f7f\u7528 top \u547d\u4ee4\u67e5\u770b\uff0c\u4e3a\u4f55\u8fd8\u662f\u5360\u7528\u4e86\u90a3\u4e48\u591a\u5185\u5b58\uff1f<\/p>\n

\u5185\u5b58\u90fd\u53bb\u54ea\u4e86\uff1f\u4f7f\u7528 info memory \u547d\u4ee4\u83b7\u53d6 Redis \u5185\u5b58\u76f8\u5173\u6307\u6807\uff0c\u6211\u5217\u4e3e\u4e86\u51e0\u4e2a\u91cd\u8981\u7684\u6570\u636e\uff1a<\/p>\n

127.0.0.1:6379> info memory\r\n# Memory\r\nused_memory:1132832  \/\/ Redis \u5b58\u50a8\u6570\u636e\u5360\u7528\u7684\u5185\u5b58\u91cf\r\nused_memory_human:1.08M  \/\/ \u4eba\u7c7b\u53ef\u8bfb\u5f62\u5f0f\u8fd4\u56de\u5185\u5b58\u603b\u91cf\r\nused_memory_rss:2977792  \/\/ \u64cd\u4f5c\u7cfb\u7edf\u89d2\u5ea6\uff0c\u8fdb\u7a0b\u5360\u7528\u7684\u7269\u7406\u603b\u5185\u5b58\r\nused_memory_rss_human:2.84M \/\/ used_memory_rss \u53ef\u8bfb\u6027\u6a21\u5f0f\u5c55\u793a\r\nused_memory_peak:1183808 \/\/ \u5185\u5b58\u4f7f\u7528\u7684\u6700\u5927\u503c\uff0c\u8868\u793a used_memory \u7684\u5cf0\u503c\r\nused_memory_peak_human:1.13M  \/\/ \u4ee5\u53ef\u8bfb\u7684\u683c\u5f0f\u8fd4\u56de used_memory_peak\u7684\u503c\r\nused_memory_lua:37888   \/\/ Lua \u5f15\u64ce\u6240\u6d88\u8017\u7684\u5185\u5b58\u5927\u5c0f\u3002\r\nused_memory_lua_human:37.00K\r\nmaxmemory:2147483648    \/\/ \u80fd\u4f7f\u7528\u7684\u6700\u5927\u5185\u5b58\u503c\uff0c\u5b57\u8282\u4e3a\u5355\u4f4d\u3002\r\nmaxmemory_human:2.00G  \/\/ \u53ef\u8bfb\u5f62\u5f0f\r\nmaxmemory_policy:noeviction \/\/ \u5185\u5b58\u6dd8\u6c70\u7b56\u7565\r\n\r\n\/\/ used_memory_rss \/ used_memory \u7684\u6bd4\u503c\uff0c\u4ee3\u8868\u5185\u5b58\u788e\u7247\u7387\r\nmem_fragmentation_ratio:2.79<\/pre>\n

Redis \u8fdb\u7a0b\u5185\u5b58\u6d88\u8017\u4e3b\u8981\u7531\u4ee5\u4e0b\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n

  • Redis \u81ea\u8eab\u542f\u52a8\u6240\u5360\u7528\u7684\u5185\u5b58\u3002<\/li>\n
  • \u5b58\u50a8\u5bf9\u8c61\u6570\u636e\u5185\u5b58\u3002<\/li>\n
  • \u7f13\u51b2\u533a\u5185\u5b58\uff1a\u4e3b\u8981\u7531 client-output-buffer-limit \u5ba2\u6237\u7aef\u8f93\u51fa\u7f13\u51b2\u533a\u3001\u590d\u5236\u79ef\u538b\u7f13\u51b2\u533a\u3001AOF \u7f13\u51b2\u533a\u3002
    \n\u5185\u5b58\u788e\u7247\u3002<\/li>\n

    \"\"<\/p>\n

    Redis \u81ea\u8eab\u7a7a\u8fdb\u7a0b\u5360\u7528\u7684\u5185\u5b58\u5f88\u5c0f\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\uff0c\u5bf9\u8c61\u5185\u5b58\u662f\u5360\u6bd4\u6700\u5927\u7684\u4e00\u5757\uff0c\u91cc\u9762\u5b58\u50a8\u7740\u6240\u6709\u7684\u6570\u636e\u3002<\/p>\n

    \u7f13\u51b2\u533a\u5185\u5b58\u5728\u5927\u6d41\u91cf\u573a\u666f\u5bb9\u6613\u5931\u63a7\uff0c\u9020\u6210 Redis \u5185\u5b58\u4e0d\u7a33\u5b9a\uff0c\u9700\u8981\u91cd\u70b9\u5173\u6ce8\u3002<\/p>\n

    \u5185\u5b58\u788e\u7247\u8fc7\u5927\u4f1a\u5bfc\u81f4\u660e\u660e\u6709\u7a7a\u95f4\u53ef\u7528\uff0c\u4f46\u662f\u5374\u65e0\u6cd5\u5b58\u50a8\u6570\u636e\u3002<\/p>\n

    \u788e\u7247 = used_memory_rss \u5b9e\u9645\u4f7f\u7528\u7684\u7269\u7406\u5185\u5b58\uff08RSS \u503c\uff09\u9664\u4ee5 used_memory \u5b9e\u9645\u5b58\u50a8\u6570\u636e\u5185\u5b58\u3002<\/p>\n

    \u4ec0\u4e48\u662f\u5185\u5b58\u788e\u7247<\/strong><\/div>\n

    \u5185\u5b58\u788e\u7247\u4f1a\u9020\u6210\u660e\u660e\u6709\u5185\u5b58\u7a7a\u95f4\u7a7a\u95f2\uff0c\u53ef\u662f\u5374\u65e0\u6cd5\u5b58\u50a8\u6570\u636e\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u4f60\u8ddf\u6f02\u4eae\u5c0f\u59d0\u59d0\u53bb\u7535\u5f71\u9662\u770b\u7535\u5f71\uff0c\u80af\u5b9a\u60f3\u8fde\u5728\u4e00\u5757\u3002<\/p>\n

    \u5047\u8bbe\u73b0\u5728\u6709 8 \u4e2a\u5ea7\u4f4d\uff0c\u5df2\u7ecf\u5356\u51fa\u4e86 4 \u5f20\u7968\uff0c\u8fd8\u6709 4 \u5f20\u53ef\u4ee5\u4e70\u3002\u53ef\u662f\u597d\u5de7\u4e0d\u5de7\uff0c\u4e70\u7968\u7684\u4eba\u5f88\u5947\u8469\uff0c\u5206\u522b\u95f4\u9694\u4e00\u4e2a\u5ea7\u4f4d\u4e70\u7968\u3002<\/p>\n

    \u5373\u4f7f\u8fd8\u6709 4 \u4e2a\u5ea7\u4f4d\u7a7a\u95f2\uff0c\u53ef\u662f\u4f60\u5374\u4e70\u4e0d\u5230\u4e24\u4e2a\u5ea7\u4f4d\u8fde\u5728\u4e00\u5757\u7684\u7968\uff0c\u539a\u793c\u87f9\uff01<\/p>\n

    \"\"<\/p>\n

    \u5185\u5b58\u788e\u7247\u5f62\u6210\u539f\u56e0<\/strong><\/div>\n

    \u5185\u5b58\u788e\u7247\u662f\u4ec0\u4e48\u539f\u56e0\u5bfc\u81f4\u5462\uff1f<\/p>\n

    \u4e3b\u8981\u6709\u4e24\u4e2a\u539f\u56e0\uff1a<\/p>\n

  • \u5185\u5b58\u5206\u914d\u5668\u7684\u5206\u914d\u7b56\u7565\u3002<\/li>\n
  • \u952e\u503c\u5bf9\u7684\u5927\u5c0f\u4e0d\u4e00\u6837\u548c\u5220\u6539\u64cd\u4f5c\uff1aRedis \u9891\u7e41\u505a\u66f4\u65b0\u64cd\u4f5c\u3001\u5927\u91cf\u8fc7\u671f\u6570\u636e\u5220\u9664\uff0c\u91ca\u653e\u7684\u7a7a\u95f4\uff08\u4e0d\u591f\u8fde\u7eed\uff09\u65e0\u6cd5\u5f97\u5230\u590d\u7528\uff0c\u5bfc\u81f4\u788e\u7247\u7387\u4e0a\u5347\u3002<\/li>\n

    \u63a5\u4e0b\u6765\u6211\u5206\u522b\u63a2\u8ba8\u5b9e\u9645\u53d1\u751f\u7684\u539f\u56e0\u2026\u2026<\/p>\n

    \u5185\u5b58\u5206\u914d\u5668\u7684\u5206\u914d\u7b56\u7565<\/strong><\/div>\n

    Redis \u9ed8\u8ba4\u7684\u5185\u5b58\u5206\u914d\u5668\u91c7\u7528 jemalloc\uff0c\u53ef\u9009\u7684\u5206\u914d\u5668\u8fd8\u6709\uff1aglibc\u3001tcmalloc\u3002<\/p>\n

    \u5185\u5b58\u5206\u914d\u5668\u5e76\u4e0d\u80fd\u505a\u5230\u6309\u9700\u5206\u914d\uff0c\u800c\u662f\u91c7\u7528\u56fa\u5b9a\u8303\u56f4\u7684\u5185\u5b58\u5757\u8fdb\u884c\u5206\u914d\u3002<\/p>\n

    \u4f8b\u5982 8 \u5b57\u8282\u300116 \u5b57\u8282\u2026..\uff0c2 KB\uff0c4KB\uff0c\u5f53\u7533\u8bf7\u5185\u5b58\u6700\u8fd1\u63a5\u67d0\u4e2a\u56fa\u5b9a\u503c\u7684\u65f6\u5019\uff0cjemalloc \u4f1a\u7ed9\u5b83\u5206\u914d\u6700\u63a5\u8fd1\u56fa\u5b9a\u503c\u5927\u5c0f\u7684\u7a7a\u95f4\u3002<\/p>\n

    \u8fd9\u6837\u5c31\u4f1a\u51fa\u73b0\u5185\u5b58\u788e\u7247\uff0c\u6bd4\u5982\u7a0b\u5e8f\u53ea\u9700\u8981 1.5 KB\uff0c\u5185\u5b58\u5206\u914d\u5668\u4f1a\u5206\u914d 2KB \u7a7a\u95f4\uff0c\u90a3\u4e48\u8fd9 0.5KB \u5c31\u662f\u788e\u7247\u3002<\/p>\n

    \u200b\u8fd9\u4e48\u505a\u7684\u76ee\u7684\u662f\u51cf\u5c11\u5185\u5b58\u5206\u914d\u6b21\u6570\uff0c\u6bd4\u5982\u7533\u8bf7 22 \u5b57\u8282\u7684\u7a7a\u95f4\u4fdd\u5b58\u6570\u636e\uff0cjemalloc \u5c31\u4f1a\u5206\u914d 32 \u5b57\u8282\uff0c\u5982\u679c\u540e\u8fb9\u8fd8\u8981\u5199\u5165 10 \u5b57\u8282\uff0c\u5c31\u4e0d\u9700\u8981\u518d\u5411\u64cd\u4f5c\u7cfb\u7edf\u7533\u8bf7\u7a7a\u95f4\u4e86\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e4b\u524d\u7533\u8bf7\u7684 32 \u5b57\u8282\u3002<\/p>\n

    \u5220\u9664 key \u7684\u65f6\u5019\uff0cRedis \u5e76\u4e0d\u4f1a\u7acb\u9a6c\u628a\u5185\u5b58\u5f52\u8fd8\u7ed9\u64cd\u4f5c\u7cfb\u7edf\uff0c\u51fa\u73b0\u8fd9\u4e2a\u60c5\u51b5\u662f\u56e0\u4e3a\u5e95\u5c42\u5185\u5b58\u5206\u914d\u5668\u7ba1\u7406\u5bfc\u81f4\uff0c\u6bd4\u5982\u5927\u591a\u6570\u5df2\u7ecf\u5220\u9664\u7684 key \u4f9d\u7136\u4e0e\u5176\u4ed6\u6709\u6548\u7684 key \u5206\u914d\u5728\u540c\u4e00\u4e2a\u5185\u5b58\u9875\u4e2d\u3002<\/p>\n

    \u53e6\u5916\uff0c\u5206\u914d\u5668\u4e3a\u4e86\u590d\u7528\u7a7a\u95f2\u7684\u5185\u5b58\u5757\uff0c\u539f\u6709 5GB \u7684\u6570\u636e\u4e2d\u5220\u9664\u4e86 2 GB \u540e\uff0c\u5f53\u518d\u6b21\u6dfb\u52a0\u6570\u636e\u5230\u5b9e\u4f8b\u4e2d\uff0cRedis \u7684 RSS \u4f1a\u4fdd\u6301\u7a33\u5b9a\uff0c\u4e0d\u4f1a\u589e\u957f\u592a\u591a\u3002<\/p>\n

    \u56e0\u4e3a\u5185\u5b58\u5206\u914d\u5668\u57fa\u672c\u4e0a\u590d\u7528\u4e86\u4e4b\u524d\u5220\u9664\u91ca\u653e\u51fa\u6765\u7684 2GB \u5185\u5b58\u3002\u200b<\/p>\n

    \u952e\u503c\u5bf9\u5927\u5c0f\u4e0d\u4e00\u6837\u548c\u5220\u6539\u64cd\u4f5c<\/strong><\/div>\n

    \u7531\u4e8e\u5185\u5b58\u5206\u914d\u5668\u662f\u6309\u7167\u56fa\u5b9a\u5927\u5c0f\u5206\u914d\u5185\u5b58\uff0c\u6240\u4ee5\u901a\u5e38\u5206\u914d\u7684\u5185\u5b58\u7a7a\u95f4\u6bd4\u5b9e\u9645\u6570\u636e\u5360\u7528\u7684\u5927\u5c0f\u591a\u4e00\u4e9b\uff0c\u4f1a\u9020\u6210\u788e\u7247\uff0c\u964d\u4f4e\u5185\u5b58\u7684\u5b58\u50a8\u6548\u7387\u3002<\/p>\n

    \u53e6\u5916\uff0c\u952e\u503c\u5bf9\u7684\u9891\u7e41\u4fee\u6539\u548c\u5220\u9664\uff0c\u5bfc\u81f4\u5185\u5b58\u7a7a\u95f4\u7684\u6269\u5bb9\u548c\u91ca\u653e\uff0c\u6bd4\u5982\u539f\u672c\u5360\u7528 32 \u5b57\u8282\u7684\u5b57\u7b26\u4e32\uff0c\u73b0\u5728\u4fee\u6539\u4e3a\u5360\u7528 20 \u5b57\u8282\u7684\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u91ca\u653e\u51fa\u7684 12 \u5b57\u8282\u5c31\u662f\u7a7a\u95f2\u7a7a\u95f4\u3002<\/p>\n

    \u5982\u679c\u4e0b\u4e00\u4e2a\u6570\u636e\u5b58\u50a8\u8bf7\u6c42\u9700\u8981\u7533\u8bf7 13 \u5b57\u8282\u7684\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u521a\u521a\u91ca\u653e\u7684 12 \u5b57\u8282\u7a7a\u95f4\u65e0\u6cd5\u4f7f\u7528\uff0c\u5bfc\u81f4\u788e\u7247\u3002<\/p>\n

    \u788e\u7247\u6700\u5927\u7684\u95ee\u9898\uff1a\u7a7a\u95f4\u603b\u91cf\u8db3\u591f\u5927\uff0c\u4f46\u662f\u8fd9\u4e9b\u5185\u5b58\u4e0d\u662f\u8fde\u7eed\u7684\uff0c\u53ef\u80fd\u5927\u81f4\u65e0\u6cd5\u5b58\u50a8\u6570\u636e\u3002<\/p>\n

    \u5185\u5b58\u788e\u7247\u89e3\u51b3\u4e4b\u9053<\/strong><\/div>\n

    \u90a3\u8be5\u5982\u4f55\u89e3\u51b3\u5462\uff1f<\/p>\n

    \u9996\u5148\u8981\u786e\u5b9a\u662f\u5426\u53d1\u751f\u4e86\u5185\u5b58\u788e\u7247\uff0c\u91cd\u70b9\u5173\u6ce8\u524d\u9762 INFO memory \u547d\u4ee4\u63d0\u793a\u7684 mem_fragmentation_ratio \u6307\u6807\uff0c\u8868\u793a\u5185\u5b58\u788e\u7247\u7387\uff1a<\/p>\n

    mem_fragmentation_ratio = used_memory_rss\/ used_memory<\/pre>\n

    \u5982\u679c 1 < \u788e\u7247\u7387 < 1.5\uff0c\u53ef\u4ee5\u8ba4\u4e3a\u662f\u5408\u7406\u7684\uff0c\u800c\u5927\u4e8e 1.5 \u8bf4\u660e\u788e\u7247\u5df2\u7ecf\u8d85\u8fc7 50%\uff0c\u6211\u4eec\u9700\u8981\u91c7\u53d6\u4e00\u4e9b\u624b\u6bb5\u89e3\u51b3\u788e\u7247\u7387\u8fc7\u5927\u7684\u95ee\u9898\u3002\n\n[yiji]\u91cd\u542f\u5927\u6cd5[\/yiji]\n\n\u6700\u7b80\u5355\u7c97\u66b4\u7684\u65b9\u5f0f\u5c31\u662f\u91cd\u542f\uff0c\u5982\u679c\u6ca1\u6709\u5f00\u542f\u6301\u4e45\u5316\uff0c\u6570\u636e\u4f1a\u4e22\u5931\u3002\n\n\u5f00\u542f\u6301\u4e45\u5316\u7684\u8bdd\uff0c\u9700\u8981\u4f7f\u7528 RDB \u6216\u8005 AOF \u6062\u590d\u6570\u636e\uff0c\u5982\u679c\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u6570\u636e\u5927\u7684\u8bdd\u4f1a\u5bfc\u81f4\u6062\u590d\u9636\u6bb5\u957f\u65f6\u95f4\u65e0\u6cd5\u63d0\u4f9b\u670d\u52a1\uff0c\u9ad8\u53ef\u7528\u5927\u6253\u6298\u6263\u3002\n\n\u548b\u529e\u5462\uff1f\u7801\u54e5\u9753\u4ed4\u3002\n\n[yiji]\u81ea\u52a8\u6e05\u7406\u5185\u5b58\u788e\u7247[\/yiji]\n\n\u65e2\u7136\u4f60\u90fd\u53eb\u6211\u9753\u4ed4\u4e86\uff0c\u5c31\u503e\u56ca\u76f8\u52a9\u544a\u8bc9\u4f60\u7ec8\u6781\u6740\u62db\uff1aRedis 4.0 \u7248\u672c\u540e\uff0c\u81ea\u8eab\u63d0\u4f9b\u4e86\u4e00\u79cd\u5185\u5b58\u788e\u7247\u6e05\u7406\u673a\u5236\u3002\n\n\u600e\u4e48\u6e05\u7406\u5462\uff1f\n\n\u5f88\u7b80\u5355\uff0c\u8fd8\u662f\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u60f3\u8981\u4e70\u4e24\u5f20\u8fde\u5728\u4e00\u5757\u7684\u7535\u5f71\u7968\u3002\u4e0e\u4e0e\u522b\u4eba\u6c9f\u901a\u8c03\u6362\u4e0b\u4f4d\u7f6e\uff0c\u5c31\u5b9e\u73b0\u4e86\u3002\n\n\u5bf9\u4e8e Redis \u6765\u8bf4\uff0c\u5f53\u4e00\u5757\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u88ab\u5212\u5206\u4e3a\u597d\u51e0\u5757\u4e0d\u8fde\u7eed\u7684\u7a7a\u95f4\u7684\u65f6\u5019\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5148\u628a\u6570\u636e\u4ee5\u4f9d\u6b21\u632a\u52a8\u62fc\u63a5\u5728\u4e00\u5757\uff0c\u5e76\u91ca\u653e\u539f\u6765\u6570\u636e\u5360\u636e\u7684\u7a7a\u95f4\uff0c\u5f62\u6210\u4e00\u5757\u8fde\u7eed\u7a7a\u95f2\u5185\u5b58\u7a7a\u95f4\u3002\u3002\n\n\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n\"\"<\/p>\n

    \u81ea\u52a8\u6e05\u7406\u5185\u5b58\u788e\u7247\u7684\u4ee3\u4ef7<\/strong><\/div>\n

    \u81ea\u52a8\u6e05\u7406\u867d\u597d\uff0c\u53ef\u4e0d\u8981\u8086\u610f\u5984\u4e3a\uff0c\u64cd\u4f5c\u7cfb\u7edf\u628a\u6570\u636e\u79fb\u52a8\u5230\u65b0\u4f4d\u7f6e\uff0c\u518d\u628a\u539f\u6709\u7a7a\u95f4\u91ca\u653e\u662f\u9700\u8981\u6d88\u8017\u8d44\u6e90\u7684\u3002<\/p>\n

    Redis \u64cd\u4f5c\u6570\u636e\u7684\u6307\u4ee4\u662f\u5355\u7ebf\u7a0b\uff0c\u6240\u4ee5\u5728\u6570\u636e\u590d\u5236\u79fb\u52a8\u7684\u65f6\u5019\uff0c\u53ea\u80fd\u7b49\u5f85\u6e05\u7406\u788e\u7247\u5b8c\u6210\u624d\u80fd\u5904\u7406\u8bf7\u6c42\uff0c\u9020\u6210\u6027\u80fd\u635f\u8017\u3002<\/p>\n

    \u5982\u4f55\u907f\u514d\u6e05\u7406\u788e\u7247\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u53c8\u80fd\u5b9e\u73b0\u81ea\u52a8\u6e05\u7406\u5462\uff1f<\/p>\n

    \u597d\u95ee\u9898\uff0c\u901a\u8fc7\u4ee5\u4e0b\u4e24\u4e2a\u53c2\u6570\u6765\u63a7\u5236\u5185\u5b58\u788e\u7247\u6e05\u7406\u548c\u7ed3\u675f\u65f6\u673a\uff0c\u907f\u514d\u5360\u7528 CPU \u8fc7\u591a\uff0c\u51cf\u5c11\u6e05\u7406\u788e\u7247\u5bf9 Redis \u5904\u7406\u8bf7\u6c42\u7684\u6027\u80fd\u5f71\u54cd\u3002<\/p>\n

    \u5f00\u542f\u81ea\u52a8\u5185\u5b58\u788e\u7247\u6e05\u7406<\/strong><\/div>\n
    CONFIG SET activedefrag yes<\/pre>\n

    \u8fd9\u53ea\u662f\u5f00\u542f\u81ea\u52a8\u6e05\u7406\uff0c\u4f55\u65f6\u6e05\u7406\u8981\u540c\u65f6\u6ee1\u8db3\u4ee5\u4e0b\u4e24\u4e2a\u6761\u4ef6\u624d\u4f1a\u89e6\u53d1\u6e05\u7406\u64cd\u4f5c\u3002<\/p>\n

    \u6e05\u7406\u7684\u6761\u4ef6<\/strong><\/div>\n

    active-defrag-ignore-bytes 200mb\uff1a\u5185\u5b58\u788e\u7247\u5360\u7528\u7684\u5185\u5b58\u8fbe\u5230 200MB\uff0c\u5f00\u59cb\u6e05\u7406\u3002<\/p>\n

    active-defrag-threshold-lower 20\uff1a\u5185\u5b58\u788e\u7247\u7684\u7a7a\u95f4\u5360\u6bd4\u8d85\u8fc7\u7cfb\u7edf\u5206\u914d\u7ed9 Redis \u7a7a\u95f4\u7684 20% \uff0c\u5f00\u59cb\u6e05\u7406\u3002<\/p>\n

    \u907f\u514d\u5bf9\u6027\u80fd\u9020\u6210\u5f71\u54cd<\/strong><\/div>\n

    \u6e05\u7406\u65f6\u95f4\u6709\u4e86\uff0c\u8fd8\u9700\u8981\u63a7\u5236\u6e05\u7406\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u3002\u7531\u4e00\u9879\u4e24\u4e2a\u8bbe\u7f6e\u5148\u5206\u914d\u6e05\u7406\u788e\u7247\u5360\u7528\u7684 CPU \u8d44\u6e90\uff0c\u4fdd\u8bc1\u65e2\u80fd\u6b63\u5e38\u6e05\u7406\u788e\u7247\uff0c\u53c8\u80fd\u907f\u514d\u5bf9 Redis \u5904\u7406\u8bf7\u6c42\u7684\u6027\u80fd\u5f71\u54cd\u3002<\/p>\n

    active-defrag-cycle-min 20\uff1a\u81ea\u52a8\u6e05\u7406\u8fc7\u7a0b\u4e2d\uff0c\u5360\u7528 CPU \u65f6\u95f4\u7684\u6bd4\u4f8b\u4e0d\u4f4e\u4e8e 20%\uff0c\u4ece\u800c\u4fdd\u8bc1\u80fd\u6b63\u5e38\u5c55\u5f00\u6e05\u7406\u4efb\u52a1\u3002<\/p>\n

    active-defrag-cycle-max 50\uff1a\u81ea\u52a8\u6e05\u7406\u8fc7\u7a0b\u5360\u7528\u7684 CPU \u65f6\u95f4\u6bd4\u4f8b\u4e0d\u80fd\u9ad8\u4e8e 75%\uff0c\u8d85\u8fc7\u7684\u8bdd\u5c31\u7acb\u523b\u505c\u6b62\u6e05\u7406\uff0c\u907f\u514d\u5bf9 Redis \u7684\u963b\u585e\uff0c\u9020\u6210\u9ad8\u5ef6\u8fdf\u3002<\/p>\n

    \u603b\u7ed3<\/strong><\/div>\n

    \u5982\u679c\u4f60\u53d1\u73b0\u660e\u660e Redis \u5b58\u50a8\u6570\u636e\u7684\u5185\u5b58\u5360\u7528\u8fdc\u5c0f\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u7ed9 Redis \u7684\u5185\u5b58\uff0c\u800c\u53c8\u65e0\u6cd5\u4fdd\u5b58\u6570\u636e\uff0c\u90a3\u53ef\u80fd\u51fa\u73b0\u5927\u91cf\u5185\u5b58\u788e\u7247\u4e86\u3002<\/p>\n

    \u901a\u8fc7 info memory \u547d\u4ee4\uff0c\u770b\u4e0b\u5185\u5b58\u788e\u7247mem_fragmentation_ratio \u6307\u6807\u662f\u5426\u6b63\u5e38\u3002<\/p>\n

    \u90a3\u4e48\u6211\u4eec\u5c31\u5f00\u542f\u81ea\u52a8\u6e05\u7406\u5e76\u5408\u7406\u8bbe\u7f6e\u6e05\u7406\u65f6\u673a\u548c CPU \u8d44\u6e90\u5360\u7528\uff0c\u8be5\u673a\u5236\u6d89\u53ca\u5230\u5185\u5b58\u62f7\u8d1d\uff0c\u4f1a\u5bf9 Redis \u6027\u80fd\u9020\u6210\u6f5c\u5728\u98ce\u9669\u3002<\/p>\n

    \u5982\u679c\u9047\u5230 Redis \u6027\u80fd\u53d8\u6162\uff0c\u6392\u67e5\u4e0b\u662f\u5426\u7531\u4e8e\u6e05\u7406\u788e\u7247\u5bfc\u81f4\uff0c\u5982\u679c\u662f\uff0c\u90a3\u5c31\u8c03\u5c0f active-defrag-cycle-max \u7684\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u7ed9 Redis \u7684\u5185\u5b58\u6709 6GB\uff0c\u901a\u8fc7\u6307\u6807 used_memory_human \u53d1\u73b0\u5b58\u50a8\u6570\u636e\u53ea\u4f7f\u7528 […]<\/p>\n","protected":false},"author":1920,"featured_media":202522,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-252398","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/252398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1920"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=252398"}],"version-history":[{"count":2,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/252398\/revisions"}],"predecessor-version":[{"id":252405,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/252398\/revisions\/252405"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/202522"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=252398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=252398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=252398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}