Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize server connection close logic #1310

Merged
merged 3 commits into from Jun 5, 2022

Conversation

stokito
Copy link
Contributor

@stokito stokito commented Jun 4, 2022

The PR simplifies and slightly improves performance of "Connection: close" header.
Please see commit comments

stokito added 3 commits Jun 4, 2022
Inline isHTTP11 var.
Use direct Header.SetConnectionClose() and Header.ConnectionClose()
The SetCanonical(strConnection, strClose) call internally will anyway call SetConnectionClose().
The "Connection: close" will be printed in the ResponseHeader.AppendBytes()
The conn limit check merged into connectionClose evaluation.
This improves performance for most cases:
1. If the connectionClose already true then the conn limit check won't be performed.
2. The SetConnectionClose() was duplicated
3. First check conn limit and only then check for resp.connClose because most users don't close conns manually.
4. We may optimize more: If the resp.connClose = true then SetConnectionClose() not needed but as mentioned above this is a rare case.
@erikdubbelboer erikdubbelboer merged commit de18824 into valyala:master Jun 5, 2022
14 checks passed
@erikdubbelboer
Copy link
Collaborator

erikdubbelboer commented Jun 5, 2022

Thanks!

@stokito stokito deleted the set_sys_header branch Jun 5, 2022
bbenzikry pushed a commit to bbenzikry/fasthttp that referenced this issue Sep 11, 2022
* server.go Make code more clear

Inline isHTTP11 var.
Use direct Header.SetConnectionClose() and Header.ConnectionClose()

* server.go Use direct SetConnectionClose()

The SetCanonical(strConnection, strClose) call internally will anyway call SetConnectionClose().
The "Connection: close" will be printed in the ResponseHeader.AppendBytes()

* server.go Simplify connectionClose evaluation

The conn limit check merged into connectionClose evaluation.
This improves performance for most cases:
1. If the connectionClose already true then the conn limit check won't be performed.
2. The SetConnectionClose() was duplicated
3. First check conn limit and only then check for resp.connClose because most users don't close conns manually.
4. We may optimize more: If the resp.connClose = true then SetConnectionClose() not needed but as mentioned above this is a rare case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants