Set a bandwidth limit per backend
You can limit the network bandwidth used by a particular application by defining a limit for a given backend (group of servers). This can be for either download or upload speed. The limit is applied across all requests and responses for all clients accessing the application, giving the application a total bandwidth allotment. The limit is expressed in bytes per second.
Use cases for this configuration include:
Prioritizing throughput for important applications, while limiting the maximum throughput of less important applications.
To set a path-based bandwidth limit:
-
Define a stick table that will store the outbound bytes-per-second rate, and another that will store the inbound bytes-per-second rate. The key for each record in the table will be an integer indicating the backend's identifier, so set
type
tointeger
. To have this work in an active-active or active-standby load balancer setup, it's best to define the tables in apeers
section. For more information on aggregating stick table data across load balancers, see Global Profiling Engine.peers mypeers peer
hapee127.0.0.1:10000 table downloadrate type integer size 1m expire 3600s store bytes_out_rate(1s) table uploadrate type integer size 1m expire 3600s store bytes_in_rate(1s) -
In the
backend
section where you would like to enable the limit, add afilter bwlim-out
directive to limit download speeds and afilter bwlim-in
directive to limit upload speeds. For each, set thelimit
parameter, which defines the bytes-per-second maximum, thekey
, which adds or updates a record in the stick table using the backend's identifier as the table key, andtable
, which references the stick table where the application's current data transfer information is stored.backend webservers server web1 192.168.56.6:80 check maxconn 30 server web2 192.168.56.7:80 check maxconn 30 filter bwlim-out mydownloadlimit limit 625000 key backend_id table mypeers/downloadrate filter bwlim-in myuploadlimit limit 625000 key backend_id table mypeers/uploadrate
-
Add the
http-response set-bandwidth-limit
andhttp-request set-bandwidth-limit
directives to the backend, which enable the filters.http-response set-bandwidth-limit mydownloadlimit http-request set-bandwidth-limit myuploadlimit
Next up
Set a bandwidth limit per client IP address