Add some functions: add_server(),add_peer(),remove_server(),remove_peer() and it's support round_robin or ip_hash.
Hi, agentzh :
I did the following there points Pls review the code, and thx.
First: Add functions: add_server(), add_peer(), remove_server() and remove_peer() and they support load balance algorithm: ip_hash or round_robin.
Second: In order to support UPSTREAM_CHECK_MODULE, I add the ngx_http_lua_upstream_module.h head file. In this file, there are save some structs/variables which are used in health check module.
Third: Update README.md and add some test for add_server() / add_peer() / remove_server() / remove_peer().
Hi,@agentzh , @wangfakang is the member of my team, Plz review the code, if anything wrong, plz contact me or @wangfakang .
Hi guys. Thanks for contributing. I've found so many coding style issues in this patch. So many that I'm tired of commenting in the patch. Please fix them before I can review your logic. Thanks a lot!
Hi @agentzh, Thanks for your code review. I'll update code as soon as possible.
Since adding add/remove peers is inevitably hacky, I wonder if the upcoming balancer_by_lua directive in ngx_lua will fulfil your requirements. Basically we will allow using Lua to write nginx upstream balancer directly where you can specify a dynamic set of peers to try for each request (if you wish) and define dynamic failover policies without hassle. This is much more flexible than the add/remove peer APIs you propose in this PR and its implementation is also much cleaner and simpler. What do you think?
@agentzh Oh, its a good idea, Im looking forward to try it, I have some questions that through balancer_by_lua directive to realize dynamic upstream can work with all the existing balancer modules like least_conn, ip_hash ? Id like to know the implementation principle of balancer_by_lua, could you give me some tips and I'm glad to learn from your idea thanks :D.
@wangfakang least_conn and ip_hash assume the round-robin upstream module at the bottom. Since balancer_by_lua can replace round-robin altogether, I need to think more about getting existing upstream modules work with balancer_by_lua at the same time. Or we can simply re-implement those least_conn and ip_hash logic in pure Lua. Their logic is very simple anyway. And this way can be way easier (and also more flexible).
@agentzh Thank you, I've learned. It's really flexible, so that we can achieve some business logic in the upstream module using balancer_by_lua is more simpler :).
@wangfakang Yeah, that was the goal of balancer_by_lua. We needed for per-request load balancing policies at CloudFlare. It would be out in next 2 months or so.
@agentzh thanks for CR, Im update code style and some logic, now they support load balance algorithm: ip_hash, round_robin or least_conn.
@wangfakang any update on this? Thanks
@aledbf Now it's recommended to use balancer_by_lua* for such kind of things.
@aledbf As agentzh put it. dynamic manage upstream clould use balancer_by_lua* and it's very flexible.
Now our internal using lua-upstream-nginx-module provide atomic rest http about dynamic manage upstream. Using consul/etcd or redis as service discovery to automation add or remove upstream server.
. Or we can simply re-implement those least_conn and ip_hash logic in pure Lu
@agentzh ip_hash is easy, we have all information we need, but how could i get the current connection number in all upstream?