diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-01-26 00:47:18 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-01-29 17:46:14 +0800 |
commit | 98d1110721faf0a5c62f5402e863f2c203783677 (patch) | |
tree | 0ad95c2536c2ca2e6aa02459f4cc6dccafd7f29f /benchmark | |
parent | 9fb91fe1d63eb773a5400d9b8c54cb590aec392d (diff) | |
download | android-node-v8-98d1110721faf0a5c62f5402e863f2c203783677.tar.gz android-node-v8-98d1110721faf0a5c62f5402e863f2c203783677.tar.bz2 android-node-v8-98d1110721faf0a5c62f5402e863f2c203783677.zip |
benchmark: implement duration in http test double
PR-URL: https://github.com/nodejs/node/pull/18380
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/_http-benchmarkers.js | 9 | ||||
-rw-r--r-- | benchmark/_test-double-benchmarker.js | 28 |
2 files changed, 31 insertions, 6 deletions
diff --git a/benchmark/_http-benchmarkers.js b/benchmark/_http-benchmarkers.js index 54b7481afa..55ebcc96ba 100644 --- a/benchmark/_http-benchmarkers.js +++ b/benchmark/_http-benchmarkers.js @@ -89,11 +89,14 @@ class TestDoubleBenchmarker { } create(options) { + const env = Object.assign({ + duration: options.duration, + test_url: `http://127.0.0.1:${options.port}${options.path}`, + }, process.env); + const child = child_process.fork(this.executable, { silent: true, - env: Object.assign({}, process.env, { - test_url: `http://127.0.0.1:${options.port}${options.path}` - }) + env }); return child; } diff --git a/benchmark/_test-double-benchmarker.js b/benchmark/_test-double-benchmarker.js index 8c2f744fbf..e2a0eb1312 100644 --- a/benchmark/_test-double-benchmarker.js +++ b/benchmark/_test-double-benchmarker.js @@ -2,6 +2,28 @@ const http = require('http'); -http.get(process.env.test_url, function() { - console.log(JSON.stringify({ throughput: 1 })); -}); +const duration = process.env.duration || 0; +const url = process.env.test_url; + +const start = process.hrtime(); +let throughput = 0; + +function request(res) { + res.on('data', () => {}); + res.on('error', () => {}); + res.on('end', () => { + throughput++; + const diff = process.hrtime(start); + if (duration > 0 && diff[0] < duration) { + run(); + } else { + console.log(JSON.stringify({ throughput })); + } + }); +} + +function run() { + http.get(url, request); +} + +run(); |