3 // test HTTP throughput in fragmented header case
4 var common = require('../common.js');
5 var net = require('net');
6 var test = require('../../test/common.js');
8 var bench = common.createBenchmark(main, {
9 len: [1, 4, 8, 16, 32, 64, 128],
10 num: [5, 50, 500, 2000],
21 // Chose 7 because 9 showed "Connection error" / "Connection closed"
22 // An odd number could result in a better length dispersion.
23 for (var i = 7; i <= 7 * 7 * 7; i *= 7)
24 headers.push(Array(i + 1).join('o'));
26 function WriteHTTPHeaders(channel, has_keep_alive, extra_header_count) {
28 todo.push('GET / HTTP/1.1');
29 todo.push('Host: localhost');
30 todo.push('Connection: keep-alive');
31 todo.push('Accept: text/html,application/xhtml+xml,' +
32 'application/xml;q=0.9,image/webp,*/*;q=0.8');
33 todo.push('User-Agent: Mozilla/5.0 (X11; Linux x86_64) ' +
34 'AppleWebKit/537.36 (KHTML, like Gecko) ' +
35 'Chrome/39.0.2171.71 Safari/537.36');
36 todo.push('Accept-Encoding: gzip, deflate, sdch');
37 todo.push('Accept-Language: en-US,en;q=0.8');
38 for (var i = 0; i < extra_header_count; i++) {
39 // Utilize first three powers of a small integer for an odd cycle and
40 // because the fourth power of some integers overloads the server.
41 todo.push('X-Header-' + i + ': ' + headers[i % 3]);
45 todo = todo.join('\r\n');
46 // Using odd numbers in many places may increase length coverage.
48 for (i = 0; i < todo.length; i += chunksize) {
49 var cur = todo.slice(i, i + chunksize);
63 var socket = net.connect(PIPE, function() {
65 WriteHTTPHeaders(socket, 1, len);
66 socket.setEncoding('utf8')
67 socket.on('data', function(d) {
69 var pattern = 'HTTP/1.1 200 OK\r\n';
70 if ((d.length === pattern.length && d === pattern) ||
71 (d.length > pattern.length &&
72 d.slice(0, pattern.length) === pattern)) {
77 if ((d.length === pattern.length && d === pattern) ||
78 (d.length > pattern.length &&
79 d.slice(0, pattern.length) === pattern)) {
84 size = (size * mult + add) % mod;
90 WriteHTTPHeaders(socket, 1, min + size);
94 socket.on('close', function() {
95 console.log('Connection closed');
98 socket.on('error', function() {
99 throw new Error('Connection error');