openresty / lua-resty-balancer

A generic consistent hash implementation for OpenResty/Lua
322 stars 77 forks source link

feature: Round Robin with optional random start #26

Closed ElvinEfendi closed 5 years ago

ElvinEfendi commented 5 years ago

It's sometimes useful to have Round Robin algorithm to start with a random node in the given list instead of always starting with the first one. Imagine you have 50 replicas on Nginx and in each replica 16 workers. That means all 50*16 requests will end up in the first server.

For another real world use case please refer to the thread in https://github.com/kubernetes/ingress-nginx/issues/4023#issuecomment-495951693.

This PR adds an optional flag to Round Robin initializer and if the flag is set it picks last_id at random instead of setting it to `nil.

ElvinEfendi commented 5 years ago

@doujiang24 thanks for quick review! I addressed your comments.

ElvinEfendi commented 5 years ago

Is there anything else I can do to get this merged and released?

ElvinEfendi commented 5 years ago

@doujiang24 any plan here?

ElvinEfendi commented 5 years ago

@doujiang24 when are you planning on releasing this?

doujiang24 commented 5 years ago

@ElvinEfendi yeah, just kicked a new release: https://github.com/openresty/lua-resty-balancer/releases/tag/v0.03. thanks for your contribution :)

ElvinEfendi commented 5 years ago

@doujiang24 thanks! Does it get automatically published to Luarocks? Or do you suggest using OPM?

doujiang24 commented 5 years ago

Does it get automatically published to Luarocks?

not yet.

Or do you suggest using OPM?

OPM doesn't support this library yet since it only supports pure Lua library now.