通過 TCPBBR 擁塞控制提高 Linux 互聯網速度


一代 最近 TCP BBR 顯著提高了 Google 內部骨幹網絡與 google.com 和 YouTube 網絡服務器之間連接的吞吐量並減少了延遲。全球平均吞吐量增長了 4%,在某些國家/地區增長了 14% 以上。 您需要將 TCPBBR 補丁應用到 Linux 內核。 BBR 的第一個公開版本於 2016 年 9 月在這裡發布。任何人都可以下載並安裝補丁。另一種選擇是使用谷歌云平台(GCP)。 GCP 默認開啟,並使用最先進的新擁塞控制算法 TCPBBR。本頁介紹如何使用 TCPBBR 配置來提高 Linux 服務器的 Internet 速度。這種簡單的設置可以提高網絡性能。

使用 TCPBBR 的 Linux 服務器的 Internet 速度要求

確保 Linux 內核將以下選項編譯為模塊或內置到 Linux 內核中。

  1. CONFIG_TCP_CONG_BBR
  2. CONFIG_NET_SCH_FQ

LinuxTCPBBR擁塞控制

您必須使用 Linux 內核版本 4.9 或更高版本。 在 Debian / Ubuntu Linux 上輸入以下 grep / egrep 命令。
$ grep 'CONFIG_TCP_CONG_BBR' /boot/config-$(uname -r)
$ grep 'CONFIG_NET_SCH_FQ' /boot/config-$(uname -r)
$ egrep 'CONFIG_TCP_CONG_BBR|CONFIG_NET_SCH_FQ' /boot/config-$(uname -r)

樣本輸出:

我在 Debian 上使用 Linux 內核版本 4.9.0-8-amd64,在 Ubuntu 服務器上使用 4.18.0-15-generic。如果沒有找到以上選項,需要使用apt-get命令/apt命令編譯最新內核或者安裝最新版本的Linux內核。

在啟用 TCP BBR 之前運行測試以提高網絡速度

在您的 Linux 服務器上輸入以下命令:
# iperf -s

在 Linux 客戶端上執行以下步驟。
$ iperf -c gcvm.backup -i 2 -t 30
如何使用 TCPBBR 提高 Linux 服務器的 Internet 速度

如何在 Linux 上啟用 TCPBBR 擁塞控制

編輯 /etc/sysctl.conf 文件或在 /etc/sysctl.d/ 目錄中創建一個新文件。
$ sudo vi /etc/sysctl.conf


$ sudo vi /etc/sysctl.d/10-custom-kernel-bbr.conf

添加以下兩行。
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr

要保存並關閉文件並退出 vim/vi 文本編輯器,請鍵入: : X!然後您需要重新啟動 Linux 機器或使用 sysctl 命令重新加載您的更改。
$ sudo reboot


$ sudo sysctl --system

樣本輸出:

* Applying /etc/sysctl.d/10-console-messages.conf ...
kernel.printk = 4 4 1 7
* Applying /etc/sysctl.d/10-custom.conf ...
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
* Applying /etc/sysctl.d/10-ipv6-privacy.conf ...
net.ipv6.conf.all.use_tempaddr = 2
net.ipv6.conf.default.use_tempaddr = 2
* Applying /etc/sysctl.d/10-kernel-hardening.conf ...
kernel.kptr_restrict = 1
* Applying /etc/sysctl.d/10-link-restrictions.conf ...
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/10-lxd-inotify.conf ...
fs.inotify.max_user_instances = 1024
* Applying /etc/sysctl.d/10-magic-sysrq.conf ...
kernel.sysrq = 176
* Applying /etc/sysctl.d/10-network-security.conf ...
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.tcp_syncookies = 1
* Applying /etc/sysctl.d/10-ptrace.conf ...
kernel.yama.ptrace_scope = 1
* Applying /etc/sysctl.d/10-zeropage.conf ...
vm.mmap_min_addr = 65536
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.conf ...

您可以使用以下 sysctl 命令檢查新設置。跑:
$ sysctl net.core.default_qdisc
net.core.default_qdisc = fq
$ sysctl net.ipv4.tcp_congestion_control
net.ipv4.tcp_congestion_control = bbr

Linux上的BBR擁塞控制測試

當在兩個具有連接互聯網的千兆端口的遠程 Linux 服務器之間進行測試時,我們能夠從 250 Mbit / s 獲得高達 800 Mbit / s 的速度。 您可以使用 wget 命令等工具測量帶寬速度。
$ wget https://your-server-ip/file.iso

我們還注意到 OpenVPN 的流量可以達到接近 100 Mbit / s。以前,您最多只能推送 30-40 Mbit / s。總的來說,我對我的 Linux 機器上的 TCPBBR 擁塞控制選項非常滿意。

使用 iperf 進行 Linux TCP BBR 測試

iperf 是一款常用的 TCP/UDP 數據流網絡測試工具。測量網絡吞吐量。這個工具可以確認 Linux TCP BBR 設置的重要性。

在啟用 TCPBBR 擁塞控制的 Linux 服務器上輸入命令

# iperf -s

樣本輸出:

------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 10.128.0.2 port 5001 connected with AAA.BB.C.DDD port 46978
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-30.6 sec   127 MBytes  34.7 Mbits/sec

在 Linux / Unix 客戶端上輸入命令

$ iperf -c YOUR-Linux-Server-IP-HERE -i 2 -t 30

連接到 Linux 上啟用的 TCPBBR 擁塞時的示例輸出:

------------------------------------------------------------
Client connecting to gcp-vm-nginx-www1, TCP port 5001
TCP window size: 45.0 KByte (default)
------------------------------------------------------------
[  3] local 10.8.0.2 port 46978 connected with xx.yyy.zzz.tt port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 2.0 sec  4.00 MBytes  16.8 Mbits/sec
[  3]  2.0- 4.0 sec  8.50 MBytes  35.7 Mbits/sec
[  3]  4.0- 6.0 sec  10.9 MBytes  45.6 Mbits/sec
[  3]  6.0- 8.0 sec  16.2 MBytes  68.2 Mbits/sec
[  3]  8.0-10.0 sec  5.29 MBytes  22.2 Mbits/sec
[  3] 10.0-12.0 sec  9.38 MBytes  39.3 Mbits/sec
[  3] 12.0-14.0 sec  8.12 MBytes  34.1 Mbits/sec
[  3] 14.0-16.0 sec  8.12 MBytes  34.1 Mbits/sec
[  3] 16.0-18.0 sec  8.38 MBytes  35.1 Mbits/sec
[  3] 18.0-20.0 sec  6.75 MBytes  28.3 Mbits/sec
[  3] 20.0-22.0 sec  8.12 MBytes  34.1 Mbits/sec
[  3] 22.0-24.0 sec  8.12 MBytes  34.1 Mbits/sec
[  3] 24.0-26.0 sec  9.50 MBytes  39.8 Mbits/sec
[  3] 26.0-28.0 sec  7.00 MBytes  29.4 Mbits/sec
[  3] 28.0-30.0 sec  8.12 MBytes  34.1 Mbits/sec
[  3]  0.0-30.3 sec   127 MBytes  35.0 Mbits/sec

結論是

在瓶頸帶寬和 RTT (BBR) 擁塞控制之前和之後,使用 iperf 命令收集了 30 秒的平均統計數據。

  1. PRE BBR:傳輸:27.5MB。帶寬:7.15 兆比特/秒
  2. 發布 BBR:傳輸:127MB。帶寬:35.0 兆比特/秒

在我看來,BBR 是近年來 Linux 網絡棧最重要的改進之一。此頁面顯示如何在基於 Linux 的系統上啟用和設置 BBR。有關詳細信息,請參閱下一頁。

  • 網絡性能測量:使用 Iperf 檢測帶寬、抖動和數據報丟失
  • BBR 信息來自 谷歌
  • TCPBBR 擁塞控制是在 GCP 中引入的。你的互聯網只是 趕快