Node.js vs. ASP.NET Web API
Much 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:
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
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.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)
Comments
Tech Fun replied on Thu, 2012/05/17 - 4:13pm
Bart Czernicki replied on Fri, 2012/05/18 - 3:00pm
I am curious what the default IIS settings are on Amazon EC2...does IIS include uncessary headers (?)
Also when benchmarking Node versus Web APIs, a proper test would include a series of: cached, non-cached, async and sync requests. Node is going to be faster in direct requests/async 100% requests...once u start mixing things I would assume that ASP.NET Web APIs would quickly catch up, especially as sync requests increase.
Also scaling Web APIs should be easier as Tasks, PLINQ etc can take advantage of multiple cores directly from the environment. In Node, you need to sping up multiple node processes and allocate to each core.