几种 Websocket 框架的性能测试
结论
NodeJS 的 ws 综合表现最好,latency ~7ms 左右,轻松上到 5000 个 client 连接,TypeScript 的成熟同样给程序的编写提供了保障,同时也能利用弱类型语言本身的便利进行快速开发。
测试指标
给定一定 clients 的数量,在不 drop 任何 client 连接的前提下:
- 单机服务器每秒能发送多少消息
- 客户端收到消息的延迟是多少 (ms)
测试环境
Host
1
2
3
4MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)
2 GHz Quad-Core Intel Core i5
16 GB 3733 MHz LPDDR4X
Intel Iris Plus Graphics 1536 MB5000个node client连接,每个client每500ms发一次小时到服务器
测试结果
nodejs ws
Server:
- CPU 100%
- completed in seconds
- send message to client per 50ms
1 | clients: 0, tps: 0 |
Client (via NodeJS):
- CPU: 100%
1 | TPS: 9828.009828009828 |
Java Vert.X v3.9.2
Server:
- CPU 130%
- send message to client per
100ms
(as 50ms it makes my computer die) - takes more than 3mins (each log is under 2 seconds interval), dropped then
1 | clients: 0, tps: 0.0 |
Client (via NodeJS):
- CPU: 151%
1 | TPS: 9055.944055944055 |
socket.io
node cpu: >120%, die after 20s
1 | clients: 200, tx/second: 3160.2962255136167 |
uwebsocket
node cpu: 100%
1 | clients: 200, tx/second: 7340 |