
我的理解是 netfilter 的 hashlimit 模組應該實現漏桶演算法...我正在使用下面的 iptables 配置
iptables -A INPUT -s 207.[...] -m hashlimit --hashlimit-above 34722b/s \
--hashlimit-burst 600m --hashlimit-name hashlimitTable1 \
--hashlimit-htable-expire 604800000 -j DROP
這對於 700 MB 的單一大下載非常有效,但如果我在下載完成後等待三個小時,然後進行另一次下載,規則仍然立即匹配(無突發)並將頻寬限制為 ~34kB/s。
cat /proc/net/ipt_hashlimit/hashlimitTable1
並在第一次大量下載後檢查節目
This seems to represent the burst "bucket" size
and it does go down and reach 0 after 600 MB
have been downloaded, but it never increases
no matter how long I wait.
|
|
604555 0.0.0.0:0->0.0.0.0:0 4194304000 0 1931967
hashlimit沒有實作「漏桶」演算法嗎?還是我的配置不正確?
從man 8 iptables-extensions|grep -e 'hashlimit-burst amount' -A 7
--hashlimit-burst amount
Maximum initial number of packets to match: this number gets
recharged by one every time the limit specified above is not
reached, up to this number; the default is 5. When byte-based
rate matching is requested, this option specifies the amount of
bytes that can exceed the given rate. This option should be
used with caution -- if the entry expires, the burst value is
reset too.
這表明我的預期行為是正確的,但也許我需要確保從相反的角度匹配規則:
iptables -A INPUT -s 207.[...] -m hashlimit --hashlimit-upto 34722b/s \
--hashlimit-burst 600m --hashlimit-name hashlimitTable1 \
--hashlimit-htable-expire 604800000 -j ACCEPT;
iptables -A INPUT -s 207.[...] -j DROP;
不幸的是,這會導致完全相同的觀察到的行為,即使使用wget --limit-rate=1024 http://207.[...]/testFile.bin
以1KiBps 的低得離譜的速率下載19 分鐘以上,但令牌的最大數量永遠不會增加到零以上,並且在等待一個小時而沒有下載後,頻寬仍然受到限制至~34KBps...
我已經確認過期時間、垃圾收集間隔、htable-size 和 htable-max 對問題沒有任何影響。如果我將過期時間設定得非常短,例如 10 秒,那麼顯然它會重置突發,但這會導致違反平均頻寬。