diff options
author | Andreas Madsen <amwebdk@gmail.com> | 2016-01-30 14:07:45 +0100 |
---|---|---|
committer | Andreas Madsen <amwebdk@gmail.com> | 2016-07-26 12:48:23 +0200 |
commit | edbed3f3fd8b0010f3f474934ad880fa2898265a (patch) | |
tree | 8fcef8863b91bb3b856992b416273db146851fc8 /benchmark/http | |
parent | ee2843b4ea54b04eca30e00ec1ab39206449bd52 (diff) | |
download | android-node-v8-edbed3f3fd8b0010f3f474934ad880fa2898265a.tar.gz android-node-v8-edbed3f3fd8b0010f3f474934ad880fa2898265a.tar.bz2 android-node-v8-edbed3f3fd8b0010f3f474934ad880fa2898265a.zip |
benchmark: move http_simple.js to http directory
PR-URL: https://github.com/nodejs/node/pull/7094
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'benchmark/http')
-rw-r--r-- | benchmark/http/_http_simple.js | 113 | ||||
-rw-r--r-- | benchmark/http/cluster.js | 2 | ||||
-rw-r--r-- | benchmark/http/simple.js | 2 |
3 files changed, 115 insertions, 2 deletions
diff --git a/benchmark/http/_http_simple.js b/benchmark/http/_http_simple.js new file mode 100644 index 0000000000..7e2eed53a1 --- /dev/null +++ b/benchmark/http/_http_simple.js @@ -0,0 +1,113 @@ +'use strict'; + +var http = require('http'); + +var port = parseInt(process.env.PORT || 8000); + +var fixed = 'C'.repeat(20 * 1024), + storedBytes = {}, + storedBuffer = {}, + storedUnicode = {}; + +var useDomains = process.env.NODE_USE_DOMAINS; + +// set up one global domain. +if (useDomains) { + var domain = require('domain'); + var gdom = domain.create(); + gdom.on('error', function(er) { + console.error('Error on global domain', er); + throw er; + }); + gdom.enter(); +} + +var server = module.exports = http.createServer(function(req, res) { + if (useDomains) { + var dom = domain.create(); + dom.add(req); + dom.add(res); + } + + var commands = req.url.split('/'); + var command = commands[1]; + var body = ''; + var arg = commands[2]; + var n_chunks = parseInt(commands[3], 10); + var status = 200; + + var n, i; + if (command == 'bytes') { + n = ~~arg; + if (n <= 0) + throw new Error('bytes called with n <= 0'); + if (storedBytes[n] === undefined) { + storedBytes[n] = 'C'.repeat(n); + } + body = storedBytes[n]; + + } else if (command == 'buffer') { + n = ~~arg; + if (n <= 0) + throw new Error('buffer called with n <= 0'); + if (storedBuffer[n] === undefined) { + storedBuffer[n] = Buffer.allocUnsafe(n); + for (i = 0; i < n; i++) { + storedBuffer[n][i] = 'C'.charCodeAt(0); + } + } + body = storedBuffer[n]; + + } else if (command == 'unicode') { + n = ~~arg; + if (n <= 0) + throw new Error('unicode called with n <= 0'); + if (storedUnicode[n] === undefined) { + storedUnicode[n] = '\u263A'.repeat(n); + } + body = storedUnicode[n]; + + } else if (command == 'quit') { + res.connection.server.close(); + body = 'quitting'; + + } else if (command == 'fixed') { + body = fixed; + + } else if (command == 'echo') { + res.writeHead(200, { 'Content-Type': 'text/plain', + 'Transfer-Encoding': 'chunked' }); + req.pipe(res); + return; + + } else { + status = 404; + body = 'not found\n'; + } + + // example: http://localhost:port/bytes/512/4 + // sends a 512 byte body in 4 chunks of 128 bytes + if (n_chunks > 0) { + res.writeHead(status, { 'Content-Type': 'text/plain', + 'Transfer-Encoding': 'chunked' }); + // send body in chunks + var len = body.length; + var step = Math.floor(len / n_chunks) || 1; + + for (i = 0, n = (n_chunks - 1); i < n; ++i) { + res.write(body.slice(i * step, i * step + step)); + } + res.end(body.slice((n_chunks - 1) * step)); + } else { + var content_length = body.length.toString(); + + res.writeHead(status, { 'Content-Type': 'text/plain', + 'Content-Length': content_length }); + res.end(body); + } +}); + +server.listen(port, function() { + if (module === require.main) + console.error('Listening at http://127.0.0.1:' + port + '/'); +}); diff --git a/benchmark/http/cluster.js b/benchmark/http/cluster.js index 9934883f7c..95e76e69cc 100644 --- a/benchmark/http/cluster.js +++ b/benchmark/http/cluster.js @@ -11,7 +11,7 @@ if (cluster.isMaster) { c: [50, 500] }); } else { - require('../http_simple.js'); + require('./_http_simple.js'); } function main(conf) { diff --git a/benchmark/http/simple.js b/benchmark/http/simple.js index 5449c49be9..eedda8e98f 100644 --- a/benchmark/http/simple.js +++ b/benchmark/http/simple.js @@ -12,7 +12,7 @@ var bench = common.createBenchmark(main, { function main(conf) { process.env.PORT = PORT; - var server = require('../http_simple.js'); + var server = require('./_http_simple.js'); setTimeout(function() { var path = '/' + conf.type + '/' + conf.length + '/' + conf.chunks; var args = ['-d', '10s', '-t', 8, '-c', conf.c]; |