有没有办法根据后端服务器使用情况dynamic更改haproxy权重?

有没有任何有助于根据后端服务器利用率修改后端服务器权重的实用工具? (例如用于LVS负载均衡的反馈)

您可以尝试使用不同的负载平衡algorithm。 leastconn似乎是你在找什么:

 balance leastconn 

根据官方HaProxy v1.4文档

  leastconn The server with the lowest number of connections receives the connection. Round-robin is performed within groups of servers of the same load to ensure that all servers will be used. Use of this algorithm is recommended where very long sessions are expected, such as LDAP, SQL, TSE, etc... but is not very well suited for protocols using short sessions such as HTTP. This algorithm is dynamic, which means that server weights may be adjusted on the fly for slow starts for instance. 

与传统的roundrobin进行比较:

  roundrobin Each server is used in turns, according to their weights. This is the smoothest and fairest algorithm when the server's processing time remains equally distributed. This algorithm is dynamic, which means that server weights may be adjusted on the fly for slow starts for instance. It is limited by design to 4128 active servers per backend. Note that in some large farms, when a server becomes up after having been down for a very short time, it may sometimes take a few hundreds requests for it to be re-integrated into the farm and start receiving traffic. This is normal, though very rare. It is indicated here in case you would have the chance to observe it, so that you don't worry. 

我写了一个实用程序来做到这一点,你可以在GitHub下载: haproxy-dynamic-weight 。 它提供了一种方法来dynamic地自动分配haproxystream量与服务器的负载成比例。

如果这个pythonmemcached解决scheme不适合你,你会看到脚本的文档引用和链接到两个select。