Stress Testing Express, Restify and hapi

2 min read Original article ↗

In the sea of node frameworks choosing the one for your application is quite a task. I required a sleek framework for building REST API, Most popular names came up we Express, Restify, hapi. There are lot of blogs quoting pros and cons but none of them quoted numbers and once who did where quite outdated.

This medium story is all about unbiased practical analysis of Express, Restify and hapi.

Here’s my analysis on running these three on

  1. 1 Core, 512 MB RAM
  2. 4 Cores, 8 GB RAM

Used PM2 for analytics and management, and loadtest for stress testing the applications. Total Four loadtest running on independent servers with each firing 1000 requests/second with concurrency 10.

loadtest -c 10 --rps 1000 http://x.y.z.a/

Code :

Express

var express = require('express');
var app = express();

app.get('/', function (req, res) {
res.send('lol');
});

app.listen(80, function () {
console.log('Express');
});

Restify

var restify = require('restify');

function respond(req, res, next) {
res.send('lol');
next();
}

var server = restify.createServer();
server.get('/', respond);

server.listen(80, function() {
console.log('Restify');
});

hapi

'use strict';

const Hapi = require('hapi');

const server = new Hapi.Server();
server.connection({ port: 80 });

server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('lol');
}
});

server.start((err) => {

if (err) {
throw err;
}
console.log('hapi');
});

  • 1 Core, 512 MB RAM; After 10 seconds of tests

Express

Restify

hapi

After round 1 it seems Restify has edge over others in Loop Delay and Memory Management.

  • 4 Cores, 8GB RAM; After 10 seconds of test

Express

Restify

hapi

After round 2 it seems distributing the load had drastic changes in Loop Delay. Express and Restify gave the similar performance.

Overall Express and Restify are both good choice for REST APIs. Express has some advantages when it comes to features and documentation

PS : Let me know if you need need full video or logs, Also I tested the same in 2 Core, 4 GB RAM which didn’t turnout into a meaningful result maybe because of server issue but I can provide that data as well if needed