Express vs Flask vs Go vs Sparkjava vs Sinatra
Bijan
9921
Bijan From node point of view I think you have under evaluated its performance. There are couple of things one must take care of while running node in production —
- Run it in cluster mode. Node by default is single threaded and would be unable able to scale if it runs on just one CPU.
- Use `const` instead of `var` this helps the v8 engine do further optimizations.
- Use `response.end()` instead of `response.send()` this will significantly improve expressJS performance.
- Use node.js version 6.0 as it now supports tail recursion. This will reduce memory footprint.
const cluster = require(‘cluster’)
const numCPUs = require(‘os’).cpus().length
const express = require(‘express’)
const app = express()
const fib = function (n) {
if (n === 0) {
return 0
} else if (n === 1) {
return 1
}
return fib(n — 1) + fib(n — 2)
}
app.get(‘/:number’, function (req, res) {
const number = parseInt(req.params[‘number’], 10)
const result = fib(number)
res.end(‘Node + Express<hr> fib(‘ + number + ‘): ‘ + result)
})
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork()
}
cluster.on(‘exit’, (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`)
})
} else {
app.listen(3000)
}
My macbook has exactly the same configuration as yours but I was able to extract Requests/sec: 50804.34 compared to yours 8962 Requests/sec. Which essentially makes it the top contender. Let me know the results you get when you run in your env.
Thanks!