lua-upstream-nginx-module icon indicating copy to clipboard operation
lua-upstream-nginx-module copied to clipboard

Add some functions: add_server(),add_peer(),remove_server(),remove_peer() and it's support round_robin or ip_hash.

Open wangfakang opened this issue 10 years ago • 13 comments

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().

wangfakang avatar Aug 10 '15 12:08 wangfakang

Hi,@agentzh , @wangfakang is the member of my team, Plz review the code, if anything wrong, plz contact me or @wangfakang .

chunshengster avatar Aug 10 '15 13:08 chunshengster

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!

agentzh avatar Aug 11 '15 04:08 agentzh

Hi @agentzh, Thanks for your code review. I'll update code as soon as possible.

wangfakang avatar Aug 11 '15 06:08 wangfakang

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 avatar Aug 12 '15 04:08 agentzh

@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 avatar Aug 12 '15 16:08 wangfakang

@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 avatar Aug 13 '15 09:08 agentzh

@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 avatar Aug 13 '15 10:08 wangfakang

@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 avatar Aug 14 '15 08:08 agentzh

@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 avatar Aug 19 '15 07:08 wangfakang

@wangfakang any update on this? Thanks

aledbf avatar Mar 16 '16 20:03 aledbf

@aledbf Now it's recommended to use balancer_by_lua* for such kind of things.

agentzh avatar Mar 16 '16 20:03 agentzh

@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.

wangfakang avatar Mar 17 '16 02:03 wangfakang

. 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?

woodgear avatar Nov 09 '21 09:11 woodgear