-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
I've observed that by just enabling ReadTimeout, WriteTimeout and IdleTimeout the raw performance drops about 25%.
I've tested it on a "dummy" server using fasthttp:
https://github.com/volution/kawipiko/blob/c78613fbf7b81782c0ab9bbb363312d19086d346/sources/cmd/server-dummy.go#L45-L47
By just enabling or disabling those three lines the performance changes.
(I'm using the latest Go 1.12 on Linux 64bit and the latest fasthttp code.)
I understand that the underlying issue is the SetDeadline implementation of net.Conn, and I've even found a Go issue (to which @valyala participated) on this topic:
golang/go#25729
However that issue was closed, but the actual problem still persists.
Could we perhaps implement an "alternative" timeout solution, perhaps something on the lines: for each connection we keep an "last touched" timestamp (updated each time we fully read a request, or write a response), and we have a background goroutine that checks these timeouts, and if they have been overrun we just c.Close() the connection.
It won't be as precise as using c.SetDeadline, however it can remove "dead" connections, or "slow-loris" attacks.