{"id":1083,"date":"2010-03-16T09:22:00","date_gmt":"2010-03-16T01:22:00","guid":{"rendered":"\/?p=1083"},"modified":"2010-03-16T09:22:00","modified_gmt":"2010-03-16T09:22:00","slug":"1083","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/architecture\/1083.html","title":{"rendered":"\u4e00\u81f4\u6027 hash \u7b97\u6cd5\uff08 consistent hashing \uff09"},"content":{"rendered":"

     consistent hashing \u7b97\u6cd5\u65e9\u5728 1997 \u5e74\u5c31\u5728\u8bba\u6587 Consistent hashing and random trees<\/font><\/a> <\/strong>\u4e2d\u88ab\u63d0\u51fa\uff0c\u76ee\u524d\u5728 cache \u7cfb\u7edf\u4e2d\u5e94\u7528\u8d8a\u6765\u8d8a\u5e7f\u6cdb\uff1b<\/p>\n

1 \u57fa\u672c\u573a\u666f<\/h4>\n

\u6bd4\u5982\u4f60\u6709 N \u4e2a cache \u670d\u52a1\u5668\uff08\u540e\u9762\u7b80\u79f0 cache \uff09\uff0c\u90a3\u4e48\u5982\u4f55\u5c06\u4e00\u4e2a\u5bf9\u8c61 object \u6620\u5c04\u5230 N \u4e2a cache \u4e0a\u5462\uff0c\u4f60\u5f88\u53ef\u80fd\u4f1a\u91c7\u7528\u7c7b\u4f3c\u4e0b\u9762\u7684\u901a\u7528\u65b9\u6cd5\u8ba1\u7b97 object \u7684 hash \u503c\uff0c\u7136\u540e\u5747\u5300\u7684\u6620\u5c04\u5230\u5230 N \u4e2a cache \uff1b<\/p>\n

hash(object)%N<\/p>\n

\u4e00\u5207\u90fd\u8fd0\u884c\u6b63\u5e38\uff0c\u518d\u8003\u8651\u5982\u4e0b\u7684\u4e24\u79cd\u60c5\u51b5\uff1b<\/p>\n

1 \u4e00\u4e2a cache \u670d\u52a1\u5668 m down \u6389\u4e86\uff08\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5fc5\u987b\u8981\u8003\u8651\u8fd9\u79cd\u60c5\u51b5\uff09\uff0c\u8fd9\u6837\u6240\u6709\u6620\u5c04\u5230 cache m \u7684\u5bf9\u8c61\u90fd\u4f1a\u5931\u6548\uff0c\u600e\u4e48\u529e\uff0c\u9700\u8981\u628a cache m \u4ece cache \u4e2d\u79fb\u9664\uff0c\u8fd9\u65f6\u5019 cache \u662f N-1 \u53f0\uff0c\u6620\u5c04\u516c\u5f0f\u53d8\u6210\u4e86 hash(object)%(N-1) \uff1b<\/p>\n

2 \u7531\u4e8e\u8bbf\u95ee\u52a0\u91cd\uff0c\u9700\u8981\u6dfb\u52a0 cache \uff0c\u8fd9\u65f6\u5019 cache \u662f N+1 \u53f0\uff0c\u6620\u5c04\u516c\u5f0f\u53d8\u6210\u4e86 hash(object)%(N+1) \uff1b<\/p>\n

1 \u548c 2 \u610f\u5473\u7740\u4ec0\u4e48\uff1f\u8fd9\u610f\u5473\u7740\u7a81\u7136\u4e4b\u95f4\u51e0\u4e4e\u6240\u6709\u7684 cache \u90fd\u5931\u6548\u4e86\u3002\u5bf9\u4e8e\u670d\u52a1\u5668\u800c\u8a00\uff0c\u8fd9\u662f\u4e00\u573a\u707e\u96be\uff0c\u6d2a\u6c34\u822c\u7684\u8bbf\u95ee\u90fd\u4f1a\u76f4\u63a5\u51b2\u5411\u540e\u53f0\u670d\u52a1\u5668\uff1b<\/p>\n

\u518d\u6765\u8003\u8651\u7b2c\u4e09\u4e2a\u95ee\u9898\uff0c\u7531\u4e8e\u786c\u4ef6\u80fd\u529b\u8d8a\u6765\u8d8a\u5f3a\uff0c\u4f60\u53ef\u80fd\u60f3\u8ba9\u540e\u9762\u6dfb\u52a0\u7684\u8282\u70b9\u591a\u505a\u70b9\u6d3b\uff0c\u663e\u7136\u4e0a\u9762\u7684 hash \u7b97\u6cd5\u4e5f\u505a\u4e0d\u5230\u3002<\/p>\n

\u6709\u4ec0\u4e48\u65b9\u6cd5\u53ef\u4ee5\u6539\u53d8\u8fd9\u4e2a\u72b6\u51b5\u5462\uff0c\u8fd9\u5c31\u662f consistent hashing\u2026<\/p>\n

2 hash \u7b97\u6cd5\u548c\u5355\u8c03\u6027<\/h4>\n

Hash \u7b97\u6cd5\u7684\u4e00\u4e2a\u8861\u91cf\u6307\u6807\u662f\u5355\u8c03\u6027\uff08 Monotonicity \uff09\uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n

\u5355\u8c03\u6027\u662f\u6307\u5982\u679c\u5df2\u7ecf\u6709\u4e00\u4e9b\u5185\u5bb9\u901a\u8fc7\u54c8\u5e0c\u5206\u6d3e\u5230\u4e86\u76f8\u5e94\u7684\u7f13\u51b2\u4e2d\uff0c\u53c8\u6709\u65b0\u7684\u7f13\u51b2\u52a0\u5165\u5230\u7cfb\u7edf\u4e2d\u3002\u54c8\u5e0c\u7684\u7ed3\u679c\u5e94\u80fd\u591f\u4fdd\u8bc1\u539f\u6709\u5df2\u5206\u914d\u7684\u5185\u5bb9\u53ef\u4ee5\u88ab\u6620\u5c04\u5230\u65b0\u7684\u7f13\u51b2\u4e2d\u53bb\uff0c\u800c\u4e0d\u4f1a\u88ab\u6620\u5c04\u5230\u65e7\u7684\u7f13\u51b2\u96c6\u5408\u4e2d\u7684\u5176\u4ed6\u7f13\u51b2\u533a\u3002<\/p>\n

\u5bb9\u6613\u770b\u5230\uff0c\u4e0a\u9762\u7684\u7b80\u5355 hash \u7b97\u6cd5 hash(object)%N \u96be\u4ee5\u6ee1\u8db3\u5355\u8c03\u6027\u8981\u6c42\u3002<\/p>\n

3 consistent hashing \u7b97\u6cd5\u7684\u539f\u7406<\/h4>\n

consistent hashing \u662f\u4e00\u79cd hash \u7b97\u6cd5\uff0c\u7b80\u5355\u7684\u8bf4\uff0c\u5728\u79fb\u9664 \/ \u6dfb\u52a0\u4e00\u4e2a cache \u65f6\uff0c\u5b83\u80fd\u591f\u5c3d\u53ef\u80fd\u5c0f\u7684\u6539\u53d8\u5df2\u5b58\u5728 key \u6620\u5c04\u5173\u7cfb\uff0c\u5c3d\u53ef\u80fd\u7684\u6ee1\u8db3\u5355\u8c03\u6027\u7684\u8981\u6c42\u3002<\/p>\n

\u4e0b\u9762\u5c31\u6765\u6309\u7167 5 \u4e2a\u6b65\u9aa4\u7b80\u5355\u8bb2\u8bb2 consistent hashing \u7b97\u6cd5\u7684\u57fa\u672c\u539f\u7406\u3002<\/p>\n

3.1 \u73af\u5f62hash \u7a7a\u95f4<\/h5>\n

\u8003\u8651\u901a\u5e38\u7684 hash \u7b97\u6cd5\u90fd\u662f\u5c06 value \u6620\u5c04\u5230\u4e00\u4e2a 32 \u4e3a\u7684 key \u503c\uff0c\u4e5f\u5373\u662f 0~2^32-1 \u6b21\u65b9\u7684\u6570\u503c\u7a7a\u95f4\uff1b\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u7a7a\u95f4\u60f3\u8c61\u6210\u4e00\u4e2a\u9996\uff08 0\uff09\u5c3e\uff08 2^32-1 \uff09\u76f8\u63a5\u7684\u5706\u73af\uff0c\u5982\u4e0b\u9762\u56fe 1 \u6240\u793a\u7684\u90a3\u6837\u3002<\/p>\n

\"circle<\/p>\n

\u56fe 1 \u73af\u5f62 hash \u7a7a\u95f4<\/p>\n

3.2 \u628a\u5bf9\u8c61\u6620\u5c04\u5230hash \u7a7a\u95f4<\/h5>\n

\u63a5\u4e0b\u6765\u8003\u8651 4 \u4e2a\u5bf9\u8c61 object1~object4 \uff0c\u901a\u8fc7 hash \u51fd\u6570\u8ba1\u7b97\u51fa\u7684 hash \u503c key \u5728\u73af\u4e0a\u7684\u5206\u5e03\u5982\u56fe 2 \u6240\u793a\u3002<\/p>\n

hash(object1) = key1;<\/p>\n

\u2026 \u2026<\/p>\n

hash(object4) = key4;<\/p>\n

\"object\"<\/p>\n

\u56fe 2 4 \u4e2a\u5bf9\u8c61\u7684 key \u503c\u5206\u5e03<\/p>\n

3.3 \u628acache \u6620\u5c04\u5230hash \u7a7a\u95f4<\/h5>\n

Consistent hashing \u7684\u57fa\u672c\u601d\u60f3\u5c31\u662f\u5c06\u5bf9\u8c61\u548c cache \u90fd\u6620\u5c04\u5230\u540c\u4e00\u4e2a hash \u6570\u503c\u7a7a\u95f4\u4e2d\uff0c\u5e76\u4e14\u4f7f\u7528\u76f8\u540c\u7684 hash \u7b97\u6cd5\u3002<\/p>\n

\u5047\u8bbe\u5f53\u524d\u6709 A,B \u548c C \u5171 3 \u53f0 cache \uff0c\u90a3\u4e48\u5176\u6620\u5c04\u7ed3\u679c\u5c06\u5982\u56fe 3 \u6240\u793a\uff0c\u4ed6\u4eec\u5728 hash \u7a7a\u95f4\u4e2d\uff0c\u4ee5\u5bf9\u5e94\u7684 hash \u503c\u6392\u5217\u3002<\/p>\n

hash(cache A) = key A;<\/p>\n

\u2026 \u2026<\/p>\n

hash(cache C) = key C;<\/p>\n

\"cache\"<\/p>\n

\u56fe 3 cache \u548c\u5bf9\u8c61\u7684 key \u503c\u5206\u5e03<\/p>\n

\u8bf4\u5230\u8fd9\u91cc\uff0c\u987a\u4fbf\u63d0\u4e00\u4e0b cache \u7684 hash \u8ba1\u7b97\uff0c\u4e00\u822c\u7684\u65b9\u6cd5\u53ef\u4ee5\u4f7f\u7528 cache \u673a\u5668\u7684 IP \u5730\u5740\u6216\u8005\u673a\u5668\u540d\u4f5c\u4e3a hash \u8f93\u5165\u3002<\/p>\n

3.4 \u628a\u5bf9\u8c61\u6620\u5c04\u5230cache<\/h5>\n

\u73b0\u5728 cache \u548c\u5bf9\u8c61\u90fd\u5df2\u7ecf\u901a\u8fc7\u540c\u4e00\u4e2a hash \u7b97\u6cd5\u6620\u5c04\u5230 hash \u6570\u503c\u7a7a\u95f4\u4e2d\u4e86\uff0c\u63a5\u4e0b\u6765\u8981\u8003\u8651\u7684\u5c31\u662f\u5982\u4f55\u5c06\u5bf9\u8c61\u6620\u5c04\u5230 cache \u4e0a\u9762\u4e86\u3002<\/p>\n

\u5728\u8fd9\u4e2a\u73af\u5f62\u7a7a\u95f4\u4e2d\uff0c\u5982\u679c\u6cbf\u7740\u987a\u65f6\u9488\u65b9\u5411\u4ece\u5bf9\u8c61\u7684 key \u503c\u51fa\u53d1\uff0c\u76f4\u5230\u9047\u89c1\u4e00\u4e2a cache \uff0c\u90a3\u4e48\u5c31\u5c06\u8be5\u5bf9\u8c61\u5b58\u50a8\u5728\u8fd9\u4e2a cache \u4e0a\uff0c\u56e0\u4e3a\u5bf9\u8c61\u548c cache \u7684 hash \u503c\u662f\u56fa\u5b9a\u7684\uff0c\u56e0\u6b64\u8fd9\u4e2a cache \u5fc5\u7136\u662f\u552f\u4e00\u548c\u786e\u5b9a\u7684\u3002\u8fd9\u6837\u4e0d\u5c31\u627e\u5230\u4e86\u5bf9\u8c61\u548c cache \u7684\u6620\u5c04\u65b9\u6cd5\u4e86\u5417\uff1f\uff01<\/p>\n

\u4f9d\u7136\u7ee7\u7eed\u4e0a\u9762\u7684\u4f8b\u5b50\uff08\u53c2\u89c1\u56fe 3 \uff09\uff0c\u90a3\u4e48\u6839\u636e\u4e0a\u9762\u7684\u65b9\u6cd5\uff0c\u5bf9\u8c61 object1 \u5c06\u88ab\u5b58\u50a8\u5230 cache A \u4e0a\uff1b object2 \u548c object3 \u5bf9\u5e94\u5230 cache C \uff1b object4 \u5bf9\u5e94\u5230 cache B \uff1b<\/p>\n

3.5 \u8003\u5bdfcache \u7684\u53d8\u52a8<\/h5>\n

\u524d\u9762\u8bb2\u8fc7\uff0c\u901a\u8fc7 hash \u7136\u540e\u6c42\u4f59\u7684\u65b9\u6cd5\u5e26\u6765\u7684\u6700\u5927\u95ee\u9898\u5c31\u5728\u4e8e\u4e0d\u80fd\u6ee1\u8db3\u5355\u8c03\u6027\uff0c\u5f53 cache \u6709\u6240\u53d8\u52a8\u65f6\uff0c cache \u4f1a\u5931\u6548\uff0c\u8fdb\u800c\u5bf9\u540e\u53f0\u670d\u52a1\u5668\u9020\u6210\u5de8\u5927\u7684\u51b2\u51fb\uff0c\u73b0\u5728\u5c31\u6765\u5206\u6790\u5206\u6790 consistent hashing \u7b97\u6cd5\u3002<\/p>\n

3.5.1 <\/strong>\u79fb\u9664 cache<\/strong><\/p>\n

\u8003\u8651\u5047\u8bbe cache B \u6302\u6389\u4e86\uff0c\u6839\u636e\u4e0a\u9762\u8bb2\u5230\u7684\u6620\u5c04\u65b9\u6cd5\uff0c\u8fd9\u65f6\u53d7\u5f71\u54cd\u7684\u5c06\u4ec5\u662f\u90a3\u4e9b\u6cbf cache B \u9006\u65f6\u9488\u904d\u5386\u76f4\u5230\u4e0b\u4e00\u4e2a cache \uff08 cache C \uff09\u4e4b\u95f4\u7684\u5bf9\u8c61\uff0c\u4e5f\u5373\u662f\u672c\u6765\u6620\u5c04\u5230 cache B \u4e0a\u7684\u90a3\u4e9b\u5bf9\u8c61\u3002<\/p>\n

\u56e0\u6b64\u8fd9\u91cc\u4ec5\u9700\u8981\u53d8\u52a8\u5bf9\u8c61 object4 \uff0c\u5c06\u5176\u91cd\u65b0\u6620\u5c04\u5230 cache C \u4e0a\u5373\u53ef\uff1b\u53c2\u89c1\u56fe 4 \u3002<\/p>\n

\"remove\"<\/p>\n

\u56fe 4 Cache B \u88ab\u79fb\u9664\u540e\u7684 cache \u6620\u5c04<\/p>\n

3.5.2 <\/strong>\u6dfb\u52a0 cache<\/strong><\/p>\n

\u518d\u8003\u8651\u6dfb\u52a0\u4e00\u53f0\u65b0\u7684 cache D \u7684\u60c5\u51b5\uff0c\u5047\u8bbe\u5728\u8fd9\u4e2a\u73af\u5f62 hash \u7a7a\u95f4\u4e2d\uff0c cache D \u88ab\u6620\u5c04\u5728\u5bf9\u8c61 object2 \u548c object3 \u4e4b\u95f4\u3002\u8fd9\u65f6\u53d7\u5f71\u54cd\u7684\u5c06\u4ec5\u662f\u90a3\u4e9b\u6cbf cache D \u9006\u65f6\u9488\u904d\u5386\u76f4\u5230\u4e0b\u4e00\u4e2a cache \uff08 cache B \uff09\u4e4b\u95f4\u7684\u5bf9\u8c61\uff08\u5b83\u4eec\u662f\u4e5f\u672c\u6765\u6620\u5c04\u5230 cache C \u4e0a\u5bf9\u8c61\u7684\u4e00\u90e8\u5206\uff09\uff0c\u5c06\u8fd9\u4e9b\u5bf9\u8c61\u91cd\u65b0\u6620\u5c04\u5230 cache D \u4e0a\u5373\u53ef\u3002<\/p>\n

\u56e0\u6b64\u8fd9\u91cc\u4ec5\u9700\u8981\u53d8\u52a8\u5bf9\u8c61 object2 \uff0c\u5c06\u5176\u91cd\u65b0\u6620\u5c04\u5230 cache D \u4e0a\uff1b\u53c2\u89c1\u56fe 5 \u3002<\/p>\n

\"add\"<\/p>\n

\u56fe 5 \u6dfb\u52a0 cache D \u540e\u7684\u6620\u5c04\u5173\u7cfb<\/p>\n

4 \u865a\u62df\u8282\u70b9<\/h4>\n

\u8003\u91cf Hash \u7b97\u6cd5\u7684\u53e6\u4e00\u4e2a\u6307\u6807\u662f\u5e73\u8861\u6027 (Balance) \uff0c\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n

\u5e73\u8861\u6027<\/p>\n

\u5e73\u8861\u6027\u662f\u6307\u54c8\u5e0c\u7684\u7ed3\u679c\u80fd\u591f\u5c3d\u53ef\u80fd\u5206\u5e03\u5230\u6240\u6709\u7684\u7f13\u51b2\u4e2d\u53bb\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u5f97\u6240\u6709\u7684\u7f13\u51b2\u7a7a\u95f4\u90fd\u5f97\u5230\u5229\u7528\u3002<\/p>\n

hash \u7b97\u6cd5\u5e76\u4e0d\u662f\u4fdd\u8bc1\u7edd\u5bf9\u7684\u5e73\u8861\uff0c\u5982\u679c cache \u8f83\u5c11\u7684\u8bdd\uff0c\u5bf9\u8c61\u5e76\u4e0d\u80fd\u88ab\u5747\u5300\u7684\u6620\u5c04\u5230 cache \u4e0a\uff0c\u6bd4\u5982\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u4ec5\u90e8\u7f72 cache A \u548c cache C \u7684\u60c5\u51b5\u4e0b\uff0c\u5728 4 \u4e2a\u5bf9\u8c61\u4e2d\uff0c cache A \u4ec5\u5b58\u50a8\u4e86 object1 \uff0c\u800c cache C \u5219\u5b58\u50a8\u4e86 object2 \u3001 object3 \u548c object4 \uff1b\u5206\u5e03\u662f\u5f88\u4e0d\u5747\u8861\u7684\u3002<\/p>\n

\u4e3a\u4e86\u89e3\u51b3\u8fd9\u79cd\u60c5\u51b5\uff0c consistent hashing \u5f15\u5165\u4e86“\u865a\u62df\u8282\u70b9”\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u5982\u4e0b\u5b9a\u4e49\uff1a<\/p>\n

“\u865a\u62df\u8282\u70b9”\uff08 virtual node \uff09\u662f\u5b9e\u9645\u8282\u70b9\u5728 hash \u7a7a\u95f4\u7684\u590d\u5236\u54c1\uff08 replica \uff09\uff0c\u4e00\u5b9e\u9645\u4e2a\u8282\u70b9\u5bf9\u5e94\u4e86\u82e5\u5e72\u4e2a“\u865a\u62df\u8282\u70b9”\uff0c\u8fd9\u4e2a\u5bf9\u5e94\u4e2a\u6570\u4e5f\u6210\u4e3a“\u590d\u5236\u4e2a\u6570”\uff0c“\u865a\u62df\u8282\u70b9”\u5728 hash \u7a7a\u95f4\u4e2d\u4ee5 hash \u503c\u6392\u5217\u3002<\/p>\n

\u4ecd\u4ee5\u4ec5\u90e8\u7f72 cache A \u548c cache C \u7684\u60c5\u51b5\u4e3a\u4f8b\uff0c\u5728\u56fe 4 \u4e2d\u6211\u4eec\u5df2\u7ecf\u770b\u5230\uff0c cache \u5206\u5e03\u5e76\u4e0d\u5747\u5300\u3002\u73b0\u5728\u6211\u4eec\u5f15\u5165\u865a\u62df\u8282\u70b9\uff0c\u5e76\u8bbe\u7f6e“\u590d\u5236\u4e2a\u6570”\u4e3a2 \uff0c\u8fd9\u5c31\u610f\u5473\u7740\u4e00\u5171\u4f1a\u5b58\u5728 4 \u4e2a“\u865a\u62df\u8282\u70b9”\uff0c cache A1, cache A2 \u4ee3\u8868\u4e86 cache A \uff1b cache C1, cache C2 \u4ee3\u8868\u4e86 cache C \uff1b\u5047\u8bbe\u4e00\u79cd\u6bd4\u8f83\u7406\u60f3\u7684\u60c5\u51b5\uff0c\u53c2\u89c1\u56fe 6 \u3002<\/p>\n

\"virtual<\/p>\n

\u56fe 6 \u5f15\u5165“\u865a\u62df\u8282\u70b9”\u540e\u7684\u6620\u5c04\u5173\u7cfb<\/p>\n

\u6b64\u65f6\uff0c\u5bf9\u8c61\u5230“\u865a\u62df\u8282\u70b9”\u7684\u6620\u5c04\u5173\u7cfb\u4e3a\uff1a<\/p>\n

objec1->cache A2 \uff1b objec2->cache A1 \uff1b objec3->cache C1 \uff1b objec4->cache C2 \uff1b<\/p>\n

\u56e0\u6b64\u5bf9\u8c61 object1 \u548c object2 \u90fd\u88ab\u6620\u5c04\u5230\u4e86 cache A \u4e0a\uff0c\u800c object3 \u548c object4 \u6620\u5c04\u5230\u4e86 cache C \u4e0a\uff1b\u5e73\u8861\u6027\u6709\u4e86\u5f88\u5927\u63d0\u9ad8\u3002<\/p>\n

\u5f15\u5165“\u865a\u62df\u8282\u70b9”\u540e\uff0c\u6620\u5c04\u5173\u7cfb\u5c31\u4ece { \u5bf9\u8c61 -> \u8282\u70b9 } \u8f6c\u6362\u5230\u4e86 { \u5bf9\u8c61 -> \u865a\u62df\u8282\u70b9 } \u3002\u67e5\u8be2\u7269\u4f53\u6240\u5728 cache \u65f6\u7684\u6620\u5c04\u5173\u7cfb\u5982\u56fe 7 \u6240\u793a\u3002<\/p>\n

\"map\"<\/p>\n

\u56fe 7 \u67e5\u8be2\u5bf9\u8c61\u6240\u5728 cache<\/p>\n

“\u865a\u62df\u8282\u70b9”\u7684 hash \u8ba1\u7b97\u53ef\u4ee5\u91c7\u7528\u5bf9\u5e94\u8282\u70b9\u7684 IP \u5730\u5740\u52a0\u6570\u5b57\u540e\u7f00\u7684\u65b9\u5f0f\u3002\u4f8b\u5982\u5047\u8bbe cache A \u7684 IP \u5730\u5740\u4e3a 202.168.14.241 \u3002<\/p>\n

\u5f15\u5165“\u865a\u62df\u8282\u70b9”\u524d\uff0c\u8ba1\u7b97 cache A \u7684 hash \u503c\uff1a<\/p>\n

Hash(“202.168.14.241”);<\/p>\n

\u5f15\u5165“\u865a\u62df\u8282\u70b9”\u540e\uff0c\u8ba1\u7b97“\u865a\u62df\u8282”\u70b9 cache A1 \u548c cache A2 \u7684 hash \u503c\uff1a<\/p>\n

Hash(“202.168.14.241#1”); \/\/ cache A1<\/p>\n

Hash(“202.168.14.241#2”); \/\/ cache A2<\/p>\n

5 \u5c0f\u7ed3<\/h4>\n

Consistent hashing \u7684\u57fa\u672c\u539f\u7406\u5c31\u662f\u8fd9\u4e9b\uff0c\u5177\u4f53\u7684\u5206\u5e03\u6027\u7b49\u7406\u8bba\u5206\u6790\u5e94\u8be5\u662f\u5f88\u590d\u6742\u7684\uff0c\u4e0d\u8fc7\u4e00\u822c\u4e5f\u7528\u4e0d\u5230\u3002<\/p>\n

http:\/\/weblogs.java.net\/blog\/2007\/11\/27\/consistent-hashing<\/font><\/a> \u4e0a\u9762\u6709\u4e00\u4e2a java \u7248\u672c\u7684\u4f8b\u5b50\uff0c\u53ef\u4ee5\u53c2\u8003\u3002<\/p>\n

http:\/\/blog.csdn.net\/mayongzhan\/archive\/2009\/06\/25\/4298834.aspx<\/font><\/a> \u8f6c\u8f7d\u4e86\u4e00\u4e2a PHP \u7248\u7684\u5b9e\u73b0\u4ee3\u7801\u3002<\/p>\n

http:\/\/www.codeproject.com\/KB\/recipes\/lib-conhash.aspx<\/font><\/a> C\u8bed\u8a00\u7248\u672c<\/p>\n

\u4e00\u4e9b\u53c2\u8003\u8d44\u6599\u5730\u5740\uff1a<\/p>\n

http:\/\/portal.acm.org\/citation.cfm?id=258660<\/font><\/a><\/p>\n

http:\/\/en.wikipedia.org\/wiki\/Consistent_hashing<\/font><\/a><\/p>\n

http:\/\/www.spiteful.com\/2008\/03\/17\/programmers-toolbox-part-3-consistent-hashing\/<\/font><\/a><\/p>\n

http:\/\/weblogs.java.net\/blog\/2007\/11\/27\/consistent-hashing<\/font><\/a><\/p>\n

http:\/\/tech.idv2.com\/2008\/07\/24\/memcached-004\/<\/font><\/a><\/p>\n

http:\/\/blog.csdn.net\/mayongzhan\/archive\/2009\/06\/25\/4298834.aspx<\/font><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

     consistent hashing \u7b97\u6cd5\u65e9\u5728 1997 \u5e74\u5c31\u5728\u8bba\u6587 Consistent hashing and random trees<\/font><\/a> <\/strong>\u4e2d\u88ab\u63d0\u51fa\uff0c\u76ee\u524d\u5728 cache \u7cfb\u7edf\u4e2d\u5e94\u7528\u8d8a\u6765\u8d8a\u5e7f\u6cdb\uff1b<\/p>\n

1 \u57fa\u672c\u573a\u666f<\/h4>\n

\u6bd4\u5982\u4f60\u6709 N \u4e2a cache \u670d\u52a1\u5668\uff08\u540e\u9762\u7b80\u79f0 cache \uff09\uff0c\u90a3\u4e48\u5982\u4f55\u5c06\u4e00\u4e2a\u5bf9\u8c61 object \u6620\u5c04\u5230 N \u4e2a cache \u4e0a\u5462\uff0c\u4f60\u5f88\u53ef\u80fd\u4f1a\u91c7\u7528\u7c7b\u4f3c\u4e0b\u9762\u7684\u901a\u7528\u65b9\u6cd5\u8ba1\u7b97 object \u7684 hash \u503c\uff0c\u7136\u540e\u5747\u5300\u7684\u6620\u5c04\u5230\u5230 N \u4e2a cache \uff1b<\/p>\n

hash(obj<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1083"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1083"}],"version-history":[{"count":0,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1083\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}