Posterous theme by Cory Watilo

WS: The Fastest WebSocket Module for Node.js

In the previous post, I wrote how to boost a WebSocket-Node module. The improved WebSocket-Node marked 800Mbs.



Recently, I had a chance to discuss with @einaros about the benchmark for WebSocket that I wrote. @einaros is an author of yet another WebSocket module for Node.js, called wsws is getting a lot of attention these days, and and Socket.IO are planning to adopt ws as a core WebSocket engine.

When I wrote my benchmark for the first time, I was not aware of ws. According to the benchmark result posted here, ws(version 0.3.4) is already as fast as / slightly faster than the improved (latest) WebSocket-Node.

The latest ws version is 0.3.8, and the performance of ws has been dramatically improved since then. @einaros and I updated websocketBinaryTransferBenchmark to compare with WebSocket-Node.



I conducted the same experiment as the way I did before, a.k.a. measured the client -> server -> client latency on localhost (== no network bottleneck). Then I calculated the throughput in bit per second.

The result was astonishing! The latest ws marked over 2Gbps (2.4Gbps for the best result on my Macbook Air Mid 13" 2011) which is more than 200% faster than the current WebSocket-Node. Moreover, The performance of ws does not drop even for large (e.g. 16MiB) binary files, (16MiB file transfer throughput with WebSocket-Node was half of 1MiB transfer case).

As I speculated in the previous post, Buffer object handling is the key to performance improvement. From 0.3.4 to 0.3.8, @einaros hand-optimized Buffer operations in many places of the code.

Note, the original ws did not support WebSocket SSL, so I quickly added a SSL support on my branch.



ws is a super promising WebSocket module for Node.js.

ws is yet a young module, a lot of room for improvement.

ws is blazing fast and the fastest WebSocket module (as far as I know)


I added a benchmark for browser client in my benchmark github repo. Chrome 16 marked 120Mbps on the same machine that I got 2Gbps with WS+Node.js. This result suggests that Chrome Websocket code has a lot of room for improvement.

Related link:

Posted | Viewed