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

Correct way to save memory using write buffer pool and freeing net.http default buffers #761

Merged
merged 2 commits into from Aug 17, 2023

Conversation

FMLS
Copy link
Contributor

@FMLS FMLS commented Jan 9, 2022

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

@FMLS 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
@wraix
Copy link

wraix commented Jan 14, 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?

A Million WebSockets and Go

@FMLS
Copy link
Contributor Author

FMLS commented Jan 15, 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?

A Million WebSockets and Go

yes, it's a good idea in this blog, but golang did not provide a suitable mechanism now
see golang/go#15735

@coreydaley coreydaley merged commit 8039329 into gorilla:main Aug 17, 2023
2 checks passed
tearmoon pushed a commit to tearmoon/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 <hakunaliu@tencent.com>
Co-authored-by: Corey Daley <cdaley@redhat.com>
nono added a commit to cozy/cozy-stack that referenced this pull request 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://togithub.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://togithub.com/gorilla/websocket/releases/tag/v1.5.1)

[Compare
Source](https://togithub.com/gorilla/websocket/compare/v1.5.0...v1.5.1)

#### What's Changed

- Add check for Sec-WebSocket-Key header by
[@&#8203;hirasawayuki](https://togithub.com/hirasawayuki) in
[gorilla/websocket#752
- Changed the method name UnderlyingConn to NetConn by
[@&#8203;JWSong](https://togithub.com/JWSong) in
[gorilla/websocket#773
- remove all versions < 1.16 and add 1.18 by
[@&#8203;ChannyClaus](https://togithub.com/ChannyClaus) in
[gorilla/websocket#793
- Check for and report bad protocol in TLSClientConfig.NextProtos by
[@&#8203;ChannyClaus](https://togithub.com/ChannyClaus) in
[gorilla/websocket#788
- check err before GotConn for trace by
[@&#8203;junnplus](https://togithub.com/junnplus) in
[gorilla/websocket#798
- Update README.md by
[@&#8203;coreydaley](https://togithub.com/coreydaley) in
[gorilla/websocket#839
- Correct way to save memory using write buffer pool and freeing
net.http default buffers by [@&#8203;FMLS](https://togithub.com/FMLS) in
[gorilla/websocket#761
- Update go version & add verification/testing tools by
[@&#8203;coreydaley](https://togithub.com/coreydaley) in
[gorilla/websocket#840
- update golang.org/x/net by
[@&#8203;coreydaley](https://togithub.com/coreydaley) in
[gorilla/websocket#856
- update GitHub workflows by
[@&#8203;coreydaley](https://togithub.com/coreydaley) in
[gorilla/websocket#857

#### New Contributors

- [@&#8203;hirasawayuki](https://togithub.com/hirasawayuki) made their
first contribution in
[gorilla/websocket#752
- [@&#8203;JWSong](https://togithub.com/JWSong) made their first
contribution in
[gorilla/websocket#773
- [@&#8203;ChannyClaus](https://togithub.com/ChannyClaus) made their
first contribution in
[gorilla/websocket#793
- [@&#8203;junnplus](https://togithub.com/junnplus) made their first
contribution in
[gorilla/websocket#798
- [@&#8203;coreydaley](https://togithub.com/coreydaley) made their first
contribution in
[gorilla/websocket#839
- [@&#8203;FMLS](https://togithub.com/FMLS) made their first
contribution in
[gorilla/websocket#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 [@&#8203;hirasawayuki](https://github.com/hirasawayuki) in gorilla/websocket#752
-   Changed the method name UnderlyingConn to NetConn by [@&#8203;JWSong](https://github.com/JWSong) in gorilla/websocket#773
-   remove all versions < 1.16 and add 1.18 by [@&#8203;ChannyClaus](https://github.com/ChannyClaus) in gorilla/websocket#793
-   Check for and report bad protocol in TLSClientConfig.NextProtos by [@&#8203;ChannyClaus](https://github.com/ChannyClaus) in gorilla/websocket#788
-   check err before GotConn for trace by [@&#8203;junnplus](https://github.com/junnplus) in gorilla/websocket#798
-   Update README.md by [@&#8203;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 [@&#8203;FMLS](https://github.com/FMLS) in gorilla/websocket#761
-   Update go version & add verification/testing tools by [@&#8203;coreydaley](https://github.com/coreydaley) in gorilla/websocket#840
-   update golang.org/x/net by [@&#8203;coreydaley](https://github.com/coreydaley) in gorilla/websocket#856
-   update GitHub workflows by [@&#8203;coreydaley](https://github.com/coreydaley) in gorilla/websocket#857

#### New Contributors

-   [@&#8203;hirasawayuki](https://github.com/hirasawayuki) made their first contribution in gorilla/websocket#752
-   [@&#8203;JWSong](https://github.com/JWSong) made their first contribution in gorilla/websocket#773
-   [@&#8203;ChannyClaus](https://github.com/ChannyClaus) made their first contribution in gorilla/websocket#793
-   [@&#8203;junnplus](https://github.com/junnplus) made their first contribution in gorilla/websocket#798
-   [@&#8203;coreydaley](https://github.com/coreydaley) made their first contribution in gorilla/websocket#839
-   [@&#8203;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

---

&nbsp;
<!--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
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants