Live data from Hacker News

Consistent hashing

eli.thegreenplace.net

11–20 of 26 posts

Re: Consistent hashing

#11
post #9

Is it just me or can you describe the whole scheme in one sentence? tl;dr: subdivide your hash space (say, [0, 2^64)) by the number of slots, then utilize the index of the slot your hash falls in. Or, in another sense: rely on / rather than % for distribution. Is this accurate or am I missing something?

That's the naive method which tends to redistribute most objects when the number of slots changes.

Re: Consistent hashing

#13
Ceph storage uses a hierarchical consistent hashing scheme called "CRUSH" to handle hierarchical data placement and replication across failure domains. Given an object ID, its location can be calculated, and the expected service queried.

As a side effect, it's possible to define a logical topology that reflects the physical layout, spreading data across hosts, racks, or by other arbitrary criteria. Things are exactly where you expect them to be, and there's very little searching involved. Combined with a consistent view of the cluster state, this avoids the need for centralized lookups.

The original paper is a surprisingly short read: https://ceph.com/assets/pdfs/weil-crush-sc06.pdf DOI: 10.1109/SC.2006.19

Re: Consistent hashing

#14
post #10
post #6

The typo is really really bothering me, because the future generations would not be able to search for it.

You can get things like this fixed with the Contact link at the bottom of the page (I just emailed them about it). It's so much better to copy and paste the title of articles.

They seem to have fixed the title. It looks wrong only here on HN now.

Re: Consistent hashing

#15
post #14
post #10

Earlier quoted context omitted.

You can get things like this fixed with the Contact link at the bottom of the page (I just emailed them about it). It's so much better to copy and paste the title of articles.

They seem to have fixed the title. It looks wrong only here on HN now.

Nice, thanks Dang.

Re: Consistent hashing

#16
post #9

Is it just me or can you describe the whole scheme in one sentence? tl;dr: subdivide your hash space (say, [0, 2^64)) by the number of slots, then utilize the index of the slot your hash falls in. Or, in another sense: rely on / rather than % for distribution. Is this accurate or am I missing something?

You're missing that the hash space is not divided uniformly. Which means one can vary the number of slots without recomputing the hash space division -- and without reassigning all of the existing entries.

Re: Consistent hashing

#17
post #7

Have a look at rendezvous hashing ( https://en.wikipedia.org/wiki/Rendezvous_hashing ). It's simpler, and more general than 'consistent hashing'. Eg you don't have to muck around with virtual nodes. Everything just works out, even for small numbers of targets. It's also easier to come up with an exact weighted version of rendezvous hashing. See https://en.wikipedia.org/wiki/Rendezvous_hashing#Weighted_re... for the w…

I also double that rendezvous hashing suggestion. Article mentions that it has O(n) time where n is number of nodes. I made a library[1] which makes rendezvous hashing more practical for a larger number of nodes (or weight shares), making it O(1) amortized running time with a bit of tradeoff: distributed elements are pre-aggregated into clusters (slots) before passing them through HRW.

[1]: https://pkg.go.dev/github.com/SenseUnit/ahrw

Re: Consistent hashing

#18
I've implemented a cache-line aware (from a paper) version of a persistent, consistent hashing algorithm that gets pretty good performance on SSDs:

https://github.com/chiefnoah/mehdb

It's used as the index for a simple KV store I did as an interview problem awhile back, it pretty handily does 500k inserts/s and 5m reads/s and it's nothing special (basic write coalescing, append-only log):

https://git.sr.ht/~chiefnoah/keeeeyz/tree/meh

Re: Consistent hashing

#19
Another strategy to avoid redistribution is simply having a big enough number of partitions and assign ranges instead of single partitions. A bit more complex on the coordination side but works well in other domains (distributed processing for example)

Re: Consistent hashing

#20
post #17
post #7

Have a look at rendezvous hashing ( https://en.wikipedia.org/wiki/Rendezvous_hashing ). It's simpler, and more general than 'consistent hashing'. Eg you don't have to muck around with virtual nodes. Everything just works out, even for small numbers of targets. It's also easier to come up with an exact weighted version of rendezvous hashing. See https://en.wikipedia.org/wiki/Rendezvous_hashing#Weighted_re... for the w…

I also double that rendezvous hashing suggestion. Article mentions that it has O(n) time where n is number of nodes. I made a library[1] which makes rendezvous hashing more practical for a larger number of nodes (or weight shares), making it O(1) amortized running time with a bit of tradeoff: distributed elements are pre-aggregated into clusters (slots) before passing them through HRW. [1]: https://pkg.go.dev/github.…

Does it really matter? Here, n is a very small number, which is almost a constant. I'd assume the iteration over the n space is negligible compared to the other parts of a request to a node.
Post reply on HN