This is the reference point. All the other options are based off this.
|-- app
| |-- controllers
| | |-- admin
This set of benchmarks explores the impact on a Node.js HTTP API server when some responses take more cpu than others. The requests are to a JSON page that calculates a random fibonacci sequence between 1 and 30. The server is using node-perfectapi with a feature that scales the http server across available cpus, while leaving the user's API code in the main Node.js process.
In the red series, the http server is running in the same process as the Fibonacci calculations. In the green series, the handling of all of the http web server stuff has been moved to separate node workers. In both cases, the Fibonacci calculations occur in a single thread in the main (master) Node process.
Now obviously the red series is going to be slower than the green series (because it is restricted to a single cpu for both http requests/responses and the calculati
// A very basic web server in node.js | |
// Stolen from: Node.js for Front-End Developers by Garann Means (p. 9-10) | |
var port = 8000; | |
var serverUrl = "127.0.0.1"; | |
var http = require("http"); | |
var path = require("path"); | |
var fs = require("fs"); | |
var checkMimeType = true; |
before(function (done) { | |
/** | |
* Mocha is extremely zealous about trapping errors, and runs each test | |
* in a try / catch block. To get the exception to propagate out to the | |
* domain's uncaughtException handler, we need to put the test in an | |
* asynchronous context and break out of the mocha jail. | |
*/ | |
process.nextTick(function () { | |
// disable mocha's error handler | |
mochaHandler = process.listeners('uncaughtException').pop(); |
// NOTE: I previously suggested doing this through Grunt, but had plenty of problems with | |
// my set up. Grunt did some weird things with scope, and I ended up using nodemon. This | |
// setup is now using Gulp. It works exactly how I expect it to and is WAY more concise. | |
var gulp = require('gulp'), | |
spawn = require('child_process').spawn, | |
node; | |
/** | |
* $ gulp server | |
* description: launch the server. If there's a server already running, kill it. |
var express = require("express"); | |
var app = express(); | |
app.get("/restricted", function(req, res, next){ | |
// Grab the "Authorization" header. | |
var auth = req.get("authorization"); | |
// On the first request, the "Authorization" header won't exist, so we'll set a Response | |
// header that prompts the browser to ask for a username and password. |
Located in alphabetical order (not prefer)
C
ab
), also designed as a more modern replacement, written in C
golang
)This is not an official report nor reliable benchmark. The testing environments are vary. These EC2 latencies are measured by http://aws-latency.altaircp.com/ Thanks to my friends!
If you want to add a result from your location, feel free to comment on this gist. Please note that you need to try it several times to get an accurate result.
Asia Pacific (Seoul) ap-northeast-2 19ms
Asia Pacific (Tokyo) ap-northeast-1 92ms