简体   繁体   中英

nodejs requests per second and concurrent calls

I am running node v0.12.7 on Debian 7 x64 and I would like to benchmark its performance on a 16 core virtual private server with 4GB of memory.

I am running the following minimalistic code:

// server.js
var http = require('http');
http.createServer(function (request, response) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World');
}).listen(80,"0.0.0.0");

I am launching it with this command in another teminal):

node server.js

At this point node is running on one core. Then I use ab to test its performance with this command:

ab -n 10000 -c 100 -k http://127.0.0.1/

... and get these results:

...
Requests per second:    3925.81 [#/sec] (mean)
...
Percentage of the requests served within a certain time (ms)
50%     35
...

I was wondering if any of you did similar tests and if you:

  • got better results
  • got same kind of results but were able to tweak your node app/server in order to obtain higher requests/s and/or lower latency.

I have to mention that running it with pm2 in cluster mode with 15 cores brings me to 4500 requests / second which makes me think that there is another bottle neck somewhere that I miss.

Thanks for any thoughts on this topic. Paul

Posting my results (hope it can benefit someone else):

On MacBook Pro 2.2 GHz, Core I7, 16 GB. The test is done using JMeter. ab was freezing and throwing some errors after processing 15K reqs.

Number Of Users: 200 Each user makes 5000 requests.

Result: Without Node Clustering :

Total Samples Processed: 1000000
Throughput: 22419 req/sec
Total Time: 44 seconds

Result: with Clustering - 8 Nodes (=numCpus)

Total Samples Processed: 1000000
Throughput: 36091 req/sec
Total Time: 27 seconds

Result: with Clustering - 6 Nodes (3:1 of total cpus)

Total Samples Processed: 1000000
Throughput: 36685 req/sec
Total Time: 27 seconds

Result: with Clustering - 4 Nodes (=numCpus/2)

Total Samples Processed: 1000000
Throughput: 35604 req/sec
Total Time: 28 seconds

Its really great. The performance is almost same for a cluster with 4/6/8 nodes.

The server code is below.

"use strict";

var http = require('http');
const PORT = 8080;

var total = 0;

var server = http.createServer(function(request, response) {
  total++;

  if ((total % 1000) === 0) {
    console.log("Completed:" + total);
  }
  response.end('It Works!! Path Hit: ' + request.url);
});

server.listen(PORT, function() {
  console.log("Server listening on: http://localhost:%s", PORT);
});

The following code is used for Clustering.

"use strict";

const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
var http = require('http');
const PORT = 8080;

var total = 0;

//numCPUs = 6;
//numCPUs = 4

console.log("Number of CPUs" + numCPUs);

if (cluster.isMaster) {
  // Fork workers.
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('exit', (worker, code, signal) => {
    console.log(`worker ${worker.process.pid} died`);
  });
}
else {
  var server = http.createServer(function(request, response) {
    total++;

    if ((total % 1000) === 0) {
      console.log("Completed:" + total);
    }
    response.end('It Works!! Path Hit: ' + request.url);
  });

  server.listen(PORT, function() {
    console.log("Server listening on: http://localhost:%s", PORT);
  });
}

I'm not really sure of the point of this question, but a quick test on a MacBook Pro, with 16GB of RAM and Node 5.0.0

Requests per second:    6839.72 [#/sec] (mean)
Time per request:       14.620 [ms] (mean)

Percentage of the requests served within a certain time (ms)
50%     14

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM