MCPcopy Index your code
hub / github.com/nodejs/node / runAb

Function runAb

test/pummel/test-keep-alive.js:50–93  ·  view source on GitHub ↗
(opts, callback)

Source from the content-addressed store, hash-verified

48
49
50const runAb = (opts, callback) => {
51 const args = [
52 '-c', opts.concurrent || 50,
53 '-t', opts.threads || 2,
54 '-d', opts.duration || '5s',
55 ];
56
57 if (!opts.keepalive) {
58 args.push('-H');
59 args.push('Connection: close');
60 }
61
62 args.push(url.format({ hostname: '127.0.0.1',
63 port: opts.port, protocol: 'http' }));
64
65 const child = child_process.spawn('wrk', args);
66 child.stderr.pipe(process.stderr);
67 child.stdout.setEncoding('utf8');
68
69 let stdout;
70
71 child.stdout.on('data', (data) => stdout += data);
72
73 child.on('close', (code, signal) => {
74 if (code) {
75 console.error(code, signal);
76 process.exit(code);
77 return;
78 }
79
80 let matches = /Requests\/sec:\s*(\d+)\./i.exec(stdout);
81 const reqSec = parseInt(matches[1]);
82
83 matches = /Keep-Alive requests:\s*(\d+)/i.exec(stdout);
84 let keepAliveRequests;
85 if (matches) {
86 keepAliveRequests = parseInt(matches[1]);
87 } else {
88 keepAliveRequests = 0;
89 }
90
91 callback(reqSec, keepAliveRequests);
92 });
93};
94
95server.listen(0, () => {
96 const port = server.address().port;

Callers 1

test-keep-alive.jsFile · 0.70

Calls 8

formatMethod · 0.65
callbackFunction · 0.50
pushMethod · 0.45
setEncodingMethod · 0.45
onMethod · 0.45
errorMethod · 0.45
exitMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected