{"id":228,"date":"2010-04-01T01:16:06","date_gmt":"2010-04-01T01:16:06","guid":{"rendered":"http:\/\/www.houquner.com\/?p=856"},"modified":"2010-04-01T01:16:06","modified_gmt":"2010-04-01T01:16:06","slug":"lvs%e7%9a%84hash-sizezz","status":"publish","type":"post","link":"https:\/\/www.houquner.com\/index.php\/archives\/228","title":{"rendered":"LVS\u7684hash size(zz)"},"content":{"rendered":"<p>LVS(Director)\u7684\u8fde\u63a5\u8ddf\u8e2a\u8868(\u4e5f\u79f0Hash\u8868),\u4fdd\u5b58\u4e86\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u6bcf\u4e2a\u65b0\u5efa\u8fde\u63a5\u3002\u8fd9\u4e48\u505a\u7684\u4e3b\u8981\u76ee\u7684\u662f\u4e3a\u4e86\u4fdd\u5b58\u8db3\u591f\u7684\u4fe1\u606f\uff0c\u4f7f\u5f97\u6765\u81ea\u540c\u4e00\u4e2a\u5ba2\u6237\u7aef\u7684\u540e\u7eed\u7684\u6570\u636e\u62a5\u80fd\u901a\u8fc7\u540c\u4e00\u4e2a\u7f51\u7edc\u8fde\u63a5\u53d1\u9001\u5230\u76f8\u540c\u7684\u771f\u5b9e\u670d\u52a1\u5668\u4e0a(RealServer).\u6bcf\u4e2a\u8fde\u63a5\u7684\u4fe1\u606f\u5305\u62ecCIP\uff0cVIP\uff0c\u76ee\u6807IP\uff0ccport(clientPort),dport\uff0c\u534f\u8bae\u7c7b\u578b\u7b49\uff0c\u8fd8\u5305\u62eclvs\u7684\u4e00\u4e9b\u5176\u4ed6\u4fe1\u606f\uff0c\u6bd4\u5982\u5b9a\u65f6\u5668\u3001\u8fde\u63a5\u72b6\u6001\u6807\u8bb0\u3001\u9501\u7b49\u7b49\u3002\u8fd9\u4e9b\u90fd\u5728include\/net\/ip_vs.h\u7684struct ip_vs_conn\u91cc\u9762\u5b9a\u4e49.<br \/>\n\u8fd9\u4e2a\u7ed3\u6784\u7684\u5927\u5c0f\u662f128+8=136\u5b57\u8282\u3002\u6bcf\u6761\u8bb0\u5f55\u7528\u4e00\u4e2aip_vs_conn\u7ed3\u6784\u8868\u793a\uff0c\u8fd9\u4e2a\u7ed3\u6784\u4f7f\u7528\u4e86Linux\u91cc\u9762\u7684\u5178\u578b\u6570\u636e\u7ed3\u6784struct list_head\u6784\u9020\u53cc\u5411\u94fe\u8868\uff0c\u4f7f\u5f97\u6240\u6709\u7684\u8bb0\u5f55\u4ee5\u94fe\u8868\u5f62\u5f0f\u94fe\u63a5\u8d77\u6765\u3002<\/p>\n<ul>\n<li>struct list_head \u7684\u5927\u5c0f\u4e3a8\u4e2a\u5b57\u8282(\u4e24\u4e2aint <em>:<\/em>pre,*next);<\/li>\n<li>struct ip_vs_conn\u91cc\u9762\u7684\u5176\u4ed6\u5143\u7d20\u5c31\u662f\u6bcf\u4e2a\u8fde\u63a5\u7684\u5177\u4f53\u4fe1\u606f\uff0c\u4e00\u5171128\u5b57\u8282\u3002<\/li>\n<\/ul>\n<p>\u6240\u4ee5\uff0chash\u8868\u91cc\u9762\u7684\u6bcf\u6761\u8bb0\u5f55(\u6bcf\u4e2a\u8fde\u63a5)\uff0c\u5360\u636e136\u5b57\u8282\u5185\u5b58\u3002<\/p>\n<p>hash table\u91cc\u9762\u8868\u957f\u7684\u4ec5\u4ec5\u662f\u6bcf\u4e2a\u94fe\u7684\u5934\u6307\u9488(list_head):<br \/>\nhash size \u8bbe\u7f6e\u4e3a10BITS\u7684\u8bdd,buckets = 1&lt;&lt;10 = 1024,\u6d88\u8017\u7684\u5185\u5b58<br \/>\n1024 * 8 \/ 1024 = 8KB<\/p>\n<p>ipvsadm\u7684\u542f\u52a8\u4fe1\u606f\u91cc\u9762\u663e\u793a\u7684\u4fe1\u606f:<br \/>\nIPVS: Connection hash table configured (size=1024, memory=8Kbytes)<\/p>\n<p>\u8fde\u63a5\u8ddf\u8e2a\u8868\u91cc\u9762\u7684\u6bcf\u884c\u79f0\u4e3ahash bucket(hash\u6876),\u6bcf\u5217\u79f0\u4e3a\u4e00\u4e2a\u8fde\u63a5\u8ddf\u8e2a\u8bb0\u5f55\u3002\u6bcf\u884c(bucket)\u53ef\u4ee5\u6709N\u5217(\u4e5f\u5c31\u662fN\u6761\u8fde\u63a5\u8bb0\u5f55),\u8fd9\u4e2aN\u662f\u65e0\u9650\u7684\uff0c\u53d6\u51b3\u4e8e\u5185\u5b58\u5927\u5c0f\u3002<\/p>\n<p>LD(Director)\u5728\u6bcf\u63a5\u5230\u4e00\u4e2a\u5305\u540e\u90fd\u4f1a\u5728hash\u8868\u91cc\u9762\u8fdb\u884c\u67e5\u627e\u5339\u914d,\u8fd9\u4e2a\u67e5\u627e\u8981\u6c42\u975e\u5e38\u5feb\u901f\u3002LVS\u4f7f\u7528hash\u6280\u672f\u6765\u51b3\u5b9a\u5148\u67e5\u627e\u54ea\u4e2abucket\u3002\u6bcf\u884c(bucket\u6216\u8005row)\u7684\u8bb0\u5f55\u6570(column)\u8d8a\u5c11\uff0c\u67e5\u8be2\u901f\u5ea6\u5c31\u8d8a\u5feb\u3002LVS\u7a0b\u5e8f\u5458\u5efa\u8bae\u6bcf\u884c16-20\u6761\u8bb0\u5f55\u3002<\/p>\n<p>2.6\u5185\u6838\u53ef\u4ee5\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u914d\u7f6eIP_VS_TAB_BITS\u7d2f\u8bbe\u7f6ehash\u6876\u7684\u5927\u5c0f(buckets).\u9ed8\u8ba4\u662f12,\u4e5f\u5c31\u662f\u67092^12 = 4096\u4e2abucket\u3002\u8fd9\u4e2a\u662fLD\u7528\u6765\u52a0\u901f\u94fe\u63a5\u8bb0\u5f55\u67e5\u8be2\u7684hash \u6876(buckets)\u7684\u5927\u5c0f\uff0c\u800c\u4e0d\u662fLD\u652f\u6301\u7684\u6700\u5927\u5e76\u53d1\u8fde\u63a5\u6570\u7684\u5927\u5c0f\u3002(\u6700\u5927\u8fde\u63a5\u6570\u4ec5\u4ec5\u53d7\u9650\u4e8eLD\u7684\u5185\u5b58)<\/p>\n<p>\u663e\u793a\u8fde\u63a5\u8ddf\u8e2a\u8868\u4fe1\u606f\uff1a<\/p>\n<h1>ipvsadm<\/h1>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.houquner.com\">Kermit\u7684\u7f51\u7ad9<\/a> &raquo; <a href=\"https:\/\/www.houquner.com\/index.php\/archives\/228\">LVS\u7684hash size(zz)<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>LVS(Director)\u7684\u8fde\u63a5\u8ddf\u8e2a\u8868(\u4e5f\u79f0Hash\u8868),\u4fdd\u5b58\u4e86\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u6bcf\u4e2a\u65b0\u5efa\u8fde\u63a5\u3002\u8fd9\u4e48\u505a\u7684\u4e3b\u8981\u76ee\u7684\u662f\u4e3a\u4e86\u4fdd\u5b58\u8db3\u591f\u7684\u4fe1\u606f\uff0c\u4f7f\u5f97\u6765\u81ea\u540c\u4e00\u4e2a\u5ba2\u6237\u7aef\u7684\u540e\u7eed\u7684\u6570\u636e\u62a5\u80fd\u901a\u8fc7\u540c\u4e00\u4e2a\u7f51\u7edc\u8fde\u63a5\u53d1\u9001\u5230\u76f8\u540c\u7684\u771f\u5b9e\u670d\u52a1\u5668\u4e0a(RealServer).\u6bcf\u4e2a\u8fde\u63a5\u7684\u4fe1\u606f\u5305\u62ec [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-228","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/posts\/228"}],"collection":[{"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/comments?post=228"}],"version-history":[{"count":0,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/posts\/228\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/media?parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/categories?post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.houquner.com\/index.php\/wp-json\/wp\/v2\/tags?post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}