Browse Source

Merge pull request #452 from 9seconds/tcp-bbr

Use TCP BBR in a best-effort mode
tags/v2.2.8^2^2
Sergei Arkhipov 4 weeks ago
parent
commit
60ab083def
No account linked to committer's email address
3 changed files with 28 additions and 0 deletions
  1. 2
    0
      network/v2/sockopts.go
  2. 19
    0
      network/v2/sockopts_linux.go
  3. 7
    0
      network/v2/sockopts_nolinux.go

+ 2
- 0
network/v2/sockopts.go View File

@@ -23,5 +23,7 @@ func setCommonSocketOptions(conn *net.TCPConn, keepAliveConfig net.KeepAliveConf
23 23
 		return fmt.Errorf("cannot setup SO_REUSEADDR/PORT: %w", err)
24 24
 	}
25 25
 
26
+	setCongestionControl(rawConn)
27
+
26 28
 	return nil
27 29
 }

+ 19
- 0
network/v2/sockopts_linux.go View File

@@ -0,0 +1,19 @@
1
+//go:build linux
2
+
3
+package network
4
+
5
+import (
6
+	"syscall"
7
+
8
+	"golang.org/x/sys/unix"
9
+)
10
+
11
+func setCongestionControl(conn syscall.RawConn) {
12
+	conn.Control(func(fd uintptr) { //nolint: errcheck
13
+		// BBR provides better throughput over lossy and high-latency links compared
14
+		// to the default cubic, which is especially beneficial for mobile and
15
+		// home internet clients. This is best-effort: silently ignored if the
16
+		// kernel does not have tcp_bbr available.
17
+		unix.SetsockoptString(int(fd), unix.IPPROTO_TCP, unix.TCP_CONGESTION, "bbr") //nolint: errcheck
18
+	})
19
+}

+ 7
- 0
network/v2/sockopts_nolinux.go View File

@@ -0,0 +1,7 @@
1
+//go:build !linux
2
+
3
+package network
4
+
5
+import "syscall"
6
+
7
+func setCongestionControl(conn syscall.RawConn) {}

Loading…
Cancel
Save