Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use Restify?

I had the requirement to build up a REST API in node.js and was looking for a more light-weight framework than express.js which probably avoids the unwanted features and would act like a custom-built framework for building REST APIs. Restify from its intro is recommended for the same case.

Reading Why use restify and not express? seemed like restify is a good choice.

But the surprise came when I tried out both with a load.

I made a sample REST API on Restify and flooded it with 1000 requests per second. Surprise to me the route started not responding after a while. The same app built on express.js handled all.

I am currently applying the load to 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 the results I have got seem sensible? And if so is express more efficient than restify in this scenario? Or is there any error in the way I tested them out?

updated in response to comments

behavior of restify

  1. when fed with a load of more than 1000 req.s it stopped processing in just 1 sec receiving till 1015 req.s and then doing nothing. ie. the counter i implemented for counting incoming requests stopped increment after 1015.

  2. when fed with a load of even 100 reqs. per second it received till 1015 and gone non responsive after that.

like image 353
Mithun Satheesh Avatar asked Jul 11 '13 08:07

Mithun Satheesh


People also ask

What is the use of Restify?

restify is a node. js module built specifically to enable you to build correct REST web services. It intentionally borrows heavily from express as that is more or less the de facto API for writing web applications on top of node. js.

Is Restify better than express?

Express is a minimal and flexible node. js web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications; Restify: node. js REST framework specifically meant for web service APIs.

What is Restify framework?

A Node. js web service framework optimized for building semantically correct RESTful web services ready for production use at scale. restify optimizes for introspection and performance, and is used in some of the largest Node. js deployments on Earth.

Why is Fastify faster than express?

Fastify provides full encapsulation for plug-ins, automatically parses JSON with relatively faster rendering, and provides quick routing. Among other benefits, Fastify also has a cleaner syntax for writing async code in controllers. Express, however, has a stronger user base with plenty of documentation available.


1 Answers

Corrigendum: this information is now wrong, keep scrolling!

there was an issue with the script causing the Restify test to be conducted on an unintended route. This caused the connection to be kept alive causing improved performance due to reduced overhead.


This is 2015 and I think the situation has changed a lot since. Raygun.io has posted a recent benchmark comparing hapi, express and restify.

It says:

We also identified that Restify keeps connections alive which removes the overhead of creating a connection each time when getting called from the same client. To be fair, we have also tested Restify with the configuration flag of closing the connection. You’ll see a substantial decrease in throughput in that scenario for obvious reasons.

Benchmark image from Raygun.io

Looks like Restify is a winner here for easier service deployments. Especially if you’re building a service that receives lots of requests from the same clients and want to move quickly. You of course get a lot more bang for buck than naked Node since you have features like DTrace support baked in.

like image 112
Masum Avatar answered Sep 20 '22 03:09

Masum