Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2015-03-25 09:26:21 +0300
committerBrian White <mscdex@mscdex.net>2015-04-03 07:56:45 +0300
commita081c7c5222de844ed0a61d470b8334676249d66 (patch)
tree7d73dd3adfa2f5b7dbf53801ecd4c96a38315c56 /benchmark/http/_chunky_http_client.js
parentf1e5a13516d1b7472206fad8c4c20c249c60f1db (diff)
benchmark: fix chunky client benchmark execution
This commit fixes a few things for this benchmark: 1. Ensures the temporary directory for the unix socket exists. 2. Prevents the client code from being run directly because the server script is the one that calls out the client code. 3. Ensures the server is closed once the client benchmarks have finished. 4. Since this is an http benchmark, it should be moved to the http benchmarks subdirectory. PR-URL: https://github.com/iojs/io.js/pull/1257 Reviewed-By: Roman Reiss <me@silverwind.io>
Diffstat (limited to 'benchmark/http/_chunky_http_client.js')
-rw-r--r--benchmark/http/_chunky_http_client.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/benchmark/http/_chunky_http_client.js b/benchmark/http/_chunky_http_client.js
new file mode 100644
index 00000000000..24e14ca2bc9
--- /dev/null
+++ b/benchmark/http/_chunky_http_client.js
@@ -0,0 +1,102 @@
+'use strict';
+
+// test HTTP throughput in fragmented header case
+var common = require('../common.js');
+var net = require('net');
+var test = require('../../test/common.js');
+
+var bench = common.createBenchmark(main, {
+ len: [1, 4, 8, 16, 32, 64, 128],
+ num: [5, 50, 500, 2000],
+ type: ['send'],
+});
+
+
+function main(conf) {
+ var len = +conf.len;
+ var num = +conf.num;
+ var type = conf.type;
+ var todo = [];
+ var headers = [];
+ // Chose 7 because 9 showed "Connection error" / "Connection closed"
+ // An odd number could result in a better length dispersion.
+ for (var i = 7; i <= 7 * 7 * 7; i *= 7)
+ headers.push(Array(i + 1).join('o'));
+
+ function WriteHTTPHeaders(channel, has_keep_alive, extra_header_count) {
+ todo = []
+ todo.push('GET / HTTP/1.1');
+ todo.push('Host: localhost');
+ todo.push('Connection: keep-alive');
+ todo.push('Accept: text/html,application/xhtml+xml,' +
+ 'application/xml;q=0.9,image/webp,*/*;q=0.8');
+ todo.push('User-Agent: Mozilla/5.0 (X11; Linux x86_64) ' +
+ 'AppleWebKit/537.36 (KHTML, like Gecko) ' +
+ 'Chrome/39.0.2171.71 Safari/537.36');
+ todo.push('Accept-Encoding: gzip, deflate, sdch');
+ todo.push('Accept-Language: en-US,en;q=0.8');
+ for (var i = 0; i < extra_header_count; i++) {
+ // Utilize first three powers of a small integer for an odd cycle and
+ // because the fourth power of some integers overloads the server.
+ todo.push('X-Header-' + i + ': ' + headers[i % 3]);
+ }
+ todo.push('');
+ todo.push('');
+ todo = todo.join('\r\n');
+ // Using odd numbers in many places may increase length coverage.
+ var chunksize = 37;
+ for (i = 0; i < todo.length; i += chunksize) {
+ var cur = todo.slice(i, i + chunksize);
+ channel.write(cur);
+ }
+ }
+
+ var success = 0;
+ var failure = 0;
+ var min = 10;
+ var size = 0;
+ var mod = 317;
+ var mult = 17;
+ var add = 11;
+ var count = 0;
+ var PIPE = test.PIPE;
+ var socket = net.connect(PIPE, function() {
+ bench.start();
+ WriteHTTPHeaders(socket, 1, len);
+ socket.setEncoding('utf8')
+ socket.on('data', function(d) {
+ var did = false;
+ var pattern = 'HTTP/1.1 200 OK\r\n';
+ if ((d.length === pattern.length && d === pattern) ||
+ (d.length > pattern.length &&
+ d.slice(0, pattern.length) === pattern)) {
+ success += 1;
+ did = true;
+ } else {
+ pattern = 'HTTP/1.1 '
+ if ((d.length === pattern.length && d === pattern) ||
+ (d.length > pattern.length &&
+ d.slice(0, pattern.length) === pattern)) {
+ failure += 1;
+ did = true;
+ }
+ }
+ size = (size * mult + add) % mod;
+ if (did) {
+ count += 1;
+ if (count === num) {
+ bench.end(count);
+ } else {
+ WriteHTTPHeaders(socket, 1, min + size);
+ }
+ }
+ });
+ socket.on('close', function() {
+ console.log('Connection closed');
+ });
+
+ socket.on('error', function() {
+ throw new Error('Connection error');
+ });
+ });
+}