Skip to content

Commit 80c6e24

Browse files
authored
Revert "use bigger socket buffers and optimizations on idle connections" (#129)
This reverts commit d6c790e.
1 parent fcdf38f commit 80c6e24

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

main_linux.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package main
2121
import (
2222
"syscall"
2323

24-
"github.com/dustin/go-humanize"
2524
"golang.org/x/sys/unix"
2625
)
2726

@@ -34,16 +33,9 @@ func setTCPParameters(_, _ string, c syscall.RawConn) error {
3433

3534
_ = unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
3635

37-
{
38-
// Enable big buffers
39-
_ = unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_SNDBUF, 4*humanize.MiByte)
40-
41-
_ = unix.SetsockoptInt(fd, unix.SOL_SOCKET, unix.SO_RCVBUF, 4*humanize.MiByte)
42-
}
43-
4436
// Enable TCP open
45-
// https://lwn.net/Articles/508865/ - 32k queue size.
46-
_ = syscall.SetsockoptInt(fd, syscall.SOL_TCP, unix.TCP_FASTOPEN, 32*humanize.KiByte)
37+
// https://lwn.net/Articles/508865/ - 16k queue size.
38+
_ = syscall.SetsockoptInt(fd, syscall.SOL_TCP, unix.TCP_FASTOPEN, 16*1024)
4739

4840
// Enable TCP fast connect
4941
// TCPFastOpenConnect sets the underlying socket to use
@@ -54,25 +46,6 @@ func setTCPParameters(_, _ string, c syscall.RawConn) error {
5446
// Enable TCP quick ACK, John Nagle says
5547
// "Set TCP_QUICKACK. If you find a case where that makes things worse, let me know."
5648
_ = syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, unix.TCP_QUICKACK, 1)
57-
58-
// The time (in seconds) the connection needs to remain idle before
59-
// TCP starts sending keepalive probes
60-
_ = syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPIDLE, 15)
61-
62-
// Number of probes.
63-
// ~ cat /proc/sys/net/ipv4/tcp_keepalive_probes (defaults to 9, we reduce it to 5)
64-
_ = syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPCNT, 5)
65-
66-
// Wait time after successful probe in seconds.
67-
// ~ cat /proc/sys/net/ipv4/tcp_keepalive_intvl (defaults to 75 secs, we reduce it to 15 secs)
68-
_ = syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, syscall.TCP_KEEPINTVL, 15)
69-
70-
// Set tcp user timeout in addition to the keep-alive - tcp-keepalive is not enough to close a socket
71-
// with dead end because tcp-keepalive is not fired when there is data in the socket buffer.
72-
// https://blog.cloudflare.com/when-tcp-sockets-refuse-to-die/
73-
// This is a sensitive configuration, it is better to set it to high values, > 60 secs since it can
74-
// affect clients reading data with a very slow pace (disappropriate with socket buffer sizes)
75-
_ = syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, unix.TCP_USER_TIMEOUT, 600000)
7649
})
7750
return nil
7851
}

0 commit comments

Comments
 (0)