HAproxy static-rr 的 weight 和 session 分配的關係
設定檔如下
listen 80-balancer
mode http
bind 0.0.0.0:80
balance static-rr
server w1 10.39.106.216:80 weight 10 check
server w2 10.39.106.217:80 weight 7 check
server w3 10.39.106.203:80 weight 1 check
使用 webbenck 模擬 5000 個 client ,持續測試 300 秒測試的結果如下
w1 : 49023 個 session
w2 : 33180 個 session
w3 : 4726 個 session
其關係為
w1 : ( w1 session + w2 session + w3 session ) / ( w1 weight + w2 weight + w3 weight ) * w1 weight
= ( 49023 + 33180 + 4726 ) / ( 10 + 7 + 1 ) * 10 = 48293.89
w2 : ( w1 session + w2 session + w3 session ) / ( w1 weight + w2 weight + w3 weight ) * w2 weight
= ( 49023 + 33180 + 4726 ) / ( 10 + 7 + 1 ) * 7 = 33805.72
w3 : ( w1 session + w2 session + w3 session ) / ( w1 weight + w2 weight + w3 weight ) * w3 weight
= ( 49023 + 33180 + 4726 ) / ( 10 + 7 + 1 ) * 1 = 4829.39