Ò»ÖÂÐÔhashºÍsolrǧÍò¼¶Êý¾Ý·Ö²¼Ê½ËÑË÷ÒýÇæÖеÄÓ¦ÓÃ
»¥ÁªÍø´´ÒµÖд󲿷ÖÈ˶¼ÊDzݸù´´Òµ£¬Õâ¸öʱºòûÓÐÇ¿¾¢µÄ·þÎñÆ÷£¬Ò²Ã»ÓÐǮȥÂòºÜ°º¹óµÄº£Á¿Êý¾Ý¿â¡£ÔÚÕâÑùÑϾþµÄÌõ¼þÏ£¬Ò»ÅúÓÖÒ»ÅúµÄ´´ÒµÕß´Ó´´ÒµÖлñµÃ³É¹¦£¬Õâ¸öºÍµ±Ç°µÄ¿ªÔ´¼¼Êõ¡¢º£Á¿Êý¾Ý¼Ü¹¹ÓÐ×űز»¿É·ÖµÄ¹Øϵ¡£±ÈÈçÎÒÃÇʹÓÃmysql¡¢nginxµÈ¿ªÔ´Èí¼þ£¬Í¨¹ý¼Ü¹¹ºÍµÍ³É±¾·þÎñÆ÷Ò²¿ÉÒԴǧÍò¼¶Óû§·ÃÎÊÁ¿µÄϵͳ¡£ÐÂÀË΢²©¡¢ÌÔ±¦Íø¡¢ÌÚѶµÈ´óÐÍ»¥ÁªÍø¹«Ë¾¶¼Ê¹ÓÃÁ˺ܶ࿪ԴÃâ·Ñϵͳ´î½¨ÁËËûÃǵÄƽ̨¡£ËùÒÔ£¬ÓÃʲôû¹Øϵ£¬Ö»ÒªÄܹ»ÔÚºÏÀíµÄÇé¿öϲÉÓúÏÀíµÄ½â¾ö·½°¸¡£
ÄÇÔõô´î½¨Ò»¸öºÃµÄϵͳ¼Ü¹¹ÄØ£¿Õâ¸ö»°ÌâÌ«´ó£¬ÕâÀïÖ÷Ҫ˵һÏÂÊý¾Ý·ÖÁ÷µÄ·½Ê½¡£±ÈÈçÎÒÃǵÄÊý¾Ý¿â·þÎñÆ÷Ö»ÄÜ´æ´¢200¸öÊý¾Ý£¬Í»È»Òª¸ãÒ»¸ö»î¶¯Ô¤¹À´ïµ½600¸öÊý¾Ý¡£
¿ÉÒÔ²ÉÓÃÁ½ÖÖ·½Ê½£ººáÏòÀ©Õ¹»òÕß×ÝÏòÀ©Õ¹¡£
×ÝÏòÀ©Õ¹ÊÇÉý¼¶·þÎñÆ÷µÄÓ²¼þ×ÊÔ´¡£µ«ÊÇËæ×Å»úÆ÷µÄÐÔÄÜÅäÖÃÔ½¸ß£¬¼Û¸ñÔ½¸ß£¬Õâ¸ö´ú¼Û¶ÔÓÚÒ»°ãµÄС¹«Ë¾Êdzе£²»ÆðµÄ¡£
ºáÏòÀ©Õ¹ÊDzÉÓöà¸öÁ®¼ÛµÄ»úÆ÷Ìṩ·þÎñ¡£ÕâÑùÒ»¸ö»úÆ÷Ö»ÄÜ´¦Àí200¸öÊý¾Ý¡¢3¸ö»úÆ÷¾Í¿ÉÒÔ´¦Àí600¸öÊý¾ÝÁË£¬Èç¹ûÒÔºóÒµÎñÁ¿Ôö¼Ó»¹¿ÉÒÔ¿ìËÙÅäÖÃÔö¼Ó¡£ÔÚ´ó¶àÊýÇé¿ö¶¼Ñ¡ÔñºáÏòÀ©Õ¹µÄ·½Ê½¡£ÈçÏÂͼ£º
ÏÖÔÚÓиöÎÊÌâÁË£¬Õâ600¸öÊý¾ÝÈçºÎ·Óɵ½¶ÔÓ¦µÄ»úÆ÷¡£ÐèÒª¿¼ÂÇÈç¹û¾ùºâ·ÖÅ䣬¼ÙÉèÎÒÃÇ600¸öÊý¾Ý¶¼ÊÇͳһµÄ×ÔÔöidÊý¾Ý£¬´Ó1~600£¬·Ö³É3¶Ñ¿ÉÒÔ²ÉÓà id mod 3µÄ·½Ê½¡£ÆäʵÔÚÕæʵ»·¾³¿ÉÄܲ»ÊÇÕâÖÖidÊÇ×Ö·û´®¡£ÐèÒª°Ñ×Ö·û´®×ª±äΪhashcodeÔÙ½øÐÐÈ¡Ä£¡£
Ä¿Ç°¿´ÆðÀ´ÊDz»Êǽâ¾öÎÒÃǵÄÎÊÌâÁË£¬ËùÓÐÊý¾Ý¶¼ºÜºÃµÄ·Ö·¢²¢ÇÒûÓдﵽϵͳµÄ¸ºÔØ¡£µ«Èç¹ûÎÒÃǵÄÊý¾ÝÐèÒª´æ´¢¡¢ÐèÒª¶ÁÈ¡¾ÍûÓÐÕâôÈÝÒ×ÁË¡£ÒµÎñÔö¶àÔõô°ì£¬´ó¼Ò°´ÕÕÉÏÃæµÄºáÏòÀ©Õ¹ÖªµÀÐèÒªÔö¼Óһ̨·þÎñÆ÷¡£µ«ÊǾÍÊÇÒòΪÔö¼ÓÕâһ̨·þÎñÆ÷´øÀ´ÁËһЩÎÊÌâ¡£¿´ÏÂÃæÕâ¸öÀý×Ó£¬Ò»¹²9¸öÊý£¬ÐèÒª·Åµ½2̨»úÆ÷£¨1¡¢2£©ÉÏ¡£¸÷¸ö»úÆ÷´æ·ÅΪ£º1ºÅ»úÆ÷´æ·Å1¡¢3¡¢5¡¢7¡¢9 £¬2ºÅ»úÆ÷´æ·Å 2¡¢4¡¢6¡¢8¡£Èç¹ûÀ©Õ¹Ò»Ì¨»úÆ÷3ÈçºÎ£¬Êý¾Ý¾ÍÒª·¢Éú´óǨÒÆ£¬1ºÅ»úÆ÷´æ·Å1¡¢4¡¢7, 2ºÅ»úÆ÷´æ·Å2¡¢5¡¢8, 3ºÅ»úÆ÷´æ·Å3¡¢6¡¢9¡£Èçͼ£º
´ÓͼÖпÉÒÔ¿´³ö 1ºÅ»úÆ÷µÄ3¡¢5¡¢9ǨÒƳöÈ¥ÁË¡¢2ºÃ»úÆ÷µÄ4¡¢6ǨÒƳöÈ¥ÁË£¬°´ÕÕеÄÖÈÐòÔÙÖØзÖÅäÁËÒ»±é¡£Êý¾ÝÁ¿Ð¡µÄ»°ÖØзÖÅäÒ»±é´ú¼Û²¢²»´ó£¬µ«Èç¹ûÎÒÃÇÓµÓÐÉÏÒÚ¡¢ÉÏT¼¶µÄÊý¾ÝÕâ¸ö²Ù×÷³É±¾ÊÇÏ൱µÄ¸ß£¬ÉÙÔò¼¸¸öСʱ¶àÔòÊýÌì¡£²¢ÇÒǨÒƵÄʱºòÔÊý¾Ý¿â»úÆ÷¸ºÔرȽϸߣ¬ÄÇ´ó¼Ò¾ÍÓÐÒÉÎÊÁË£¬ÊDz»ÊÇÕâÖÖˮƽÀ©Õ¹µÄ¼Ü¹¹·½Ê½²»Ì«ºÏÀí£¿
¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C»ªÀö·Ö¸îÏß¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª
Ò»ÖÂÐÔhash¾ÍÊÇÔÚÕâÖÖÓ¦Óñ³¾°Ìá³öÀ´µÄ£¬ÏÖÔÚ±»¹ã·ºÓ¦ÓÃÓÚ·Ö²¼Ê½»º´æ£¬±ÈÈçmemcached¡£ÏÂÃæ¼òµ¥½éÉÜÏÂÒ»ÖÂÐÔhashµÄ»ù±¾ÔÀí¡£×îÔçµÄ°æ±¾ http://dl.acm.org/citation.cfm?id=258660¡£¹úÄÚÍøÉÏÓкܶàÎÄÕ¶¼Ð´µÄ±È½ÏºÃ¡£È磺 http://blog.csdn.net/x15594/article/details/6270242
ÏÂÃæ¼òµ¥¾Ù¸öÀý×ÓÀ´ËµÃ÷Ò»ÖÂÐÔhash¡£
×¼±¸£º1¡¢2¡¢3 Èý̨»úÆ÷
»¹Óдý·ÖÅäµÄ9¸öÊý 1¡¢2¡¢3¡¢4¡¢5¡¢6¡¢7¡¢8¡¢9
Ò»ÖÂÐÔhashËã·¨¼Ü¹¹
²½Öè
Ò»¡¢¹¹Ôì³öÀ´ 2µÄ32´Î·½ ¸öÐéÄâ½Úµã³öÀ´£¬ÒòΪ¼ÆËã»úÀïÃæÊÇ01µÄÊÀ½ç£¬½øÐл®·Öʱ²ÉÓÃ2µÄ´Î·½Êý¾ÝÈÝÒ×·ÖÅä¾ùºâ¡£Áí 2µÄ32´Î·½ÊÇ42ÒÚ£¬ÎÒÃǾÍËãÓг¬´óÁ¿µÄ·þÎñÆ÷Ò²²»¿ÉÄܳ¬¹ý42ÒŲ́°É£¬À©Õ¹ºÍ¾ùºâÐÔ¶¼±£Ö¤ÁË¡£
¶þ¡¢½«Èý̨»úÆ÷·Ö±ðÈ¡IP½øÐÐhashcode¼ÆË㣨ÕâÀïÒ²¿ÉÒÔÈ¡hostname£¬Ö»ÒªÄܹ»Î¨Ò»Çø±ð¸÷¸ö»úÆ÷¾Í¿ÉÒÔÁË£©£¬È»ºóÓ³Éäµ½2µÄ32´Î·½ÉÏÈ¥¡£±ÈÈç1ºÅ»úÆ÷Ëã³öÀ´µÄhashcode²¢ÇÒmod (2^32)Ϊ 123£¨Õâ¸öÊÇÐé¹¹µÄ£©£¬2ºÅ»úÆ÷Ëã³öÀ´µÄֵΪ 2300420£¬3ºÅ»úÆ÷Ëã³öÀ´Îª 90203920¡£ÕâÑùÈý̨»úÆ÷¾ÍÓ³Éäµ½ÁËÕâ¸öÐéÄâµÄ42ÒÚ»·ÐνṹµÄ½ÚµãÉÏÁË¡£
Èý¡¢½«Êý¾Ý£¨1-9£©Ò²ÓÃͬÑùµÄ·½·¨Ëã³öhashcode²¢¶Ô42ÒÚÈ¡Ä£½«ÆäÅäÖõ½»·ÐνڵãÉÏ¡£¼ÙÉèÕ⼸¸ö½ÚµãËã³öÀ´µÄֵΪ 1£º10£¬2£º23564£¬3£º57£¬4£º6984£¬5£º5689632£¬6£º86546845£¬7£º122£¬8£º3300689£¬9£º135468¡£¿ÉÒÔ¿´³ö 1¡¢3¡¢7СÓÚ123£¬ 2¡¢4¡¢9 СÓÚ 2300420 ´óÓÚ 123£¬ 5¡¢6¡¢8 ´óÓÚ 2300420 СÓÚ90203920¡£´ÓÊý¾ÝÓ³Éäµ½µÄλÖÿªÊ¼Ë³Ê±Õë²éÕÒ£¬½«Êý¾Ý±£´æµ½ÕÒµ½µÄµÚÒ»¸öCache½ÚµãÉÏ¡£Èç¹û³¬¹ý2^32ÈÔÈ»ÕÒ²»µ½Cache½Úµã£¬¾Í»á±£´æµ½µÚÒ»¸öCache½ÚµãÉÏ¡£Ò²¾ÍÊÇ1¡¢3¡¢7½«·ÖÅäµ½1ºÅ»úÆ÷£¬2¡¢4¡¢9½«·ÖÅäµ½2ºÅ»úÆ÷£¬5¡¢6¡¢8½«·ÖÅäµ½3ºÅ»úÆ÷¡£
Õâ¸öʱºò´ó¼Ò¿ÉÄÜ»áÎÊ£¬ÎÒµ½ÏÖÔÚûÓп´¼ûÒ»ÖÂÐÔhash´øÀ´Èκκô¦£¬±È´«Í³µÄÈ¡Ä£»¹Ôö¼ÓÁ˸´ÔӶȡ£ÏÖÔÚÂíÉÏÀ´×öһЩ¹Ø¼üÐԵĴ¦Àí£¬±ÈÈçÎÒÃÇÔö¼Óһ̨»úÆ÷¡£°´ÕÕÔÀ´ÎÒÃÇÐèÒª°ÑËùÓеÄÊý¾ÝÖØзÖÅäµ½ËĄ̈»úÆ÷¡£Ò»ÖÂÐÔhashÔõô×öÄØ£¿ÏÖÔÚ4ºÅ»úÆ÷¼Ó½øÀ´£¬ËûµÄhashÖµËã³öÀ´È¡Ä£ºóÊÇ12302012¡£ 5¡¢8 ´óÓÚ2300420 СÓÚ12302012 £¬6 ´óÓÚ 12302012 СÓÚ90203920 ¡£ÕâÑùµ÷ÕûµÄÖ»ÊÇ°Ñ5¡¢8´Ó3ºÅ»úÆ÷ɾ³ý£¬4ºÅ»úÆ÷ÖмÓÈë 5¡¢8¡£
ͬÀí£¬É¾³ý»úÆ÷Ôõô×öÄØ£¬¼ÙÉè2ºÅ»úÆ÷¹Òµô£¬ÊÜÓ°ÏìµÄÒ²Ö»ÊÇ2ºÅ»úÆ÷ÉϵÄÊý¾Ý±»Ç¨ÒƵ½ÀëËü½Úµã£¬ÉÏͼΪ4ºÅ»úÆ÷¡£
´ó¼ÒÓ¦¸ÃÃ÷°×Ò»ÖÂÐÔhashµÄ»ù±¾ÔÀíÁË°É¡£²»¹ýÕâÖÖËã·¨»¹ÊÇÓÐȱÏÝ£¬±ÈÈçÔÚ»úÆ÷½Úµã±È½ÏÉÙ¡¢Êý¾ÝÁ¿´óµÄʱºò£¬Êý¾ÝµÄ·Ö²¼¿ÉÄܲ»ÊǺܾùºâ£¬¾Í»áµ¼ÖÂÆäÖÐһ̨·þÎñÆ÷µÄÊý¾Ý±ÈÆäËû»úÆ÷¶àºÜ¶à¡£ÎªÁ˽â¾öÕâ¸öÎÊÌ⣬ÐèÒªÒýÈëÐéÄâ·þÎñÆ÷½ÚµãµÄ»úÖÆ¡£ÈçÎÒÃÇÒ»¹²ÓÐÖ»ÓÐÈý̨»úÆ÷£¬1¡¢2¡¢3¡£µ«ÊÇʵ¼ÊÓÖ²»¿ÉÄÜÓÐÕâô¶à»úÆ÷Ôõô½â¾öÄØ£¿°Ñ ÕâЩ»úÆ÷¸÷×ÔÐéÄ⻯³öÀ´3̨»úÆ÷£¬Ò²¾ÍÊÇ 1a 1b 1c 2a 2b 2c 3a 3b 3c£¬ÕâÑù¾Í±ä³ÉÁË9̨»úÆ÷¡£Êµ¼Ê 1a 1b 1c »¹ÊǶÔÓ¦1¡£µ«ÊÇʵ¼Ê·Ö²¼µ½»·Ðνڵã¾Í±ä³ÉÁË9̨»úÆ÷¡£Êý¾Ý·Ö²¼Ò²¾ÍÄܹ»¸ü·ÖÉ¢Ò»µã¡£Èçͼ£º
дÁËÕâô¶àÒ»ÖÂÐÔhash£¬Õâ¸öºÍ·Ö²¼Ê½ËÑË÷ÓÐʲô°ëµã¹Øϵ£¿ÎÒÃÇÏÖÔÚʹÓÃsolr4´î½¨ÁË·Ö²¼Ê½ËÑË÷£¬²âÊÔÁË»ùÓÚsolrcloudµÄ·Ö²¼Ê½Æ½Ì¨Ìá½»20ÌõÊý¾Ý¾ÓÈ»ÐèÒª¼¸Ê®Ã룬ËùÒԾͷÏÆúÁËsolrcloud¡£²ÉÓÃ×Ô¼ºhack solrƽ̨£¬²»ÓÃzookeeper×ö·Ö²¼Ê½Ò»ÖÂÐÔ¹ÜÀíƽ̨£¬×Ô¼º¹ÜÀíÊý¾ÝµÄ·Ö·¢»úÖÆ¡£¼ÈÈ»ÐèÒª×Ô¼º¹ÜÀíÊý¾ÝµÄ·Ö·¢£¬¾ÍÐèÒª¿¼Âǵ½Ë÷ÒýµÄ´´½¨£¬Ë÷ÒýµÄ¸üС£ÕâÑùÎÒÃǵÄÒ»ÖÂÐÔhashÒ²¾ÍÓÃÉÏÁË¡£ÕûÌå¼Ü¹¹ÈçÏÂͼ£º
½¨Á¢ºÍ¸üÐÂÐèҪά³Ö»úÆ÷µÄλÖã¬Äܹ»¸ù¾ÝÊý¾ÝµÄkeyÕÒµ½¶ÔÓ¦µÄÊý¾Ý·Ö·¢²¢¸üС£ÕâÀïÐèÒª¿¼ÂǵÄÊÇÈçºÎ¸ßЧ¡¢¿É¿¿µÄ°ÑÊý¾Ý½¨Á¢¡¢¸üе½Ë÷ÒýÀï¡£
±¸·Ý·þÎñÆ÷·ÀÖ¹½¨Á¢·þÎñÆ÷¹Òµô£¬¿ÉÒÔ¸ù¾Ý±¸·Ý·þÎñÆ÷¿ìËÙ»Ö¸´¡£
¶Á·þÎñÆ÷Ö÷Òª×ö¶Áд·ÖÀëʹÓ㬷ÀֹдË÷ÒýÓ°Ïì²éѯÊý¾Ý¡£
¼¯Èº¹ÜÀí·þÎñÆ÷¹ÜÀíÕû¸ö¼¯ÈºÄڵķþÎñÆ÷״̬¡¢¸æ¾¯¡£
Õû¸ö¼¯ÈºËæ×ÅÒµÎñÔö¶à»¹¿ÉÒÔ°´ÕÕÊý¾ÝµÄÀàÐÍ»®·Ö£¬±ÈÈçÓû§¡¢Î¢²©µÈ¡£Ã¿¸öÀàÐÍ°´ÕÕÉÏͼ¼Ü¹¹´î½¨£¬¾Í¿ÉÒÔÂú×ãÒ»°ãÐÔÄܵķֲ¼Ê½ËÑË÷¡£¶ÔÓÚsolrºÍ·Ö²¼Ê½ËÑË÷µÄ»°ÌâºóÐøÔÙÁÄ¡£
À©Õ¹ÔĶÁ£º
javaµÄhashmapËæ×ÅÊý¾ÝÁ¿µÄÔö¼ÓÒ²»á³öÏÖmapµ÷ÕûµÄÎÊÌ⣬±ØÒªµÄʱºò¾Í³õʼ»¯×ã¹»´óµÄsizeÒÔ·ÀÖ¹ÈÝÁ¿²»×ã¶ÔÒÑÓÐÊý¾Ý½øÐÐÖØÐÂhash¼ÆËã¡£
ÒßÃ磺Java HashMapµÄËÀÑ»· http://coolshell.cn/articles/9606.html
Ò»ÖÂÐÔ¹þÏ£Ëã·¨µÄÓÅ»¯¡ª-¹ØÓÚÈçºÎ±£ÕýÔÚ»·ÖÐÔö¼Óнڵãʱ£¬ÃüÖÐÂʲ»ÊÜÓ°Ïì £¨ÔÅÄÅÄͬÊÂscott£©http://scottina.iteye.com/blog/650380
ÓïÑÔʵÏÖ£º
http://weblogs.java.net/blog/2007/11/27/consistent-hashing java °æ±¾µÄÀý×Ó
http://blog.csdn.net/mayongzhan/archive/2009/06/25/4298834.aspx PHP °æµÄÀý×Ó
http://www.codeproject.com/KB/recipes/lib-conhash.aspx CÓïÑÔ°æ±¾Àý×Ó
תÔØ×ÔLANCEYAN.COM
ÍƼöÐÅÏ¢
- linuxÃüÁîѧϰ±Ê¼Ç£¨11£©£ºnlÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨5£©£ºrmÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨4£©£ºmkdirÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨1£©£ºlsÃüÁî
- ½«CentosµÄyumÔ´¸ü»»Îª¹úÄڵİ¢ÀïÔÆÔ´
- ʹÓÃNginxÌí¼Óheader·ÀÖ¹ÍøÒ³±»frame
- linuxϼÓËÙscp´«Êä´óÎļþµÄËÙ¶È
- linuxϵͳÉ϶ÔnginxÈÕÖ¾·Ö¸î´¦Àí
- lnmp/nginxϵͳÕæÕýÓÐЧµÄͼƬ·ÀµÁÁ´ÍêÕûÉèÖÃÏê½â
- Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- ²éÕÒ²¢É¾³ý.svnĿ¼Îļþ
- redis ÆßÖÖÊý¾ÝÀàÐ͵ÄʹÓó¡¾°
- linux ÏÂÎļþ¸´ÖƵ½windowsÏÂÂÒÂëµÄ½â¾ö°ì·¨
- nginx³öÏÖ502 upstream sent too big he....
- linuxÏÂsudoÅäÖÃÏê½â
- linuxÃüÁîѧϰ±Ê¼Ç£¨15£©£ºtailÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨14£©£ºheadÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨13£©£ºlessÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨12£©£ºmoreÃüÁî
- ¼ÓÃÜËã·¨±È½Ï3DES AES RSA ECC MD5 SHA1µÈ
ÆÀÂÛ