Reference
set weight
Change the weight of a server.
Description Jump to heading
Use set weight to increase or decrease the weight assigned to a server, which affects how much traffic the load balancer sends to it.
Examples Jump to heading
In the example below, the backend has two servers, each with an assigned weight of 100:
haproxybackend be_serversserver server1 127.0.0.1:8080 check weight 100server server2 127.0.0.1:8081 check weight 100
haproxybackend be_serversserver server1 127.0.0.1:8080 check weight 100server server2 127.0.0.1:8081 check weight 100
-
Use the
get weightRuntime API command to display the current weight of a given server.nixecho "get weight be_servers/server1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "get weight be_servers/server1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999outputtext100 (initial 100)outputtext100 (initial 100)It indicates the initial value that was set in the configuration file and the current value, which may have changed.
-
Use
set weightto change the weight of a server.You can pass either an absolute value or a percentage.
nixecho "set weight be_servers/server1 50%" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "set weight be_servers/server1 50%" | \sudo socat stdio tcp4-connect:127.0.0.1:9999In the snippet above, we changed the
server1server’s weight to 50% of its current value. -
Call
get weightagain to see the server’s updated weight:nixecho "get weight be_servers/server1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "get weight be_servers/server1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999outputtext50 (initial 100)outputtext50 (initial 100)
See also Jump to heading
Do you have any suggestions on how we can improve the content of this page?