I’ve added optional [`picows`](
https://github.com/tarasko/picows) support to the UNICORN Binance WebSocket API (UBWA).
The goal was simple: find out whether replacing the pure-Python `websockets` implementation with the Cython-based picows actually makes a difference inside the full UBWA stack.
For small Binance messages, it does.
Some benchmark results:
```
aggTrade
websockets: 201,912 msgs/s
picows: 403,316 msgs/s
speedup: 2.00x
kline
websockets: 195,460 msgs/s
picows: 371,019 msgs/s
speedup: 1.90x
depth20
websockets: 153,187 msgs/s
picows: 259,960 msgs/s
speedup: 1.70x
```
I also ran both implementations for 24 hours in parallel against live Binance:
* ~138 million messages per implementation
* ~50 GB received each
* picows: 9.5% average CPU
* websockets: 12.8% average CPU
* no picows-specific stalls or unrecoverable streams
* picows ended with 23 MB lower RSS
The benchmark also uncovered several issues in UBWA itself, including unnecessary work in the hot receive loop and some proxy/failure-path bugs. Those were fixed as part of the work.
`websockets` remains the default for now.
The reason isn’t performance — picows clearly performs well. The reason is production history. A 24-hour soak and 138 million messages are useful evidence, but not yet equivalent to months of usage across many different systems.
So picows is opt-in while more real-world feedback comes in.
Full write-up, methodology and results:
https://blog.technopathy.club/picows-in-unicorn-binance-websocket-api-up-to-2-the-throughput-opt-in-for-nowGitHub discussion / feedback:
https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/issues/477If anyone here runs high-volume Binance WebSocket workloads, I’d be especially interested in independent CPU/memory numbers.