summaryrefslogtreecommitdiff
path: root/deps/node/benchmark/http/cluster.js
blob: 35d0ba98d00b434261f5661bea026d14afddb956 (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
41
'use strict';
const common = require('../common.js');
const PORT = common.PORT;

const cluster = require('cluster');
if (cluster.isMaster) {
  var bench = common.createBenchmark(main, {
    // unicode confuses ab on os x.
    type: ['bytes', 'buffer'],
    len: [4, 1024, 102400],
    c: [50, 500]
  });
} else {
  const port = parseInt(process.env.PORT || PORT);
  require('../fixtures/simple-http-server.js').listen(port);
}

function main({ type, len, c }) {
  process.env.PORT = PORT;
  var workers = 0;
  const w1 = cluster.fork();
  const w2 = cluster.fork();

  cluster.on('listening', () => {
    workers++;
    if (workers < 2)
      return;

    setImmediate(() => {
      const path = `/${type}/${len}`;

      bench.http({
        path: path,
        connections: c
      }, () => {
        w1.destroy();
        w2.destroy();
      });
    });
  });
}