Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Node.js vs. ASP.NET Web API

DZone's Guide to

Node.js vs. ASP.NET Web API

· Web Dev Zone ·
Free Resource

Access over 20 APIs and mobile SDKs, up to 250k transactions free with no credit card required

imageMuch has been said about the Node.js’s great performance so I wanted to test out how it compares to an ASP.NET Web Api backend.I created a simple server for both of the platforms which accepts a POST-request and then responds back with the request’s body.

The Node.js and ASP.NET Web Api implementations

Here’s the Node.js code:

var express = require('express')
    , app = express.createServer();
 
app.use(express.bodyParser());
 
app.post('/', function(req, res){
    res.send(req.body);
});
 
app.listen(3000);

And here’s the ASP.NET Web Api controller:

public class ValuesController : ApiController
{
    // POST /api/values
    public Task<string> Post()
    {
        return this.ControllerContext.Request.Content.ReadAsStringAsync();
    }
}

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: 100

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 100 -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.

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.17
  • ASP.NET Web Api: Current release (12.5.2012)
  • IIS: 7

Both the Node and IIS –servers were run with their out-of-the-box settings.

Benchmark Results

image

  Web Api Node.js
Time taken (in s) 89.95 41.65
Requests per second 1111.69 2400.89
Time per request (in ms) 89.95 41.65
Failed requests 0 0


Conclusion

The out-of-the-box performance of the Node.js seems to be better than the performance of the ASP.NET Web Api + IIS7. Tweaking the IIS7’s settings could make the ASP.NET Web Api perform better but for this test the default settings of IIS7 were used.



#1 for location developers in quality, price and choice, switch to HERE.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}