-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Correct way to save memory using write buffer pool and freeing net.http default buffers #761
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FMLS
changed the title
Add an example that uses the write buffer pool
Correct way to save memory using write buffer pool and freeing net.http default buffers
Jan 12, 2022
Maybe the ideas posted here could be reflected to get even better at large volume connection handling or at least give the options to? |
yes, it's a good idea in this blog, but golang did not provide a suitable mechanism now |
This was referenced Dec 13, 2022
coreydaley
approved these changes
Aug 17, 2023
twnesss
pushed a commit
to twnesss/websocket
that referenced
this pull request
Aug 29, 2023
…tp default buffers (gorilla#761) **Summary of Changes** 1. Add an example that uses the write buffer pool The loop process of the websocket connection is inner the http handler at existing examples, This usage will cause the 8k buffer(4k read buffer + 4k write buffer) allocated by net.http can't be GC(Observed by heap profiling, see picture below) . The purpose of saving memory is not achieved even if the WriteBufferPool is used. In example bufferpool, server process websocket connection in a new goroutine, and the goroutine created by the net.http will exit, then the 8k buffer will be GC. ![heap](https://user-images.githubusercontent.com/12793501/148676918-872d1a6d-ce10-4146-ba01-7de114db09f5.png) Co-authored-by: hakunaliu <[email protected]> Co-authored-by: Corey Daley <[email protected]>
nono
referenced
this pull request
in cozy/cozy-stack
Nov 6, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/gorilla/websocket](https://github.com/gorilla/websocket) | require | patch | `v1.5.0` -> `v1.5.1` | --- ### Release Notes <details> <summary>gorilla/websocket (github.com/gorilla/websocket)</summary> ### [`v1.5.1`](https://github.com/gorilla/websocket/releases/tag/v1.5.1) [Compare Source](https://github.com/gorilla/websocket/compare/v1.5.0...v1.5.1) #### What's Changed - Add check for Sec-WebSocket-Key header by [@​hirasawayuki](https://github.com/hirasawayuki) in [https://github.com/gorilla/websocket/pull/752](https://github.com/gorilla/websocket/pull/752) - Changed the method name UnderlyingConn to NetConn by [@​JWSong](https://github.com/JWSong) in [https://github.com/gorilla/websocket/pull/773](https://github.com/gorilla/websocket/pull/773) - remove all versions < 1.16 and add 1.18 by [@​ChannyClaus](https://github.com/ChannyClaus) in [https://github.com/gorilla/websocket/pull/793](https://github.com/gorilla/websocket/pull/793) - Check for and report bad protocol in TLSClientConfig.NextProtos by [@​ChannyClaus](https://github.com/ChannyClaus) in [https://github.com/gorilla/websocket/pull/788](https://github.com/gorilla/websocket/pull/788) - check err before GotConn for trace by [@​junnplus](https://github.com/junnplus) in [https://github.com/gorilla/websocket/pull/798](https://github.com/gorilla/websocket/pull/798) - Update README.md by [@​coreydaley](https://github.com/coreydaley) in [https://github.com/gorilla/websocket/pull/839](https://github.com/gorilla/websocket/pull/839) - Correct way to save memory using write buffer pool and freeing net.http default buffers by [@​FMLS](https://github.com/FMLS) in [https://github.com/gorilla/websocket/pull/761](https://github.com/gorilla/websocket/pull/761) - Update go version & add verification/testing tools by [@​coreydaley](https://github.com/coreydaley) in [https://github.com/gorilla/websocket/pull/840](https://github.com/gorilla/websocket/pull/840) - update golang.org/x/net by [@​coreydaley](https://github.com/coreydaley) in [https://github.com/gorilla/websocket/pull/856](https://github.com/gorilla/websocket/pull/856) - update GitHub workflows by [@​coreydaley](https://github.com/coreydaley) in [https://github.com/gorilla/websocket/pull/857](https://github.com/gorilla/websocket/pull/857) #### New Contributors - [@​hirasawayuki](https://github.com/hirasawayuki) made their first contribution in [https://github.com/gorilla/websocket/pull/752](https://github.com/gorilla/websocket/pull/752) - [@​JWSong](https://github.com/JWSong) made their first contribution in [https://github.com/gorilla/websocket/pull/773](https://github.com/gorilla/websocket/pull/773) - [@​ChannyClaus](https://github.com/ChannyClaus) made their first contribution in [https://github.com/gorilla/websocket/pull/793](https://github.com/gorilla/websocket/pull/793) - [@​junnplus](https://github.com/junnplus) made their first contribution in [https://github.com/gorilla/websocket/pull/798](https://github.com/gorilla/websocket/pull/798) - [@​coreydaley](https://github.com/coreydaley) made their first contribution in [https://github.com/gorilla/websocket/pull/839](https://github.com/gorilla/websocket/pull/839) - [@​FMLS](https://github.com/FMLS) made their first contribution in [https://github.com/gorilla/websocket/pull/761](https://github.com/gorilla/websocket/pull/761) **Full Changelog**: gorilla/websocket@v1.5.0...v1.5.1 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 6am on Monday" in timezone Europe/Paris, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/cozy/cozy-stack). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMS41IiwidXBkYXRlZEluVmVyIjoiMzcuMzEuNSIsInRhcmdldEJyYW5jaCI6Im1hc3RlciJ9-->
algitbot
pushed a commit
to alpinelinux/build-server-status
that referenced
this pull request
May 5, 2024
This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/gorilla/websocket](https://github.com/gorilla/websocket) | require | patch | `v1.5.0` -> `v1.5.1` | --- ### Release Notes <details> <summary>gorilla/websocket (github.com/gorilla/websocket)</summary> ### [`v1.5.1`](https://github.com/gorilla/websocket/releases/tag/v1.5.1) [Compare Source](gorilla/websocket@v1.5.0...v1.5.1) #### What's Changed - Add check for Sec-WebSocket-Key header by [@​hirasawayuki](https://github.com/hirasawayuki) in gorilla/websocket#752 - Changed the method name UnderlyingConn to NetConn by [@​JWSong](https://github.com/JWSong) in gorilla/websocket#773 - remove all versions < 1.16 and add 1.18 by [@​ChannyClaus](https://github.com/ChannyClaus) in gorilla/websocket#793 - Check for and report bad protocol in TLSClientConfig.NextProtos by [@​ChannyClaus](https://github.com/ChannyClaus) in gorilla/websocket#788 - check err before GotConn for trace by [@​junnplus](https://github.com/junnplus) in gorilla/websocket#798 - Update README.md by [@​coreydaley](https://github.com/coreydaley) in gorilla/websocket#839 - Correct way to save memory using write buffer pool and freeing net.http default buffers by [@​FMLS](https://github.com/FMLS) in gorilla/websocket#761 - Update go version & add verification/testing tools by [@​coreydaley](https://github.com/coreydaley) in gorilla/websocket#840 - update golang.org/x/net by [@​coreydaley](https://github.com/coreydaley) in gorilla/websocket#856 - update GitHub workflows by [@​coreydaley](https://github.com/coreydaley) in gorilla/websocket#857 #### New Contributors - [@​hirasawayuki](https://github.com/hirasawayuki) made their first contribution in gorilla/websocket#752 - [@​JWSong](https://github.com/JWSong) made their first contribution in gorilla/websocket#773 - [@​ChannyClaus](https://github.com/ChannyClaus) made their first contribution in gorilla/websocket#793 - [@​junnplus](https://github.com/junnplus) made their first contribution in gorilla/websocket#798 - [@​coreydaley](https://github.com/coreydaley) made their first contribution in gorilla/websocket#839 - [@​FMLS](https://github.com/FMLS) made their first contribution in gorilla/websocket#761 **Full Changelog**: gorilla/websocket@v1.5.0...v1.5.1 </details> --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yODYuMSIsInVwZGF0ZWRJblZlciI6IjM3LjI4Ni4xIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=--> See merge request alpine/infra/build-server-status!9
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of Changes
The loop process of the websocket connection is inner the http handler at existing examples, This usage will cause the 8k buffer(4k read buffer + 4k write buffer) allocated by net.http can't be GC(Observed by heap profiling, see picture below) . The purpose of saving memory is not achieved even if the WriteBufferPool is used.
In example bufferpool, server process websocket connection in a new goroutine, and the goroutine created by the net.http will exit, then the 8k buffer will be GC.