2009-10-31 20:06:46 +01:00
|
|
|
var path = require("path");
|
|
|
|
libDir = path.join(path.dirname(__filename), "../lib");
|
2009-10-25 22:51:10 +01:00
|
|
|
require.paths.unshift(libDir);
|
2009-10-31 20:06:46 +01:00
|
|
|
http = require("http");
|
2009-07-13 12:48:59 +02:00
|
|
|
var concurrency = 30;
|
|
|
|
var port = 8000;
|
2009-08-08 21:51:28 +02:00
|
|
|
var n = 700;
|
2009-07-13 12:48:59 +02:00
|
|
|
var bytes = 1024*5;
|
|
|
|
|
2009-08-08 21:51:28 +02:00
|
|
|
var requests = 0;
|
|
|
|
var responses = 0;
|
|
|
|
|
2009-07-13 12:48:59 +02:00
|
|
|
var body = "";
|
|
|
|
for (var i = 0; i < bytes; i++) {
|
|
|
|
body += "C";
|
|
|
|
}
|
|
|
|
|
2009-09-28 12:36:36 +02:00
|
|
|
var server = http.createServer(function (req, res) {
|
2009-08-23 12:20:25 +02:00
|
|
|
res.sendHeader(200, {
|
|
|
|
"Content-Type": "text/plain",
|
|
|
|
"Content-Length": body.length
|
|
|
|
});
|
2009-07-13 12:48:59 +02:00
|
|
|
res.sendBody(body);
|
|
|
|
res.finish();
|
|
|
|
})
|
|
|
|
server.listen(port);
|
|
|
|
|
|
|
|
function responseListener (res) {
|
|
|
|
res.addListener("complete", function () {
|
2009-08-08 21:51:28 +02:00
|
|
|
if (requests < n) {
|
2009-07-13 12:48:59 +02:00
|
|
|
res.client.get("/").finish(responseListener);
|
2009-08-08 21:51:28 +02:00
|
|
|
requests++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++responses == n) {
|
2009-07-13 12:48:59 +02:00
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-08-26 22:11:51 +02:00
|
|
|
for (var i = 0; i < concurrency; i++) {
|
2009-09-28 12:36:36 +02:00
|
|
|
var client = http.createClient(port);
|
2009-08-26 22:11:51 +02:00
|
|
|
client.id = i;
|
|
|
|
client.get("/").finish(responseListener);
|
|
|
|
requests++;
|
2009-07-13 12:48:59 +02:00
|
|
|
}
|