openresty / lua-resty-balancer

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

Add documentation for roundrobin #7

Closed joshenders closed 7 years ago

joshenders commented 7 years ago

Would you be able to add an example of using the roundrobin load balancing algorithm in the synopsis?

Tieske commented 7 years ago

not sure I get the question. There are two RR implementations, in the dns client (actually 2 here, RR for A/AAAA and WRR for SRV) and the RR implementation in the ring-balancer.

joshenders commented 7 years ago

Ah, sorry if I wasn't clear. I'm referring to the RR balancer implementation. E.g, lib/resty/roundrobin.lua. The documentation states that the chash and roundrobin modules have the same API but even after careful study it's not clear to me how one would use the roundrobin module since it appears very different from the chash module.

doujiang24 commented 7 years ago

@joshenders I have just added a example in Synopsis. By the way, the resty.chash example Synopsis is a bit more complicated, because it's the example to keep the same hash result as the nginx builtin consistent_hash.

joshenders commented 7 years ago

That's very helpful, thank you! I also ended up looking at the roundrobin test cases which made it more clear. Using _M.next() was easier to reason about than _M.find().

Tieske commented 7 years ago

Apologies for my remark above, had another repository in mind, so it is complete BS in relation to this repo. Sorry for the noise!