Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
headers: params.headers,
body: params.body
}
// Create the test and finish handler.
const instance = Autocannon(opts, (err, result) => {
if (err) {
console.error(err)
process.exit(-1)
}
console.log('Detailed Result:', '\n\n', result)
})
// Starts the test and shows a pretty progress bar while it runs
Autocannon.track(instance)
function run (opts, cb) {
console.log('\n===========Benching ' + opts.title + '=============')
var instance = autocannon(opts, cb)
autocannon.track(instance)
}
runner.on('bench', function (data, cannon) {
process.stdout.write('==> ')
autocannon.track(cannon)
cannon.on('done', function () {
console.log()
})
})
]
const instance = autocannon({
title: 'ssr-example',
url,
connections: 10,
pipelining: 1,
duration: 10,
requests,
}, console.log)
process.once('SIGINT', () => {
instance.stop()
})
autocannon.track(instance)
const shoot = (port) => new Promise((resolve) => {
const opts = {
url: `http://localhost:${port}/`,
connections: 100,
pipelining: 4,
duration: 30,
timeout: 30
}
currentBenchmark = autocannon(opts)
currentBenchmark.once('done', resolve)
autocannon.track(currentBenchmark, { renderResultsTable: false })
})
var instance = autocannon(opts, function onResult(err, result) {
if (err) {
cb(err);
return;
}
if (save) {
writeResult(handler, version, result);
}
cb();
});
if (opts.track && save) {
autocannon.track(instance);
}
}
});
stats.rpsMap.push({
count: stats.rpsCount,
date: now,
});
stats.rpsCount = 0;
}, 1000);
engine.on('done', function(results) {
delete stats.rpsCount;
clearInterval(interval);
});
autocannon.track(engine, {
renderProgressBar: true,
});
};
duration: DURATION,
connections: CONNECTIONS,
headers: {
authorization: 'ROOTid',
org: 'CONCH'
},
requests: [
{
method: 'GET',
path: getPath()
}
],
setupClient: setupClient
}, onComplete)
autocannon.track(instance, {renderProgressBar: !DEBUG})
instance.on('response', onResponse)
}
async function run(lib: string, url: string) {
const _targetPath = path.join(basePath, lib)
const child = childProcess.spawn('node', [_targetPath], {
stdio: 'inherit',
});
await sleep(2000)
benchmarksMDStream.write('\n')
benchmarksMDStream.write(`### ${lib}\n`)
benchmarksMDStream.write('\n')
const { requests, throughput } = await autocannon({
...opt,
url,
})
child.kill()
benchmarksMDStream.write(table([
['Stat', 'Avg', 'Stdev', 'Min'],
['Req/Sec', requests.average, requests.stddev, requests.min],
['Bytes/Sec', size(throughput.average), size(requests.stddev), size(requests.min)]
]))
benchmarksMDStream.write('\n')
benchmarksMDStream.write('\n')
}
title: string,
urlPath: string,
options: Omit = {},
): Promise {
const config = {
url: this.buildUrl(urlPath),
duration: this.duration,
title,
...options,
headers: {
'content-type': 'application/json',
...options.headers,
},
};
const data = await autocannon(config);
assert.equal(
data.non2xx,
0,
'No request should have failed with non-2xx status code.',
);
const stats: EndpointStats = {
requestsPerSecond: data.requests.average,
latency: data.latency.average,
};
return stats;
}