Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add clustering to node.js' ws benchmark, to utilize more cores #23

merged 1 commit into from

4 participants


Also requires node v0.7, which will let you increase the socket listener backlog. Combined all of this should take care of the socket timeout errors.


What kind of improvement do you see with these changes?

could you patch to download and built the best version of 0.7 for this test? I'm going to try this out with 0.7.11 but because I'm not a node.js user, I don't know if that is the best beta version to use.


has require('os').cpus() been fixed by now to return all cores ? i had previously hit a limit on my 80 core test machine.

@ericmoritz ericmoritz merged commit 55d31c1 into ericmoritz:master

Forget patching configure_ubuntu, I'll just 0.7.11 since that's what you patch says to use.


I patched it all the same.


I ran this twice on the same server and both times it resulted in more timeouts than before.


Let me test the original right now and see if it's a AWS problem.


Strange. When I ran it on one of my Unbuntu boxes, it got rid of all the timeouts. Is the AWS you're running on single core?


No, it's a m1.large 64bit dual core box. The only variation is that it's technically not the same hardware because I stopped it after the last test. In may experience AWS boxes have varying degrees of performance.

Did you experience timeouts on your boxes before the change?


About 50% timeout on that box. I could get about 4.8k sockets up and running. On the 4 core server, with 0.7.11 clustered it handled all 10k just fine.


Yeah, I can't blame the implementation on this. This new box is performing terribly. The old version is hitting a wall at about 3700 connections. AWS is terrible. I don't think I can confidentially release the results of my previous test on this hardware. I can most certainly not compare any new results to the benchmark I did on Friday night.


Even the Erlang version, while it hit 10,000 clients, took twice as long to get there. This box is crap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 7 deletions.
  1. +22 −7 competition/wsdemo-ws.js
29 competition/wsdemo-ws.js
@@ -1,10 +1,25 @@
#!/usr/bin/env node
-var ws = require('ws')
-, wss = new ws.Server({port:8000, host: ""})
+var http = require('http')
+ , cluster = require('cluster')
+ , numCPUs = require('os').cpus().length
-wss.on('connection', function(con) {
- con.on('message', con.send)
+if (cluster.isMaster) {
+ // Master Process
+ var versionInfo = process.version.substr(1).split('.').map(function(v) { return parseInt(v); });
+ if (versionInfo[1] !== 7 || versionInfo[2] < 11) {
+ console.error('Please use node v0.7.11+\nAfter installing v0.7, please run "npm rebuild ws".');
+ process.exit(-1);
+ }
+ for (var i = 0; i < numCPUs; i++) cluster.fork();
+else {
+ // Worker Process
+ var ws = require('ws')
+ , server = http.createServer()
+ , wss = new ws.Server({server: server});
+ server.listen(8000, 3000); // increased socket backlog
+ wss.on('connection', function(con) {
+ con.on('message', con.send);
+ });
Something went wrong with that request. Please try again.