浏览代码

Use TCP BBR in a best-effort mode

This small commits conditionally sets TCP BBR as a preferrable algorithm
for TCP congestion control
tags/v2.2.8^2^2
9seconds 4 周前
父节点
当前提交
88f33debab
共有 3 个文件被更改,包括 28 次插入0 次删除
  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 查看文件

28
 		return fmt.Errorf("cannot setup SO_REUSEADDR/PORT: %w", err)
28
 		return fmt.Errorf("cannot setup SO_REUSEADDR/PORT: %w", err)
29
 	}
29
 	}
30
 
30
 
31
+	setCongestionControl(rawConn)
32
+
31
 	return nil
33
 	return nil
32
 }
34
 }

+ 19
- 0
network/v2/sockopts_linux.go 查看文件

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 查看文件

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

正在加载...
取消
保存