From f028e6e066c2153442715448501b5916e2061f4b Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 22 Jun 2022 16:55:04 +0200 Subject: [PATCH] MEDIUM: bwlim: Add support of bandwith limitation at the stream level This patch adds a filter to limit bandwith at the stream level. Several filters can be defined. A filter may limit incoming data (upload) or outgoing data (download). The limit can be defined per-stream or shared via a stick-table. For a given stream, the bandwith limitation filters can be enabled using the "set-bandwidth-limit" action. A bandwith limitation filter can be used indifferently for HTTP or TCP stream. For HTTP stream, only the payload transfer is limited. The filter is pretty simple for now. But it was designed to be extensible. The current design tries, as far as possible, to never exceed the limit. There is no burst. --- Makefile | 2 +- doc/configuration.txt | 176 +++++++++ src/flt_bwlim.c | 848 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1025 insertions(+), 1 deletion(-) create mode 100644 src/flt_bwlim.c diff --git a/Makefile b/Makefile index b248acccfa..8148371339 100644 --- a/Makefile +++ b/Makefile @@ -955,7 +955,7 @@ OBJS += src/mux_h2.o src/mux_fcgi.o src/mux_h1.o src/tcpcheck.o \ src/base64.o src/auth.o src/uri_auth.o src/time.o src/ebistree.o \ src/dynbuf.o src/wdt.o src/pipe.o src/init.o src/http_acl.o \ src/hpack-huff.o src/hpack-enc.o src/dict.o src/freq_ctr.o \ - src/ebtree.o src/hash.o src/dgram.o src/version.o + src/ebtree.o src/hash.o src/dgram.o src/version.o src/flt_bwlim.o ifneq ($(TRACE),) OBJS += src/calltrace.o diff --git a/doc/configuration.txt b/doc/configuration.txt index 183710c357..7efefea303 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -120,6 +120,7 @@ Summary 9.4. Cache 9.5. fcgi-app 9.6. OpenTracing +9.7. Bandwidth limitation 10. FastCGI applications 10.1. Setup @@ -6322,6 +6323,7 @@ http-request [options...] [ { if | unless } ] - sc-inc-gpc1() - sc-set-gpt(,) { | } - sc-set-gpt0() { | } + - set-bandwidth-limit [limit ] [period ] - set-dst - set-dst-port - set-header @@ -6991,6 +6993,33 @@ http-request send-spoe-group The SPOE group name as specified in the engine configuration. +http-request set-bandwidth-limit [limit ] [period ] [ { if | unless } ] + + This action is used to enable the bandwidth limitation filter , either + on the upload or download direction depending on the filter type. Custom + limit and period may be defined, if and only if references a + per-stream bandwidth limitation filter. When a set-bandwidth-limit rule is + executed, it first resets all settings of the filter to their defaults prior + to enabling it. As a consequence, if several "set-bandwidth-limit" actions + are executed for the same filter, only the last one is considered. Several + bandwidth limitation filters can be enabled on the same stream. + + Note that this action cannot be used in a defaults section because bandwidth + limitation filters cannot be defined in defaults sections. In addition, only + the HTTP payload transfer is limited. The HTTP headers are not considered. + + Arguments: + Is a standard HAProxy expression formed by a sample-fetch followed + by some converters. The result is converted to an integer. It is + interpreted as a size in bytes for the "limit" parameter and as a + duration in milliseconds for the "period" parameter. + + Example: + http-request set-bandwidth-limit global-limit + http-request set-bandwidth-limit my-limit limit 1m period 10s + + See section 9.7 about bandwidth limitation filter setup. + http-request set-dst [ { if | unless } ] This is used to set the destination IP address to the value of specified @@ -7462,6 +7491,7 @@ http-response [ { if | unless } ] - sc-set-gpt(,) { | } - sc-set-gpt0() { | } - send-spoe-group + - set-bandwidth-limit [limit ] [period ] - set-header - set-log-level - set-map() @@ -7659,6 +7689,12 @@ http-response send-spoe-group This action is used to trigger sending of a group of SPOE messages. Please refer to "http-request send-spoe-group" for a complete description. +http-response set-bandwidth-limit [limit ] [period ] [ { if | unless } ] + + This action is used to enable the bandwidth limitation filter , either + on the upload or download direction depending on the filter type. Please + refer to "http-request set-bandwidth-limit" for a complete description. + http-response set-header [ { if | unless } ] This does the same as "http-response add-header" except that the header name @@ -12587,6 +12623,7 @@ tcp-request content [{if | unless} ] - sc-set-gpt(,) { | } - sc-set-gpt0() { | } - send-spoe-group + - set-bandwidth-limit [limit ] [period ] - set-dst - set-dst-port - set-log-level @@ -12780,6 +12817,13 @@ tcp-request content send-spoe-group Thaction is is used to trigger sending of a group of SPOE messages. Please refer to "http-request send-spoe-group" for a complete description. +tcp-request content set-bandwidth-limit [limit ] [period ] + [ { if | unless } ] + + This action is used to enable the bandwidth limitation filter , either + on the upload or download direction depending on the filter type. Please + refer to "http-request set-bandwidth-limit" for a complete description. + tcp-request content set-dst [ { if | unless } ] tcp-request content set-dst-port [ { if | unless } ] @@ -13147,6 +13191,7 @@ tcp-response content [{if | unless} ] - sc-set-gpt(,) { | } - sc-set-gpt0() { | } - send-spoe-group + - set-bandwidth-limit [limit ] [period ] - set-log-level - set-mark - set-nice @@ -13224,6 +13269,14 @@ tcp-response content send-spoe-group Thaction is is used to trigger sending of a group of SPOE messages. Please refer to "http-request send-spoe-group" for a complete description. + +tcp-response content set-bandwidth-limit [limit ] [period ] + [ { if | unless } ] + + This action is used to enable the bandwidth limitation filter , either + on the upload or download direction depending on the filter type. Please + refer to "http-request set-bandwidth-limit" for a complete description. + tcp-response content set-log-level [ { if | unless } ] This action is used to set the log level of the current session. Please refer @@ -23023,6 +23076,129 @@ filter opentracing [id ] config More detailed documentation related to the operation, configuration and use of the filter can be found in the addons/ot directory. +9.7. Bandwidth limitation +-------------------------- + +filter bwlim-in default-limit default-period