Skip to content

Commit

Permalink
Setup: Add BBR congestion control configuration
Browse files Browse the repository at this point in the history
This commit added a feature to enable the BBR congestion control algorithm. This increases throughput of TCP connections thanks to clever engineering by Google.
  • Loading branch information
stickz committed Apr 23, 2023
1 parent 31d9a5f commit 3237afe
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ Want to specify the user and their password? And the packages to have installed?
bash <(curl -sL git.io/swizzin) --unattend qbittorrent nginx panel --user tester --pass test1234
```

Want to enable BBR Congestion Control for increased TCP throughput? Use the `--enablebbr` flag on your supported or default configuration! Optionally, combine it with the `--unattend`, `--user` and `--pass` flags above for automated setup!
```bash
bash <(curl -sL git.io/swizzin) --enablebbr
```

Want something a bit more complex, specify package install variables, don't want a super long command to type, and store the configuration? Use the `--env` flag with your custom `env` file! (see the [unattended.example.env](unattended.example.env) file for an example)
```bash
bash <(curl -sL git.io/swizzin) --env /path/to/your/env/file/here.env
Expand Down
51 changes: 51 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ function _option_parse() {
rmgrsec=yes
echo_info "OVH Kernel nuke = $rmgrsec"
;;
--enablebbr)
enablebbr=true
echo_info "Enable BBR = $enablebbr"
;;
--env)
shift
if [[ ! -f $1 ]]; then
Expand Down Expand Up @@ -221,6 +225,52 @@ function _preparation() {
echo
}

function _checkbbr() {
# If bbr is enabled through unattended setup mark it as enabled
if [[ -n $BBR_CONGESTION_CONTROL ]]; then
[[ $BBR_CONGESTION_CONTROL = "yes" ]] && enablebbr=true
fi
# If bbr is already running on the operating system, skip checks and exit function
local old_cc=$(sysctl net.ipv4.tcp_congestion_control | grep -c bbr)
if [[ $old_cc -ge 1 ]]; then
echo_info "BBR Congestion Control is already enabled, skipping BBR"
return 0
fi
# if sysctl.conf has already defined a cc or qdisc, skip checks and exit function
local sysctl_cc=$(grep -c net.ipv4.tcp_congestion_control /etc/sysctl.conf)
local sysctl_qdisc=$(grep -c net.core.default_qdisc /etc/sysctl.conf)
if [[ $sysctl_cc -ge 1 ]] || [[ $sysctl_qdisc -ge 1 ]]; then
echo_info "sysctl.conf has conflicting options, skipping BBR"
return 0
fi
# If bbr is not supported by the linux kernel, skip checks and exit function
modprobe tcp_bbr >> $log 2>&1
local availible_cc=$(sysctl net.ipv4.tcp_available_congestion_control | grep -c bbr)
if [[ $availible_cc -le 0 ]]; then
echo_info "Linux Kernel does not support BBR Congestion Control, skipping BBR"
return 0
fi
# If fq is not supported by the linux kernel, skip checks and exit function
local availible_fq=$(grep -c CONFIG_NET_SCH_FQ= /boot/config-$(uname -r))
if [[ $availible_fq -le 0 ]]; then
echo_info "Linux Kernel does not support Fair Queue Scheduler, skipping BBR"
return 0
fi
# If enablebbr was NOT set and we're not in unattended mode
if [[ $enablebbr != "true" ]] && [[ $unattend != "true" ]]; then
# Ask the user if they would like to enable bbr congestion control
if ask "Would you like to enable BBR congestion control for increased throughput?" Y; then
enablebbr=true
fi
fi
# If enablebbr is set then enable fq plus bbq and apply the changes
if [[ $enablebbr = "true" ]]; then
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p >> $log 2>&1
fi
}

#FYI code duplication from `box rmgrsec`
function _nukeovh() {
bash /etc/swizzin/scripts/nukeovh
Expand Down Expand Up @@ -404,6 +454,7 @@ _run_post() {

_os
_preparation
_checkbbr
## If install is attended, do the nice intro
if [[ $unattend != "true" ]]; then
if [[ -z "$user" ]] && [[ -z "$pass" ]]; then # If password AND username are empty
Expand Down
4 changes: 3 additions & 1 deletion unattended.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pass=test123
## packages to install separated by colons.
packages=nginx:panel:transmission:letsencrypt

## Enable BBR congestion control for increased TCP throughput
BBR_CONGESTION_CONTROL=yes

# PACKAGE SPECIFIC OPTIONS

Expand All @@ -25,4 +27,4 @@ LE_DEFAULTCONF=yes
# LE_BOOL_CF=no if you don't want to use any cloudflare
LE_CF_API=aaapppiiiikkkeeeeeyyyyyyyy
LE_CF_EMAIL="[email protected]"
LE_CF_ZONE="some.zone.asdasdasdasd" # or LE_CF_ZONEEXISTS=yes if you don't need it created
LE_CF_ZONE="some.zone.asdasdasdasd" # or LE_CF_ZONEEXISTS=yes if you don't need it created

0 comments on commit 3237afe

Please sign in to comment.