• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3const PORT = common.PORT;
4
5const cluster = require('cluster');
6let bench;
7if (cluster.isMaster) {
8  bench = common.createBenchmark(main, {
9    // Unicode confuses ab on os x.
10    type: ['bytes', 'buffer'],
11    len: [4, 1024, 102400],
12    c: [50, 500],
13    duration: 5,
14  });
15} else {
16  const port = parseInt(process.env.PORT || PORT);
17  require('../fixtures/simple-http-server.js').listen(port);
18}
19
20function main({ type, len, c, duration }) {
21  process.env.PORT = PORT;
22  let workers = 0;
23  const w1 = cluster.fork();
24  const w2 = cluster.fork();
25
26  cluster.on('listening', () => {
27    workers++;
28    if (workers < 2)
29      return;
30
31    setImmediate(() => {
32      const path = `/${type}/${len}`;
33
34      bench.http({
35        path: path,
36        connections: c,
37        duration
38      }, () => {
39        w1.destroy();
40        w2.destroy();
41      });
42    });
43  });
44}
45