HAProxy Enterprise Documentation 2.6r1

Set a bandwidth limit for uploads

You can limit the network bandwidth used when receiving data from a client. This limit is applied per stream and not at the connection level, meaning that for multiplexed protocols like HTTP/2, where a single connection can simultaneously transfer multiple requests and responses, each of those streams will have its own limit. The limit is expressed in bytes per second.

Use cases for this configuration include:

  • Limiting the bandwidth used when a client uploads a large file.

To set an upload speed limit:

  1. In the frontend section where you would like to enable the limit, add a filter bwlim-in directive that sets default-limit and default-period.

    The default-limit parameter sets the number of bytes that can be transferred during the interval defined by default-period.

    The value 62500, which represents bytes, equals 5Mbps (0.625 megabytes per second = 5 megabits per second).

    frontend myfrontend
       mode http
       bind :80
       filter bwlim-in mylimit default-limit 625000 default-period 1s
  2. Add the http-request set-bandwidth-limit directive, which enables the filter.

    frontend myfrontend
       mode http
       bind :80
       filter bwlim-in mylimit default-limit 625000 default-period 1s
       http-request set-bandwidth-limit mylimit
  3. Optional: Edit the http-request set-bandwidth-limit directive or add another one to override the bandwidth limit when a given condition is true.

    This example overrides the bandwidth limit if the URL path begins with /gaming.

    frontend myfrontend
       mode http
       bind :80
    
       # Sets the normal bandwidth limit for uploads to 5 Mbps
       filter bwlim-in mylimit default-limit 625000 default-period 1s
       http-response set-bandwidth-limit mylimit
    
       # Overrides the upload bandwidth limit to be 10 Mbps
       # for any URL path that begins with /gaming
       acl is-gaming path_beg /gaming
       http-request set-bandwidth-limit mylimit limit int(1250000) if is-gaming

Next up

Set a bandwidth limit per backend