Browse Source

bench: update static_http_server benchmark to new API

Fixes #2016.
v0.7.4-release
koichik 13 years ago
parent
commit
1001cf412c
  1. 59
      benchmark/static_http_server.js

59
benchmark/static_http_server.js

@ -1,48 +1,43 @@
var http = require("http"); var http = require('http');
var concurrency = 30; var concurrency = 30;
var port = 12346; var port = 12346;
var n = 7; // several orders of magnitude slower var n = 700;
var bytes = 1024*5; var bytes = 1024*5;
var requests = 0; var requests = 0;
var responses = 0; var responses = 0;
var body = ""; var body = '';
for (var i = 0; i < bytes; i++) { for (var i = 0; i < bytes; i++) {
body += "C"; body += 'C';
} }
var server = http.createServer(function (req, res) { var server = http.createServer(function(req, res) {
res.writeHead(200, { res.writeHead(200, {
"Content-Type": "text/plain", 'Content-Type': 'text/plain',
"Content-Length": body.length 'Content-Length': body.length
}); });
res.write(body); res.end(body);
res.close();
}) })
server.listen(port);
function responseListener (res) { server.listen(port, function() {
res.addListener("end", function () { var agent = new http.Agent();
if (requests < n) { agent.maxSockets = concurrency;
var req = res.client.request("/");
req.addListener('response', responseListener);
req.close();
requests++;
}
if (++responses == n) { for (var i = 0; i < n; i++) {
server.close(); var req = http.get({
} port: port,
}); path: '/',
} agent: agent
}, function(res) {
for (var i = 0; i < concurrency; i++) { res.on('end', function() {
var client = http.createClient(port); if (++responses === n) {
client.id = i; server.close();
var req = client.request("/"); }
req.addListener('response', responseListener); });
req.close(); });
requests++; req.id = i;
} requests++;
}
});

Loading…
Cancel
Save