You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I learned recently that Cachex supports distributed caching, and when checking the implementation I saw that it uses consistent hashing. I wonder if there is any interest in implementing the approach described in https://en.wikipedia.org/wiki/Rendezvous_hashing?
defmoduleRendezvousdodefroute(key)donodes=Node.list()node=Node.self()max_by_hash(nodes,key,node,:erlang.phash2({key,node}))enddefpmax_by_hash([node|nodes],key,max_node,max_hash)dohash=:erlang.phash2({key,node})# TODO needs a tie-breaker for hash collisions, otherwise it seems to depend on nodes ordercasehash>=max_hashdotrue->max_by_hash(nodes,key,node,hash)false->max_by_hash(nodes,key,max_node,max_hash)endenddefpmax_by_hash([],_key,node,_hash),do: nodeend
@ruslandoga hi! Sorry, I thought I'd replied to this 😅
I haven't spent too much time thinking about adding new routers; if you'd like to contribute I'd be happy to take a look at it. If you can, trying to match the same options as the Ring router would be good - makes it easier for people to swap between.
You could also publish as it's own package, so people can include it additionally to Cachex if they need it, then we could bake it in based on how much usage it seems to get (and I'm happy to link to it from the Cachex docs, to avoid visibility bias).
👋
I learned recently that Cachex supports distributed caching, and when checking the implementation I saw that it uses consistent hashing. I wonder if there is any interest in implementing the approach described in https://en.wikipedia.org/wiki/Rendezvous_hashing?
Compared to https://github.com/discord/ex_hash_ring it doesn't require any 3rd party NIFs or keeping extra in-memory state.
Quick performance check
Using a slightly more optimized version:
Three nodes setup:
Quick performance check:
I know this is unfair because of the anonymous function but it shows that it's fast enough while being simpler :)
The text was updated successfully, but these errors were encountered: