i had requirement build rest api in node.js , looking more light-weight framework express.js avoids unwanted features , act custom-built framework building rest apis. restify intro recommended same case.
reading why use restify , not express? seemed restify choice.
but surprise came when tried out both load.
i made sample rest api on restify , flooded 1000 requests per second. surprise me route started not responding after while. same app built on express.js handled all.
i applying load api via
var fnpush = setinterval(function() { for(i=0;i<1000;i++) sendmsg(makemsg(i)); }, 1000); function sendmsg(msg) { var post_data = querystring.stringify(msg); var post_options = { host: target.host, port: target.port, path: target.path, agent: false, method: 'post', headers: { 'content-type': 'application/x-www-form-urlencoded', 'content-length': post_data.length, "connection": "close" } }; var post_req = http.request(post_options, function(res) {}); post_req.write(post_data); post_req.on('error', function(e) { }); post_req.end(); }
does results have got seem sensible? , if express more efficient restify in scenario? or there error in way tested them out?
updated in response comments
behavior of restify
when fed load of more 1000 req.s stopped processing in 1 sec receiving till 1015 req.s , doing nothing. ie. counter implemented counting incoming requests stopped increment after 1015.
when fed load of 100 reqs. per second received till 1015 , gone non responsive after that.
in blog there comparison between perfectapi
, express.js
, restify.js
, result express
better restify
large number of queries, made simple benchmark using current versions of express , restify
here's code test express:
var express = require('express'); var app = express(); app.get('/hello/:name', function(req, res){ res.send('hello ' + req.params.name); }); app.listen(3000); console.log('listening on port 3000');
and here's code restify
:
var restify = require('restify'); var server = restify.createserver(); server.get('/hello/:name', function(req, res, next) { res.send('hello ' + req.params.name); }); server.listen(3000, function() { console.log('listening on port 3000'); });
i used apachebench testing , simple example use it.
you can install sudo apt-get install apache2-utils
can run command test ab -n 10000 -c 100 http://127.0.0.1:3000/
. hit server 10000 requests, concurrency of 100.
the results restify
server hostname: 127.0.0.1 server port: 3000 document path: /hello/mark document length: 12 bytes concurrency level: 100 time taken tests: 2.443 seconds complete requests: 10000 failed requests: 0 write errors: 0 total transferred: 1390000 bytes html transferred: 120000 bytes requests per second: 4092.53 [#/sec] (mean) time per request: 24.435 [ms] (mean) time per request: 0.244 [ms] (mean, across concurrent requests) transfer rate: 555.53 [kbytes/sec] received connection times (ms) min mean[+/-sd] median max connect: 0 0 0.5 0 8 processing: 5 24 4.5 23 40 waiting: 5 24 4.5 23 40 total: 12 24 4.5 23 40
and express
:
server hostname: 127.0.0.1 server port: 3000 document path: /hello/mark document length: 10 bytes concurrency level: 100 time taken tests: 2.254 seconds complete requests: 10000 failed requests: 0 write errors: 0 total transferred: 1890000 bytes html transferred: 100000 bytes requests per second: 4436.76 [#/sec] (mean) time per request: 22.539 [ms] (mean) time per request: 0.225 [ms] (mean, across concurrent requests) transfer rate: 818.89 [kbytes/sec] received connection times (ms) min mean[+/-sd] median max connect: 0 0 0.5 0 7 processing: 17 22 4.7 21 55 waiting: 16 22 4.7 21 55 total: 18 22 4.9 21 58
from comparison can see express
faster restify
restify
didn't block , respond requests.
any 1 can try benchmark , can change number of requests , number of concurrent requests see effect on both.
Comments
Post a Comment