Correct way to save memory using write buffer pool and freeing net.http default buffers
Summary of Changes
- 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.

Maybe the ideas posted here could be reflected to get even better at large volume connection handling or at least give the options to?
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