Skip to content

Raw performance drops by ~25% when using timeouts #626

@cipriancraciun

Description

@cipriancraciun

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions