Skip to content

Commit b48cfcc

Browse files
legendecastargos
authored andcommitted
benchmark: add benchmark on async_hooks enabled http server
PR-URL: #31100 Refs: nodejs/diagnostics#124 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7aa7759 commit b48cfcc

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
constcommon=require('../common.js');
3+
4+
constbench=common.createBenchmark(main,{
5+
asyncHooks: ['init','before','after','all','disabled','none'],
6+
connections: [50,500]
7+
});
8+
9+
functionmain({ asyncHooks, connections }){
10+
if(asyncHooks!=='none'){
11+
lethooks={
12+
init(){},
13+
before(){},
14+
after(){},
15+
destroy(){},
16+
promiseResolve(){}
17+
};
18+
if(asyncHooks!=='all'||asyncHooks!=='disabled'){
19+
hooks={
20+
[asyncHooks]: ()=>{}
21+
};
22+
}
23+
consthook=require('async_hooks').createHook(hooks);
24+
if(asyncHooks!=='disabled'){
25+
hook.enable();
26+
}
27+
}
28+
constserver=require('../fixtures/simple-http-server.js')
29+
.listen(common.PORT)
30+
.on('listening',()=>{
31+
constpath='/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‎

Lines changed: 2 additions & 0 deletions
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)