2019-12-26 16:21:18 +08:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
asyncHooks: ['init', 'before', 'after', 'all', 'disabled', 'none'],
|
2020-02-12 19:33:33 +01:00
|
|
|
connections: [50, 500],
|
2023-02-01 22:46:09 +01:00
|
|
|
duration: 5,
|
2019-12-26 16:21:18 +08:00
|
|
|
});
|
|
|
|
|
2020-02-12 19:33:33 +01:00
|
|
|
function main({ asyncHooks, connections, duration }) {
|
2019-12-26 16:21:18 +08:00
|
|
|
if (asyncHooks !== 'none') {
|
|
|
|
let hooks = {
|
|
|
|
init() {},
|
|
|
|
before() {},
|
|
|
|
after() {},
|
|
|
|
destroy() {},
|
2023-02-01 22:46:09 +01:00
|
|
|
promiseResolve() {},
|
2019-12-26 16:21:18 +08:00
|
|
|
};
|
|
|
|
if (asyncHooks !== 'all' || asyncHooks !== 'disabled') {
|
|
|
|
hooks = {
|
2023-02-01 22:46:09 +01:00
|
|
|
[asyncHooks]: () => {},
|
2019-12-26 16:21:18 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
const hook = require('async_hooks').createHook(hooks);
|
|
|
|
if (asyncHooks !== 'disabled') {
|
|
|
|
hook.enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const server = require('../fixtures/simple-http-server.js')
|
2020-01-02 23:09:20 +08:00
|
|
|
.listen(common.PORT)
|
|
|
|
.on('listening', () => {
|
|
|
|
const path = '/buffer/4/4/normal/1';
|
2019-12-26 16:21:18 +08:00
|
|
|
|
2020-01-02 23:09:20 +08:00
|
|
|
bench.http({
|
|
|
|
connections,
|
|
|
|
path,
|
2023-02-01 22:46:09 +01:00
|
|
|
duration,
|
2020-01-02 23:09:20 +08:00
|
|
|
}, () => {
|
|
|
|
server.close();
|
|
|
|
});
|
2019-12-26 16:21:18 +08:00
|
|
|
});
|
|
|
|
}
|