Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b48cfcc

Browse files
legendecastargos
authored andcommittedJan 14, 2020
benchmark: add benchmark on async_hooks enabled http server
PR-URL: #31100 Refs: nodejs/diagnostics#124 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7aa7759 commit b48cfcc

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
 

‎benchmark/async_hooks/http-server.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
4+
const bench = common.createBenchmark(main, {
5+
asyncHooks: ['init', 'before', 'after', 'all', 'disabled', 'none'],
6+
connections: [50, 500]
7+
});
8+
9+
function main({ asyncHooks, connections }) {
10+
if (asyncHooks !== 'none') {
11+
let hooks = {
12+
init() {},
13+
before() {},
14+
after() {},
15+
destroy() {},
16+
promiseResolve() {}
17+
};
18+
if (asyncHooks !== 'all' || asyncHooks !== 'disabled') {
19+
hooks = {
20+
[asyncHooks]: () => {}
21+
};
22+
}
23+
const hook = require('async_hooks').createHook(hooks);
24+
if (asyncHooks !== 'disabled') {
25+
hook.enable();
26+
}
27+
}
28+
const server = require('../fixtures/simple-http-server.js')
29+
.listen(common.PORT)
30+
.on('listening', () => {
31+
const path = '/buffer/4/4/normal/1';
32+
33+
bench.http({
34+
connections,
35+
path,
36+
}, () => {
37+
server.close();
38+
});
39+
});
40+
}

‎test/benchmark/test-benchmark-async-hooks.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const runBenchmark = require('../common/benchmark');
1212

1313
runBenchmark('async_hooks',
1414
[
15+
'asyncHooks=all',
16+
'connections=50',
1517
'method=trackingDisabled',
1618
'n=10'
1719
],

0 commit comments

Comments
 (0)
Please sign in to comment.