站点图标 谷姐靓号网

Debian 9/10 开启 Google TCP BBR 有效提升访问速度

Rate this post

黑五买了几个新的小鸡,为了测性能,试着在Debian 9/10上开启下Google TCP BBR,发现效果挺明显的,特记录一下。其他系统待测。

一、什么是BBR?BBR的好处?

BBR是Google提出的一种TCP拥塞(数据包丢失)控制机制,源码在Github上开源。 TCP拥塞控制机制是基于损耗的拥塞控制机制,直白地说,当瓶颈缓冲区较小时,它会将吞吐量降低;而瓶颈缓冲区较大时,它会将吞吐量增大。其实有多种可用的TCP拥塞控制机制(例如Reno和Cubic等),Google BBR只是其中之一。

相比于其他几个拥塞控制算法,BBR可以有效优化网络传输性能,提升访问服务器速度
Google Cloud Platform GCP使用BBR,允许应用程序以闪电般的速度访问其云服务;
YouTube之类的Google服务使用了BBR,可以使得用户从YouTube获得更好的体验;
我们自己服务器安装/开启BBR后,可以使得服务器上的网站或节点被更快地访问...

二、如何安装/开启 BBR

目前,只能在Linux操作系统中启用Google BBR。 如果Linux系统的内核是4.9或更高版本,则可以启用BBR:默认情况下,系统使用Reno和Cubic,但是内核还包括Google BBR算法,可以手动启用。如果Linux系统的内核低于4.9,可以将内核升级到4.9再开启BBR。这里系统是Debian 9/10,直接开启BBR即可。

查看系统当前的TCP拥塞控制算法

1. 运行

sysctl net.ipv4.tcp_congestion_control

输出

net.ipv4.tcp_congestion_control = cubic

2. 运行

sysctl net.ipv4.tcp_available_congestion_control

输出

net.ipv4.tcp_available_congestion_control = reno cubic

可以看出,系统使用的TCP拥塞控制算法是Reno和Cubic,其中默认的是Cubic

开启BBR

命令行依次输入

grep -qxF 'net.core.default_qdisc=fq' /etc/sysctl.conf || echo 'net.core.default_qdisc=fq' >> /etc/sysctl.conf
grep -qxF 'net.ipv4.tcp_congestion_control=bbr' /etc/sysctl.conf || echo 'net.ipv4.tcp_congestion_control=bbr' >> /etc/sysctl.conf
sysctl -p

如果配置文件中不存在以上相关配置,则新增。其中-q表示静默方式查找,-x表示匹配整行...
如果提示

sysctl: setting key "net.ipv4.tcp_congestion_control": No such file or directory

说明内核中没有bbr,检查系统内核是否高于4.9哦

验证BBR是否开启成功

命令行输入

sysctl net.ipv4.tcp_congestion_control

如果输出

net.ipv4.tcp_congestion_control = bbr

即表示BBR开启成功。

三、开启前后效果对比

这里跑了下superbench脚本
wget -qO- https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | sudo bash

VirMach VPS

VirMach Los Angeles启用BBR之前

----------------------------------------------------------------------
 Superbench.sh -- https://www.oldking.net/350.html
 Mode  : Standard    Version : 1.1.7
 Usage : wget -qO- sb.oldking.net | bash
----------------------------------------------------------------------
 CPU Model            : QEMU Virtual CPU version (cpu64-rhel6)
 CPU Cores            : 2 Cores 2499.998 MHz x86_64
 CPU Cache            : 4096 KB 
 OS                   : Debian GNU/Linux 10 (64 Bit) KVM
 Kernel               : 4.19.0-6-amd64
 Total Space          : 1.1 GB / 45.0 GB 
 Total RAM            : 53 MB / 1869 MB (367 MB Buff)
 Total SWAP           : 0 MB / 255 MB
 Uptime               : 0 days 15 hour 7 min
 Load Average         : 0.00, 0.00, 0.00
 TCP CC               : cubic
 ASN & ISP            : AS36352, ColoCrossing
 Organization         : Virtual Machine Solutions LLC
 Location             : Los Angeles, United States / US
 Region               : California
----------------------------------------------------------------------
 I/O Speed( 1.0GB )   : 409 MB/s
 I/O Speed( 1.0GB )   : 411 MB/s
 I/O Speed( 1.0GB )   : 463 MB/s
 Average I/O Speed    : 427.7 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    895.12 Mbit/s     409.90 Mbit/s       (*)60.11 ms 
 Fast.com         0.00 Mbit/s       154.1 Mbit/s        -           
 Nanjing 5G   CT  176.96 Mbit/s     1865.96 Mbit/s      135.78 ms   
 Hefei 5G     CT  0.49 Mbit/s       54.33 Mbit/s        153.14 ms   
 Guangzhou 5G CT  0.14 Mbit/s       1169.21 Mbit/s      175.24 ms   
 TianJin 5G   CU  0.38 Mbit/s       37.82 Mbit/s        369.61 ms   
 Shanghai 5G  CU  0.21 Mbit/s       1322.17 Mbit/s      254.40 ms   
 Guangzhou 5G CU  FAILED Mbit/s     294.15 Mbit/s       322.03 ms   
 Tianjin 5G   CM  0.24 Mbit/s       565.61 Mbit/s       253.24 ms   
 Hefei 5G     CM  0.35 Mbit/s       707.64 Mbit/s       205.84 ms   
 Changsha 5G  CM  0.92 Mbit/s       621.04 Mbit/s       213.99 ms   
----------------------------------------------------------------------
 Finished in  : 6 min 28 sec
 Timestamp    : 2020-12-16 22:47:16 GMT+8
 Results      : ./superbench.log

VirMach Los Angeles启用BBR之后

----------------------------------------------------------------------
 Superbench.sh -- https://www.oldking.net/350.html
 Mode  : Standard    Version : 1.1.7
 Usage : wget -qO- sb.oldking.net | bash
----------------------------------------------------------------------
 CPU Model            : QEMU Virtual CPU version (cpu64-rhel6)
 CPU Cores            : 2 Cores 2499.998 MHz x86_64
 CPU Cache            : 4096 KB 
 OS                   : Debian GNU/Linux 10 (64 Bit) KVM
 Kernel               : 4.19.0-6-amd64
 Total Space          : 1.1 GB / 45.0 GB 
 Total RAM            : 57 MB / 1869 MB (377 MB Buff)
 Total SWAP           : 0 MB / 255 MB
 Uptime               : 0 days 15 hour 20 min
 Load Average         : 0.05, 0.06, 0.02
 TCP CC               : bbr
 ASN & ISP            : AS36352, ColoCrossing
 Organization         : Virtual Machine Solutions LLC
 Location             : Los Angeles, United States / US
 Region               : California
----------------------------------------------------------------------
 I/O Speed( 1.0GB )   : 511 MB/s
 I/O Speed( 1.0GB )   : 391 MB/s
 I/O Speed( 1.0GB )   : 478 MB/s
 Average I/O Speed    : 460.0 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    687.04 Mbit/s     385.34 Mbit/s       (*)55.80 ms 
 Fast.com         0.00 Mbit/s       137.0 Mbit/s        -           
 Nanjing 5G   CT  283.86 Mbit/s     1810.37 Mbit/s      137.77 ms   
 Hefei 5G     CT  28.39 Mbit/s      71.54 Mbit/s        162.99 ms   
 Guangzhou 5G CT  0.34 Mbit/s       36.96 Mbit/s        170.26 ms   
 TianJin 5G   CU  0.74 Mbit/s       0.40 Mbit/s         286.44 ms   
 Shanghai 5G  CU  10.50 Mbit/s      1616.95 Mbit/s      232.41 ms   
 Tianjin 5G   CM  11.46 Mbit/s      593.42 Mbit/s       234.04 ms   
----------------------------------------------------------------------
 Finished in  : 4 min 45 sec
 Timestamp    : 2020-12-16 22:58:37 GMT+8
 Results      : ./superbench.log

Oracle VPS

Oracle San Jose启用BBR之前

----------------------------------------------------------------------
 Superbench.sh -- https://www.oldking.net/350.html
 Mode  : Standard    Version : 1.1.7
 Usage : wget -qO- sb.oldking.net | bash
----------------------------------------------------------------------
 CPU Model            : AMD EPYC 7551 32-Core Processor
 CPU Cores            : 2 Cores 1996.248 MHz x86_64
 CPU Cache            : 512 KB 
 OS                   : Ubuntu 20.04.1 LTS (64 Bit) KVM
 Kernel               : 5.4.0-1029-oracle
 Total Space          : 6.0 GB / 45.3 GB 
 Total RAM            : 261 MB / 976 MB (572 MB Buff)
 Total SWAP           : 396 MB / 1024 MB
 Uptime               : 13 days 3 hour 56 min
 Load Average         : 0.61, 0.19, 0.05
 TCP CC               : cubic
 ASN & ISP            : AS31898, Oracle Corporation
 Organization         : Oracle Cloud Infrastructure (us-sanjose-1)
 Location             : San Jose, United States / US
 Region               : California
----------------------------------------------------------------------
 I/O Speed( 1.0GB )   : 54.7 MB/s
 I/O Speed( 1.0GB )   : 51.0 MB/s
 I/O Speed( 1.0GB )   : 51.0 MB/s
 Average I/O Speed    : 52.2 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    46.34 Mbit/s      46.38 Mbit/s        1.72 ms     
 Fast.com         0.00 Mbit/s       46.4 Mbit/s         -           
 Nanjing 5G   CT  46.37 Mbit/s      48.64 Mbit/s        151.51 ms   
 Hefei 5G     CT  0.62 Mbit/s       48.21 Mbit/s        152.18 ms   
 Guangzhou 5G CT  0.24 Mbit/s       28.06 Mbit/s        184.97 ms   
 TianJin 5G   CU  2.75 Mbit/s       50.35 Mbit/s        184.95 ms   
 Shanghai 5G  CU  1.67 Mbit/s       41.87 Mbit/s        218.46 ms   
 Guangzhou 5G CU  0.98 Mbit/s       7.93 Mbit/s         323.18 ms   
 Tianjin 5G   CM  0.41 Mbit/s       50.66 Mbit/s        239.03 ms   
 Nanjing 5G   CM  FAILED Mbit/s     21.55 Mbit/s        275.89 ms   
 Hefei 5G     CM  1.05 Mbit/s       8.68 Mbit/s         202.29 ms   
 Changsha 5G  CM  4.19 Mbit/s       51.99 Mbit/s        190.52 ms   
----------------------------------------------------------------------
 Finished in  : 7 min 29 sec
 Timestamp    : 2020-12-17 00:35:49 GMT+8
 Results      : ./superbench.log

Oracle San Jose启用BBR之后

----------------------------------------------------------------------
 Superbench.sh -- https://www.oldking.net/350.html
 Mode  : Standard    Version : 1.1.7
 Usage : wget -qO- sb.oldking.net | bash
----------------------------------------------------------------------
 CPU Model            : AMD EPYC 7551 32-Core Processor
 CPU Cores            : 2 Cores 1996.248 MHz x86_64
 CPU Cache            : 512 KB 
 OS                   : Ubuntu 20.04.1 LTS (64 Bit) KVM
 Kernel               : 5.4.0-1029-oracle
 Total Space          : 6.0 GB / 45.3 GB 
 Total RAM            : 212 MB / 976 MB (250 MB Buff)
 Total SWAP           : 434 MB / 1024 MB
 Uptime               : 13 days 4 hour 39 min
 Load Average         : 0.02, 0.05, 0.10
 TCP CC               : bbr
 ASN & ISP            : AS31898, Oracle Corporation
 Organization         : Oracle Cloud Infrastructure (us-sanjose-1)
 Location             : San Jose, United States / US
 Region               : California
----------------------------------------------------------------------
 I/O Speed( 1.0GB )   : 56.3 MB/s
 I/O Speed( 1.0GB )   : 51.2 MB/s
 I/O Speed( 1.0GB )   : 49.7 MB/s
 Average I/O Speed    : 52.4 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    47.30 Mbit/s      46.49 Mbit/s        0.43 ms     
 Fast.com         0.00 Mbit/s       45.8 Mbit/s         -           
 Nanjing 5G   CT  51.99 Mbit/s      48.26 Mbit/s        151.81 ms   
 Hefei 5G     CT  39.40 Mbit/s      43.81 Mbit/s        135.84 ms   
 TianJin 5G   CU  46.63 Mbit/s      29.63 Mbit/s        187.59 ms   
 Shanghai 5G  CU  48.78 Mbit/s      10.97 Mbit/s        201.08 ms   
 Guangzhou 5G CU  36.67 Mbit/s      31.43 Mbit/s        280.63 ms   
 Tianjin 5G   CM  45.91 Mbit/s      52.03 Mbit/s        224.60 ms   
 Wuxi 5G      CM  2.83 Mbit/s       34.39 Mbit/s        318.18 ms   
 Nanjing 5G   CM  1.75 Mbit/s       33.98 Mbit/s        251.54 ms   
 Hefei 5G     CM  45.97 Mbit/s      8.80 Mbit/s         201.81 ms   
 Changsha 5G  CM  46.36 Mbit/s      50.41 Mbit/s        176.72 ms   
----------------------------------------------------------------------
 Finished in  : 7 min 14 sec
 Timestamp    : 2020-12-17 01:18:40 GMT+8
 Results      : ./superbench.log

可以看出几个Upload速度,尤其是在本来就很低的线路(例如Shang CU和Tianjin CM)上有明显提升。意味着如果我们是搭建节点,那么我们使用节点的时候的本地下载速度会突破瓶颈得以提升。

四、后记

博主完全业余,仅简单记录操作过程,欢迎留言指正。另外这里测速时间刚好是晚高峰,每次结果都存在明显波动,但总体上对于瓶颈改善(或多或少)是有的,开启后的实际效果小伙伴自测!

退出移动版