var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World');
});
server.listen(4567);
console.log('Server is running at http://localhost:4567');
Lets take this example a bit further and add a setTimeout function to simulate a long running database query. Now each web request will take 1 second to complete.
var http = require('http');
var server = http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type':'text/plain'});
setTimeout(function() {
response.end('Hello World');
}, 1000);
});
server.listen(4567);
console.log('Server is running at http://locahost:4567');
Start the server and run apache bench against it. How long do the following take to finish?
ab -n 10 -c 1 http://localhost:4567/ (1 user sending 10 requests)
ab -n 100 -c 10 http://localhost:4567/ (10 users sending 10 requests)
ab -n 1000 -c 100 http://localhost:4567/ (100 users sending 10 requests)
How would would you do this in Ruby/Python/.Net/Java? Would you get similar response times?