@
ferock wss 统计在线人数,代价还是很低的,一般只是端口不够用
我之前的测试,库使用 gorilla/websocket 1 万个连接测试
占用 147.93MB RAM, 平均连接每个占用 15kb 测试代码见:[github gwebsocket](
https://github.com/douyacun/gwebsocket/blob/master/v3_ws_ulimit/wsserver.go)
```shell
(pprof) top
Showing nodes accounting for 137.93MB, 93.24% of 147.93MB total
Dropped 6 nodes (cum <= 0.74MB)
Showing top 10 nodes out of 51
flat flat% sum% cum cum%
73.79MB 49.88% 49.88% 73.79MB 49.88% bufio.NewWriterSize
34.63MB 23.41% 73.29% 34.63MB 23.41% bufio.NewReaderSize
11MB 7.44% 80.73% 11MB 7.44% runtime.malg
4MB 2.70% 83.44% 5.50MB 3.72% net/textproto.(*Reader).ReadMIMEHeader
3MB 2.03% 85.46% 3.50MB 2.37%
github.com/gorilla/websocket.newConn 3MB 2.03% 87.49% 10.50MB 7.10% net/http.readRequest
2.50MB 1.69% 89.18% 16.50MB 11.16% net/http.(*conn).readRequest
2.50MB 1.69% 90.87% 3.50MB 2.37% context.propagateCancel
2MB 1.35% 92.23% 2MB 1.35% syscall.anyToSockaddr
1.50MB 1.01% 93.24% 1.50MB 1.01% net.newFD
(pprof) web
failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in $PATH
(pprof) list flat
Total: 147.93MB
```
goroutine 是 10003,每个 goroutine 占用 4kb 的内存
```shell
(pprof) top
Showing nodes accounting for 10001, 100% of 10003 total
Dropped 24 nodes (cum <= 50)
Showing top 10 nodes out of 19
flat flat% sum% cum cum%
10001 100% 100% 10001 100% runtime.gopark
0 0% 100% 9998 100% bufio.(*Reader).Peek
0 0% 100% 9998 100% bufio.(*Reader).fill
0 0% 100% 9999 100%
github.com/gorilla/websocket.(*Conn).NextReader 0 0% 100% 9999 100%
github.com/gorilla/websocket.(*Conn).ReadMessage 0 0% 100% 9999 100%
github.com/gorilla/websocket.(*Conn).advanceFrame 0 0% 100% 9998 100%
github.com/gorilla/websocket.(*Conn).read 0 0% 100% 9999 100% internal/poll.(*FD).Read
0 0% 100% 10001 100% internal/poll.(*pollDesc).wait
0 0% 100% 10001 100% internal/poll.(*pollDesc).waitRead (inline)
(pprof) list flat
Total: 10003
(pprof)
```