mcollina / autocannon

fast HTTP/1.1 benchmarking tool written in Node.js
MIT License
7.83k stars 325 forks source link

what triggers the error #110

Closed binarytracer closed 7 years ago

binarytracer commented 7 years ago

Im currently benchmarking an Express App,

benchmark.js

const http = require('http');
const autocannon = require('autocannon');

function handle(req, res) {
  res.end('hello world');
}

function startBench() {
  function finishedBench(err, res) {
    console.log('finished benchmarking');
    // console.log('finished bench', err, res);
  }

  const config = {
    url: 'http://localhost:3000/596c473a12288a0bd490a517',
    amount: 6000,
  };
  const instance = autocannon(config, finishedBench);

  instance.on('reqError', (...args) => {
    console.log('---------------------');
    console.log(args);
    console.log('---------------------');
  });

  autocannon.track(instance, { renderResultTable: true });

  // this is used to kill the instance on CTRL-C
  process.once('SIGINT', () => {
    instance.stop();
  });
}

const server = http.createServer(handle);

server.listen(0, startBench);

round 1

STAT AVG STDEV MAX
Latency (ms) 44.94 3.52 96
Req/Sec 214.29 24.89 225
Bytes/Sec 149 kB 17.3 kB 164 kB

6k requests in 28s, 4.18 MB read


round 2

  const config = {
    url: 'http://localhost:3000/596c473a12288a0bd490a517',
    connections: 6000,
    timeout: 60,
    amount: 6000,
  };
  const instance = autocannon(config, finishedBench);
STAT AVG STDEV MAX
Latency (ms) 4822.17 2061.34 9641
Req/Sec 493.37 581.35 1600
Bytes/Sec 346 kB 410 kB 1.18 MB

5k requests in 12s, 3.78 MB read 573 errors (573 timeouts) finished benchmarking

Error logging

...
---------------------
---------------------
[]
---------------------
---------------------
[]
---------------------
---------------------
[]
---------------------
...

I would like to know what causes it to trigger errors / timeout?

mcollina commented 7 years ago

timeout: the number of seconds we wait for a response to arrive. We wait 10 by default. This is consistent with the MAX latency you are seeing, 9 seconds. Some requests go over.

errors: timeout plus other errors, like 500.

binarytracer commented 7 years ago

Thanks, @mcollina

just updated my post.

knowing that kind of situation, what needs to be done? Do i need to to adjust the express application or i need to adjust autocannon configuration?

mcollina commented 7 years ago

The bug is in the express application.

GlenTiki commented 7 years ago

You can adjust the timeout period to be larger if you want to see what the max delay is without a timeout. Check the readme for how to do this. However a 10 second+ latency/response delay is probably not what you want for your application anyway, so I would advise you to keep treating it as an error :)

binarytracer commented 7 years ago

thanks @thekemkid and @mcollina, :thumbsup: this npm works great.