Open klinquist opened 9 years ago
I'm not exactly sure what you want, but the range method might be useful here: https://github.com/3rd-Eden/node-hashring/blob/master/index.js#L252-L303
3rd-eden: Thanks - with the range function, the hashring needs to already have been defined (if I'm reading it correctly).
I've got half a dozen different server types and for each server type, I'll be scaling up and down instances dynamically based on load. I'll make a db query to find out how many instances there currently are for a given server type and then I'd like to know which instance to assign a user to based on their userid.
I want a function that generates a hashring with (X) "servers" with the "servers" simply being named ("1" through "X")
My code above works by generating 10 hashrings (supporting services for up to 10 servers) allowing me to say "tell me the appropriate server for a service that has 4 instances".
Hope that clarifies things!
Assuming I have X servers for a given service - and I want all the parameters (vnodes, weight) to be the same, is there any way to just say...
var correct_server_number = ring.getresult(number_of_servers,"foo bar")
Right now I'm doing something that seems ridiculous, but it may be the most efficient way.. supports up to 10 servers...