希望balancer有更多新特性

229 views
Skip to first unread message

c hello

unread,
Aug 8, 2019, 6:09:16 AM8/8/19
to openresty
关于balancer ,目前测试多次调用 balancer.set_current_peer(host,port) 结果为最后一次,如果有多台server的话只能利用到一台,还需要自定义负载均衡算法选择一台。
所以希望有新的api可以有更多的选择,比如

balancer.add_current_peer(host,port)   ,可以添加多个

balancer.set_upstrem(new_upstream) ,可以利用其他upstream定义的server,和upstrem中定义的权重或者是负载均衡算法

aogooc xu

unread,
Aug 9, 2019, 6:09:15 AM8/9/19
to openresty
我想你需要这个,支持加权轮训和hash算法  https://github.com/openresty/lua-resty-balancer


在 2019年8月8日星期四 UTC+8下午6:09:16,c hello写道:

DeJiang Zhu

unread,
Aug 9, 2019, 6:16:54 AM8/9/19
to open...@googlegroups.com
貌似你对 balancer_by_lua 的理解有些偏差,balancer_by_lua 就是每次重试上游都会重新执行的,这个时候可以每次设置不同的上游,其实是非常底层,非常灵活的

使用类似楼上提到的 lua-resty-balancer 可以帮助你构建更上层的 balancer

c hello <afghan...@gmail.com> 于2019年8月8日周四 下午6:09写道:
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
---
您收到此邮件是因为您订阅了Google网上论坛上的“openresty”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到openresty+...@googlegroups.com
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/openresty/21574e75-dd6f-4c20-8380-7d5a144d7f23%40googlegroups.com

c hello

unread,
Aug 12, 2019, 5:58:53 AM8/12/19
to openresty
非常感谢提示,看了一下对我非常有帮助,因为之前使用的是https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/balancer.md,所以感觉~~~
再次感谢!


在 2019年8月9日星期五 UTC+8下午6:09:15,aogooc xu写道:

c hello

unread,
Aug 12, 2019, 6:11:15 AM8/12/19
to openresty
  upstream service1.default {
        server 127.0.0.1:8080;
        server 127.0.0.1:8081;
        balancer_by_lua_file 'ABTestBalancer.lua';
  }

  upstream service1.abtest {
        server 127.0.0.1:8082;
        server 127.0.0.1:8083;
  }

我的想法是在balancer_by_lua中匹配某些条件后直接替换upstrem,然后直接复用service1.abtest这个upstream,包括其中的server,lb-method,weight等其他一些预先配置好的元素。




在 2019年8月8日星期四 UTC+8下午6:09:16,c hello写道:
关于balancer ,目前测试多次调用 balancer.set_current_peer(host,port) 结果为最后一次,如果有多台server的话只能利用到一台,还需要自定义负载均衡算法选择一台。
Reply all
Reply to author
Forward
0 new messages