ElasticPerch / epws

A fast, well-tested and widely used WebSocket implementation for Go.
BSD 2-Clause "Simplified" License
5 stars 1 forks source link

Examples to save memory using write buffer pool and freeing net.http default buffers #8

Open tebruno99 opened 1 year ago

tebruno99 commented 1 year ago

Original PR: gorilla/websocket#761 by @FMLS

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.

image

tebruno99 commented 1 year ago

Original PR comment by: @wraix https://github.com/gorilla/websocket/pull/761#issuecomment-1013114728

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

tebruno99 commented 1 year ago

Original PR comment by: @FMLS

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 see https://github.com/golang/go/issues/15735