From 5be4096452ea258c36679e8571fb9708f0ff1df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Wed, 5 Feb 2020 14:00:41 +0000 Subject: [PATCH] Add a stupid dynamic rate limiter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- mud.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mud.c b/mud.c index 03b6e7e..e93d4c1 100644 --- a/mud.c +++ b/mud.c @@ -1204,11 +1204,7 @@ mud_update_window(struct mud *mud, struct mud_path *path, uint64_t now, uint64_t rx_dt, uint64_t rx_bytes, uint64_t rx_pkt) { if (rx_dt && rx_dt > tx_dt + (tx_dt >> 3)) { - if (!path->conf.fixed_rate) { - path->tx.rate = 1 + ((rx_bytes * MUD_ONE_SEC) - 1) / rx_dt; - if (path->tx.rate > path->conf.tx_max_rate) - path->tx.rate = path->conf.tx_max_rate; - } + path->tx.rate = (7 * rx_bytes * MUD_ONE_SEC) / (8 * rx_dt); } else { uint64_t tx_acc = path->msg.tx.acc + tx_pkt; uint64_t rx_acc = path->msg.rx.acc + rx_pkt; @@ -1223,7 +1219,13 @@ mud_update_window(struct mud *mud, struct mud_path *path, uint64_t now, path->msg.tx.acc = tx_acc; path->msg.rx.acc = rx_acc; } + + if (!path->conf.fixed_rate) + path->tx.rate += path->tx.rate / 10; } + + if (path->tx.rate > path->conf.tx_max_rate) + path->tx.rate = path->conf.tx_max_rate; } static void