2010-03-23 09:47:04 +08:00
|
|
|
var http = require("http");
|
2010-03-09 11:06:25 +08:00
|
|
|
|
2009-07-13 18:48:59 +08:00
|
|
|
var concurrency = 30;
|
2010-03-23 09:47:04 +08:00
|
|
|
var port = 12346;
|
|
|
|
var n = 7; // several orders of magnitude slower
|
2009-07-13 18:48:59 +08:00
|
|
|
var bytes = 1024*5;
|
|
|
|
|
2009-08-09 03:51:28 +08:00
|
|
|
var requests = 0;
|
|
|
|
var responses = 0;
|
|
|
|
|
2009-07-13 18:48:59 +08:00
|
|
|
var body = "";
|
|
|
|
for (var i = 0; i < bytes; i++) {
|
|
|
|
body += "C";
|
|
|
|
}
|
|
|
|
|
2009-09-28 18:36:36 +08:00
|
|
|
var server = http.createServer(function (req, res) {
|
2010-02-26 04:54:48 +08:00
|
|
|
res.writeHead(200, {
|
2009-08-23 18:20:25 +08:00
|
|
|
"Content-Type": "text/plain",
|
|
|
|
"Content-Length": body.length
|
|
|
|
});
|
2010-02-17 14:16:29 +08:00
|
|
|
res.write(body);
|
2010-02-18 07:36:50 +08:00
|
|
|
res.close();
|
2009-07-13 18:48:59 +08:00
|
|
|
})
|
|
|
|
server.listen(port);
|
|
|
|
|
|
|
|
function responseListener (res) {
|
2010-02-17 14:16:29 +08:00
|
|
|
res.addListener("end", function () {
|
2009-08-09 03:51:28 +08:00
|
|
|
if (requests < n) {
|
2010-02-18 07:36:50 +08:00
|
|
|
var req = res.client.request("/");
|
|
|
|
req.addListener('response', responseListener);
|
|
|
|
req.close();
|
2009-08-09 03:51:28 +08:00
|
|
|
requests++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++responses == n) {
|
2009-07-13 18:48:59 +08:00
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-08-27 04:11:51 +08:00
|
|
|
for (var i = 0; i < concurrency; i++) {
|
2009-09-28 18:36:36 +08:00
|
|
|
var client = http.createClient(port);
|
2009-08-27 04:11:51 +08:00
|
|
|
client.id = i;
|
2010-02-18 07:36:50 +08:00
|
|
|
var req = client.request("/");
|
|
|
|
req.addListener('response', responseListener);
|
|
|
|
req.close();
|
2009-08-27 04:11:51 +08:00
|
|
|
requests++;
|
2009-07-13 18:48:59 +08:00
|
|
|
}
|