| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,10 +82,12 @@ class WrkBenchmarker { | |||
| 82 | 82 | * works | |
| 83 | 83 | */ | |
| 84 | 84 | class TestDoubleBenchmarker { | |
| 85 | - constructor() { | ||
| 86 | - this.name = 'test-double'; | ||
| 85 | + constructor(type) { | ||
| 86 | + // `type` is the type ofbenchmarker. Possible values are 'http' and 'http2'. | ||
| 87 | + this.name = `test-double-${type}`; | ||
| 87 | 88 | this.executable = path.resolve(__dirname, '_test-double-benchmarker.js'); | |
| 88 | 89 | this.present = fs.existsSync(this.executable); | |
| 90 | + this.type = type; | ||
| 89 | 91 | } | |
| 90 | 92 | ||
| 91 | 93 | create(options) { | |
@@ -94,10 +96,9 @@ class TestDoubleBenchmarker { | |||
| 94 | 96 | test_url: `http://127.0.0.1:${options.port}${options.path}`, | |
| 95 | 97 | }, process.env); | |
| 96 | 98 | ||
| 97 | - const child = child_process.fork(this.executable, { | ||
| 98 | - silent: true, | ||
| 99 | - env | ||
| 100 | - }); | ||
| 99 | + const child = child_process.fork(this.executable, | ||
| 100 | + [this.type], | ||
| 101 | + { silent: true, env }); | ||
| 101 | 102 | return child; | |
| 102 | 103 | } | |
| 103 | 104 | ||
@@ -167,7 +168,8 @@ class H2LoadBenchmarker { | |||
| 167 | 168 | const http_benchmarkers = [ | |
| 168 | 169 | new WrkBenchmarker(), | |
| 169 | 170 | new AutocannonBenchmarker(), | |
| 170 | - new TestDoubleBenchmarker(), | ||
| 171 | + new TestDoubleBenchmarker('http'), | ||
| 172 | + new TestDoubleBenchmarker('http2'), | ||
| 171 | 173 | new H2LoadBenchmarker() | |
| 172 | 174 | ]; | |
| 173 | 175 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,20 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - const http = require('http'); | ||
| 3 | + const myModule = process.argv[2]; | ||
| 4 | + if (!['http', 'http2'].includes(myModule)) { | ||
| 5 | + throw new Error(`Invalid module for benchmark test double: ${myModule}`); | ||
| 6 | + } | ||
| 7 | + | ||
| 8 | + const http = require(myModule); | ||
| 4 | 9 | ||
| 5 | 10 | const duration = process.env.duration || 0; | |
| 6 | 11 | const url = process.env.test_url; | |
| 7 | 12 | ||
| 8 | 13 | const start = process.hrtime(); | |
| 9 | 14 | let throughput = 0; | |
| 10 | 15 | ||
| 11 | - function request(res) { | ||
| 12 | - res.on('data', () => {}); | ||
| 16 | + function request(res, client) { | ||
| 17 | + res.resume(); | ||
| 13 | 18 | res.on('error', () => {}); | |
| 14 | 19 | res.on('end', () => { | |
| 15 | 20 | throughput++; | |
@@ -18,12 +23,21 @@ function request(res) { | |||
| 18 | 23 | run(); | |
| 19 | 24 | } else { | |
| 20 | 25 | console.log(JSON.stringify({ throughput })); | |
| 26 | + if (client) { | ||
| 27 | + client.destroy(); | ||
| 28 | + } | ||
| 21 | 29 | } | |
| 22 | 30 | }); | |
| 23 | 31 | } | |
| 24 | 32 | ||
| 25 | 33 | function run() { | |
| 26 | - http.get(url, request); | ||
| 34 | + if (http.get) { // HTTP | ||
| 35 | + http.get(url, request); | ||
| 36 | + } else { // HTTP/2 | ||
| 37 | + const client = http.connect(url); | ||
| 38 | + client.on('error', (e) => { throw e; }); | ||
| 39 | + request(client.request(), client); | ||
| 40 | + } | ||
| 27 | 41 | } | |
| 28 | 42 | ||
| 29 | 43 | run(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,7 @@ const PORT = common.PORT; | |||
| 5 | 5 | ||
| 6 | 6 | const bench = common.createBenchmark(main, { | |
| 7 | 7 | n: [1e3], | |
| 8 | - nheaders: [0, 10, 100, 1000], | ||
| 9 | - benchmarker: ['h2load'] | ||
| 8 | + nheaders: [0, 10, 100, 1000] | ||
| 10 | 9 | }, { flags: ['--no-warnings'] }); | |
| 11 | 10 | ||
| 12 | 11 | function main({ n, nheaders }) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ const runBenchmark = require('../common/benchmark'); | |||
| 13 | 13 | ||
| 14 | 14 | runBenchmark('http', | |
| 15 | 15 | [ | |
| 16 | - 'benchmarker=test-double', | ||
| 16 | + 'benchmarker=test-double-http', | ||
| 17 | 17 | 'c=1', | |
| 18 | 18 | 'chunkedEnc=true', | |
| 19 | 19 | 'chunks=0', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + | ||
| 5 | + if (!common.enoughTestMem) | ||
| 6 | + common.skip('Insufficient memory for HTTP/2 benchmark test'); | ||
| 7 | + | ||
| 8 | + // Because the http benchmarks use hardcoded ports, this should be in sequential | ||
| 9 | + // rather than parallel to make sure it does not conflict with tests that choose | ||
| 10 | + // random available ports. | ||
| 11 | + | ||
| 12 | + const runBenchmark = require('../common/benchmark'); | ||
| 13 | + | ||
| 14 | + runBenchmark('http2', | ||
| 15 | + [ | ||
| 16 | + 'benchmarker=test-double-http2', | ||
| 17 | + 'clients=1', | ||
| 18 | + 'length=65536', | ||
| 19 | + 'n=1', | ||
| 20 | + 'nheaders=0', | ||
| 21 | + 'requests=1', | ||
| 22 | + 'streams=1' | ||
| 23 | + ], | ||
| 24 | + { | ||
| 25 | + NODEJS_BENCHMARK_ZERO_ALLOWED: 1, | ||
| 26 | + duration: 0 | ||
| 27 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments