From 827d3fea0e17ba1db642df43fb92b7d6f51e8d4a Mon Sep 17 00:00:00 2001 From: legendecas Date: Thu, 26 Dec 2019 16:21:18 +0800 Subject: [PATCH] benchmark: add benchmark on async_hooks enabled http server PR-URL: https://github.com/nodejs/node/pull/31100 Refs: https://github.com/nodejs/diagnostics/issues/124 Reviewed-By: Rich Trott Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell --- benchmark/async_hooks/http-server.js | 40 ++++++++++++++++++++ test/benchmark/test-benchmark-async-hooks.js | 2 + 2 files changed, 42 insertions(+) create mode 100644 benchmark/async_hooks/http-server.js diff --git a/benchmark/async_hooks/http-server.js b/benchmark/async_hooks/http-server.js new file mode 100644 index 00000000000000..493500fd1f2d66 --- /dev/null +++ b/benchmark/async_hooks/http-server.js @@ -0,0 +1,40 @@ +'use strict'; +const common = require('../common.js'); + +const bench = common.createBenchmark(main, { + asyncHooks: ['init', 'before', 'after', 'all', 'disabled', 'none'], + connections: [50, 500] +}); + +function main({ asyncHooks, connections }) { + if (asyncHooks !== 'none') { + let hooks = { + init() {}, + before() {}, + after() {}, + destroy() {}, + promiseResolve() {} + }; + if (asyncHooks !== 'all' || asyncHooks !== 'disabled') { + hooks = { + [asyncHooks]: () => {} + }; + } + const hook = require('async_hooks').createHook(hooks); + if (asyncHooks !== 'disabled') { + hook.enable(); + } + } + const server = require('../fixtures/simple-http-server.js') + .listen(common.PORT) + .on('listening', () => { + const path = '/buffer/4/4/normal/1'; + + bench.http({ + connections, + path, + }, () => { + server.close(); + }); + }); +} diff --git a/test/benchmark/test-benchmark-async-hooks.js b/test/benchmark/test-benchmark-async-hooks.js index 4cb6f89a8c70e3..9951d8c9330804 100644 --- a/test/benchmark/test-benchmark-async-hooks.js +++ b/test/benchmark/test-benchmark-async-hooks.js @@ -12,6 +12,8 @@ const runBenchmark = require('../common/benchmark'); runBenchmark('async_hooks', [ + 'asyncHooks=all', + 'connections=50', 'method=trackingDisabled', 'n=10' ],