Memcached hash Algorithm

Source: Internet
Author: User

From: http://stackoverflow.com/questions/10434375/what-hashing-algorithm-does-memcached-use-to-hash-keys

Question:

Memcached uses distributed consistent hashing to choose which server to put a key on but which hashing algo does it use to map string
Key into the final hash on which the Ketama algo is applied for server selection. And how good is that algo at spreading similar keys to different servers.


Answer:

According to the source code in hash. c,
Memcached uses the following algorithm:

The hash function used here is by Bob Jenkins, 1996:

Http://burtleburtle.net/bob/hash/doobs.html

"By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this code any way you wish, private, educational, or other cial. It's free ."

From Bob Jenkins 'website:

I offer you a new hash function for hash table lookup that is faster and more thorough than the one you are using now. I also give you a way to verify that it is more thorough.

Also, his requirements are:

  • The keys are unaligned variable-length byte arrays.
  • Sometimes keys are several such arrays.
  • Sometimes a set of independent hash functions were required.
  • Average key lengths ranged from 8 bytes to 200 bytes.
  • Keys might be character strings, numbers, bit-arrays, or weirder things.
  • Table sizes cocould be anything, including powers of 2.
  • The hash must be faster than the old one.
  • The hash must do a good job.

...

The real requirement then is that a good hash function shocould distribute hash values uniformly for the keys that users actually use.

To get back to your other question, he measured the ability of the algorithm to uniformly distribute hash values, so I wowould presume that the hash does a good job at spreading similar keys to different servers. if you have concerns, the code is isolated so
You shoshould be able to run your own tests.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.