Improve performance, reuse server params for same connection #467
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves the HTTP server performance by reusing the socket addressses stored in the server params for the same connection. This helps avoiding unneeded
getpeername()
andgetsockname()
syscalls that show a noticeable performance impact especially during benchmark runs (see also #455). This change is somewhat similar to theClock
introduced to avoidgettimeofday()
syscalls in #457.For a single HTTP request, no syscalls can be eliminated, but for any further request over the same connection (
Connection: keep-alive
), these syscalls can be eliminated:This is especially noticeable during a benchmark run. In particular, the HTTP server may handle any number of requests over a single connection, so the socket addresses will only be checked once and reused for all following requests. Running
docker run -it --rm --net=host jordi/ab -n1000000 -c50 -k http://localhost:8080/
against the example HTTP server suggests results improved from 22624 req/s to 25301 req/s on my machine (best of 5 each).This changeset only refactors some internal logic and does not affect the public API, so it should be safe to apply. The test suite confirms this has 100% code coverage.
Together with #457, this closes #455