Skip to content

Instantly share code, notes, and snippets.

@pasaran
Created June 14, 2013 12:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasaran/5781516 to your computer and use it in GitHub Desktop.
Save pasaran/5781516 to your computer and use it in GitHub Desktop.
var http = require('http');
var data = [];
var length;
var req = http.request('http://mail.yandex.ru', function(res) {
res.on('data', function (chunk) {
data.push(chunk);
});
res.on('end', function() {
length = data.length;
startServer();
});
});
req.end();
function startServer() {
http.createServer(function(req, res) {
res.writeHead( 200, { 'Content-Type': 'text/html' } );
for (var i = 0; i < length; i++) {
res.write( data[i] );
}
res.end();
}).listen(9000, '127.0.0.1');
}
var http = require('http');
var length = 0;
var data = [];
var buffer;
var req = http.request('http://mail.yandex.ru', function(res) {
res.on('data', function (chunk) {
length += chunk.length;
data.push(chunk);
});
res.on('end', function() {
buffer = Buffer.concat(data, length);
startServer();
});
});
req.end();
function startServer() {
http.createServer(function(req, res) {
res.writeHead( 200, { 'Content-Type': 'text/html' } );
res.end(buffer);
}).listen(9000, '127.0.0.1');
}
var http = require('http');
var result = '';
var req = http.request('http://mail.yandex.ru', function(res) {
res.on('data', function (chunk) {
result += chunk;
});
res.on('end', startServer);
});
req.end();
function startServer() {
http.createServer(function(req, res) {
res.writeHead( 200, { 'Content-Type': 'text/html' } );
res.end(result);
}).listen(9000, '127.0.0.1');
}
@pasaran
Copy link
Author

pasaran commented Jun 14, 2013

Если брать страницу mail.yandex.ru, то примерно так:

http-buffer.js ~7500 rps
http-array-of-buffers.js ~5000 rps
http-string.js ~5800 rps

Если поменять урл на www.yandex.ru, то примерно так:

http-buffer.js ~1600 rps
http-array-of-buffers.js ~1600 rps
http-string.js ~1200 rps

Т.е. существенно еще размер ответа и количество чанков.

www.yandex.ru 52 154541
mail.yandex.ru 4 17446

У mail чанков мало и сам размер маленький, у www наоборот.
Т.е. тюнить еще есть что.

@pasaran
Copy link
Author

pasaran commented Jun 14, 2013

Да, тестил тупо через ab:

ab -n 10000 -c 100 http://127.0.0.1:9000/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment