大网数据广告活动
服务器运维问答

How to use "Set weight" in HAProxy

· 52CE 我爱测

Hi I have configured an HAProxy server in haproxy.cfg to balance the traffic flow between two servers, say server web1 10.10.10.10 weight 50 server web2 10.10.10.11 weight 50 For testing purpose we need to set the weights dynamic…

问题原文

原帖链接 · susil95 · CC BY-SA 4.0

Hi I have configured an HAProxy server in haproxy.cfg to balance the traffic flow between two servers, say

server web1 10.10.10.10 weight 50
server web2 10.10.10.11 weight 50

For testing purpose we need to set the weights dynamically, so we are using set weight <backend>/<server> <weight>[%] command as mentioned in this article http://cbonte.github.io/haproxy-dconv/configuration-1.4.html#hash-type

1) In the document they have mentioned

Relative weights are only permitted between 0 and 100%, and absolute weights are permitted between 0 and 256.

and if I use set weight for web1 with percentage value 70%, does it means 70% in that allotted 50 for web1(which is initially configured in server) traffic is passed, if so rest of that 30% in that 50 value where it will be passed?

2) Another query is, if we use set weight command as

set weight web1 10.10.10.10 3
set weight web2 10.10.10.11 1

Does it mean that 75% of the traffic to web1 and 25% traffic to web2? How to split traffic in ratio manner and use it in set weight.

If possible please let me know how to use absolute weight for splitting traffic. Thanks for the answer.

已采纳解答

原帖链接 · Tommiie · CC BY-SA 4.0

Question 1:

The documentation states:

If the value ends with the '%' sign, then the new weight will be relative to the initially configured weight.

So it indeed means 70% "in that allotted 50 for web1". Where the other 30% would go, is not clear from the documentation but it would have to be web2 as it can not be dropped.

Question 2:

The HAProxy documentation states:

The "weight" parameter is used to adjust the server's weight relative to other servers. All servers will receive a load proportional to their weight relative to the sum of all weights, so the higher the weight, the higher the load. The default weight is 1, and the maximal value is 256

So, yes, it means that web1 will receive 75% = 3/(1+3) of traffic and web2 will receive 25% of traffic.

Extra questions:

How to split traffic in ratio manner and use it in set weight.

If possible please let me know how to use absolute weight for splitting traffic.

I don't understand these two questions. Can you elaborate a bit?

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-08-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。