From 2b8c4ced4fb613158ab440f6a926df440a5ce866 Mon Sep 17 00:00:00 2001 From: fmuratori Date: Sat, 2 Dec 2023 17:48:08 +0100 Subject: [PATCH 1/2] chore: setup env variables for tbf algorithm burst and latency configuration when using rate limit --- .env | 6 +++++- Dockerfile | 4 +++- bin/tc-common.sh | 2 +- docker-compose.yml | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.env b/.env index f76eedd..8493f92 100644 --- a/.env +++ b/.env @@ -3,4 +3,8 @@ # HTTP HTTP_BIND=127.0.0.1 -HTTP_PORT=4080 \ No newline at end of file +HTTP_PORT=4080 + +# Traffic control qdisc TRF fields +QDISC_TBF_BURST=5kb +QDISC_TBF_LATENCY=50ms \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 807f3d4..551b19e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,7 +42,9 @@ ENV DOCKER_TC_VERSION="${VERSION:-dev}" \ S6_KILL_GRACETIME=0 \ S6_KILL_FINISH_MAXTIME=0 \ S6_KEEP_ENV=1 \ - S6_BEHAVIOUR_IF_STAGE2_FAILS=2 + S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \ + QDISC_TBF_BURST=5kb \ + QDISC_TBF_LATENCY=50ms LABEL maintainer="Ɓukasz Lach " \ org.opencontainers.image.title="docker-tc" \ org.opencontainers.image.description="Docker Traffic Control" \ diff --git a/bin/tc-common.sh b/bin/tc-common.sh index 3035822..1ed44ac 100755 --- a/bin/tc-common.sh +++ b/bin/tc-common.sh @@ -24,6 +24,6 @@ qdisc_netm() { qdisc_tbf() { IF="$1" shift - tc qdisc add dev "$IF" $QDISC_HANDLE tbf burst 5kb latency 50ms $@ + tc qdisc add dev "$IF" $QDISC_HANDLE tbf burst $QDISC_TBF_BURST latency $QDISC_TBF_LATENCY $@ qdisc_next } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 67f7fe9..b01486b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,8 @@ services: environment: HTTP_BIND: "${HTTP_BIND:-127.0.0.1}" HTTP_PORT: "${HTTP_PORT:-4080}" + QDISC_TBF_BURST: "${QDISC_TBF_BURST:-5kb}" + QDISC_TBF_LATENCY: "${QDISC_TBF_LATENCY:-50ms}" network_mode: host networks: From d7b2bc32a7182a3abdf488f8ada06eec5d17d42d Mon Sep 17 00:00:00 2001 From: fmuratori Date: Sat, 2 Dec 2023 17:48:21 +0100 Subject: [PATCH 2/2] docs: update README with new rate configurable fields --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index af0cd59..75b94d3 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Docker Traffic Control recognizes the following labels: * `bit`, `kbit`, `mbit`, `gbit`, `tbit` * `bps`, `kbps`, `mbps`, `gbps`, `tbps` * to specify in IEC units, replace the SI prefix (k-, m-, g-, t-) with IEC prefix (ki-, mi-, gi- and ti-) respectively + * to configure other [rate specific parameters](https://linux.die.net/man/8/tc-tbf#:~:text=to%201mbit/s.-,Parameters,-See%20tc(8)), setup env variables `QDISC_TBF_BURST` and `QDISC_TBF_LATENCY` before running docker-tc * `com.docker-tc.delay` - length of time packets will be delayed, accepts a floating point number followed by an optional unit: * `s`, `sec`, `secs` * `ms`, `msec`, `msecs`