244 Comments

imageHere’s a new run of the ASP.NET Web Api vs Node.js benchmark but this time with few changes:

  • ASP.NET Web Api: The release candidate is used instead of beta.
  • ASP.NET Web Api: Self-Host is used instead of IIS.
  • ASP.NET Web Api: Use of async / await
  • Node.js: Version 0.6.19 is used instead of 0.6.17.

Also the test environment was tweaked a little and this time there was a dedicated c1.medium server for the ab.

The test

A simple server which accepts a POST-request and then responds back with the request’s body.

Node.js Implementation

var express = require('express') 
    , app = express.createServer(); 

app.use(express.bodyParser()); 

app.post('/', function(req, res){ 
    res.send(req.body); 
}); 

app.listen(8080);

ASP.NET Web Api implementation

public class ValuesAsyncController : ApiController 
{ 
    public async Task<string> Post() 
    { 
        return await this.ControllerContext.Request.Content.ReadAsStringAsync(); 
    } 
}

The benchmark

I used Apache’s ab tool to test the performance of the platforms. The benchmark was run with the following settings:

  • Total number of requests: 100 000
  • Concurrency: 80

The benchmark (test.dat) contained a simple JSON, taken from Wikipedia.

{
     "firstName": "John",
     "lastName" : "Smith",
     "age"      : 25,
     "address"  :
     {
         "streetAddress": "21 2nd Street",
         "city"         : "New York",
         "state"        : "NY",
         "postalCode"   : "10021"
     },
     "phoneNumber":
     [
         {
           "type"  : "home",
           "number": "212 555-1234"
         },
         {
           "type"  : "fax",
           "number": "646 555-4567"
         }
     ]
 }

Here’s the whole command which was used to run the performance test:

ab -n 100000 -c 80 -p .test.dat -T 'application/json; charset=utf-8' http://localhost/

The performance test was run 3 times and the best result for each platform was selected. The performance difference between the test runs was minimal.

The Test Environment

The benchmark was run on a Windows Server 2008 R2, hosted on an c1.medium Amazon EC2 –instance:

image

Specs of the instance
  • 1.7GB memory
  • 5 EC2 Compute Units (2 virtual cores)
Versions
  • Node.js: 0.6.19
  • ASP.NET Web Api: The release candidate.

The ab has its own dedicated c1.medium –instance. All the instances were on the eu-west-1a zone and the private IP was used to connect the ab and test servers.

The Benchmark Results

image

Web ApiNode.js
Time taken (in s)59,6454,73
Requests per second1676,761827,33
Time per request (in ms)47,7143,78
Failed requests00

Few words about the multi-core systems

Where Node.js is limited to a single thread and as such only uses one processor core, self-hosted Web Api can automatically take advantage of multi-core systems. With Node.js you have to use for example cluster in order to split the workload between the cores.

Here’s a graph from ASP.NET Web Api-server which shows the CPU usage of each logical processor (from my local machine):

image

Here’s an overall CPU usage when running the Node-server:

image

And here’s the same graph but this time with the ASP.NET Web Api-server:

image

The Code

The source code for the implementations and also the test tools (ab.exe, test.dat) are available from GitHub.