summaryrefslogtreecommitdiff
path: root/benchmark/async_hooks/http-server.js
blob: 9e1c1214240eaaea3e4277bf92065802d4badba6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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();
      });
    });
}