websocket icon indicating copy to clipboard operation
websocket copied to clipboard

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

Open FMLS opened this issue 4 years ago • 2 comments

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 avatar Jan 09 '22 09:01 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?

A Million WebSockets and Go

wraix avatar Jan 14 '22 13:01 wraix

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

FMLS avatar Jan 15 '22 14:01 FMLS