Search code examples
node.jsapachebench

Increase throughput of node.js http server


I'm experimenting with node.js and facing a strange issue with throughput. Basically, I have this code to create a simple HTTP server (on a VM with 4GB RAM and 4 vCPUs, running Ubuntu 16.04 and node.js v6.3.1):

const http = require('http');
http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello');
}).listen(8888);

I'm running it with node server.js to start the HTTP server, and then I'm trying to load-test it from a different machine using Apache Bench:

ab -l -r -n 100 -c 50 -k http://server-ip:8888/

However, no matter what the number & concurrency of requests (n/c values) I test with, the benchmark results always show the 'requests per second' to be under 5/sec, which is too low for a scalable framework like node.js and a simple HTTP server as above.

So I'm assuming that it's something to do with configuration, settings etc. Anyone has any ideas on how to increase the throughput in this case?!

Update: I've come across people who are getting high-throughput with near-identical base code running on cloud VMs:

http://zgadzaj.com/benchmarking-nodejs-basic-performance-tests-against-apache-php

https://www.jayway.com/2015/04/13/600k-concurrent-websocket-connections-on-aws-using-node-js/

http://blog.yld.io/2016/02/08/squeeze-the-juice-out-of-node/

http://blog.caustik.com/2012/08/19/node-js-w1m-concurrent-connections/


Solution

  • The problem was Windows 8.1 (load-test machine I first tried) limiting the tcp connections, hence affecting Apache Bench (ab) concurrency. On a different Ubuntu machine, it works fine and the throughput results are much better.