mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Use deferred accept in reuseport.Listener. This should reduce the number of context switches for busy servers accepting a lot of new connections per second. Will test it, since google says TCP_DEFER_ACCEPT option is useless :)
This commit is contained in:
@@ -72,6 +72,11 @@ func Listen(network, addr string) (l net.Listener, err error) {
|
||||
return nil, &ErrNoReusePort{err}
|
||||
}
|
||||
|
||||
if err = setTCPDeferAccept(fd); err != nil {
|
||||
syscall.Close(fd)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = syscall.Bind(fd, sockaddr); err != nil {
|
||||
syscall.Close(fd)
|
||||
return nil, err
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
package reuseport
|
||||
|
||||
import "syscall"
|
||||
|
||||
var reusePort = syscall.SO_REUSEPORT
|
||||
|
||||
func setTCPDeferAccept(fd int) error {
|
||||
// BSD supports similar SO_ACCEPTFILTER option, but I have no access
|
||||
// to BSD at the moment for proper implementation.
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
// +build linux
|
||||
|
||||
package reuseport
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var reusePort = 0x0F
|
||||
|
||||
func setTCPDeferAccept(fd int) error {
|
||||
return syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.TCP_DEFER_ACCEPT, 2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user