Permalink
Browse files

squash

  • Loading branch information...
1 parent fa00e09 commit 27ee56793f5f3ac823936ea01070e1060072bfbc @bnoordhuis committed Oct 21, 2011
Showing with 25 additions and 5 deletions.
  1. +25 −5 benchmark/http_pump.js
@@ -23,22 +23,42 @@ var NUM_CLIENTS = 100;
var NUM_REQUESTS = 500; // # requests per client
var http = require('http');
+var net = require('net');
-var body = Buffer("Hello, node.js world.\n");
+var body = "Hello, node.js world.\n";
var headers = {
'Content-Type': 'text/plain',
'Content-Length': '' + body.length
};
+var response = Buffer(
+ "HTTP/1.0 200 OK\r\n" +
+ "Content-Type: text/plain\r\n" +
+ "Content-Length: " + body.length + "\r\n" +
+ "\r\n" +
+ body);
+
+var response_slices = [];
+for (var n = 0; n < response.length; n += 8) {
+ response_slices.push(response.slice(n, Math.min(n + 8, response.length)));
+}
+
var activeClients = 0;
var requestsCompleted = 0;
var startTime = 0;
-var server = http.createServer(function(req, res) {
- res.writeHead(200, headers);
- res.write(body);
- res.end();
+var server = net.createServer(function(conn) {
+ var i = 0, n = response_slices.length;
+
+ function write() {
+ if (i < n)
+ conn.write(response_slices[i++], write);
+ else
+ conn.destroy();
+ }
+
+ write();
});
var options = {

0 comments on commit 27ee567

Please sign in to comment.