websocket/examples/bufferpool
LiuYang 80393295c1
Correct way to save memory using write buffer pool and freeing net.http default buffers (#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>
2023-08-17 11:25:09 -04:00
..
client.go Correct way to save memory using write buffer pool and freeing net.http default buffers (#761) 2023-08-17 11:25:09 -04:00
server.go Correct way to save memory using write buffer pool and freeing net.http default buffers (#761) 2023-08-17 11:25:09 -04:00