mcollina / autocannon

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

Requests (from options) are repeated when overallRate>1 - should be configurable #251

Open md-fid opened 4 years ago

md-fid commented 4 years ago

Description

When configuring autocannon to run with a specific rate (rate or requests/secs) and also have a set of "prepared" requests given with "requests" option, then these requests are repeated. This is okay when running GET (reading) requests. But for other HTTP methods this could cause error like "409 conflict".

We have a scenario where we have a flat file of numbers. This file is used to prepare an Array of POST/PUT requests with specific paths including these numbers. When we then run autocannon for benchmarking, we retrieve a high number of errors in responses with "409 Conflict" because on server side the number from the the request path is unique.

Possible solution

It should be configurable that the num of rates (overallRate) should not repeat the one request from the Array but take the next one.

mcollina commented 4 years ago

Would you like to send a PR to implement this functionality?

EladIsraeli commented 3 years ago

@md-fid @mcollina I tried to reproduce the issue in my local environment and I could not generate the issue you presented. I create 5 requests:

{
    url: path,
    connections: 1,
    overallRate: 5,
    amount: 5,
    requests: [
      {
        method: 'GET',
        path: '/users/1',
        onResponse (status, body) {
        }
      },
      {
        method: 'GET',
        path: '/users/2',
        onResponse (status, body) {
        }
      },
      {
        method: 'GET',
        path: '/users/3',
        onResponse (status, body) {
        }
      },
      {
        method: 'GET',
        path: '/users/4',
        onResponse (status, body) {
        }
      },
      {
        method: 'GET',
        path: '/users/5',
        onResponse (status, body) {
        }
      }
    ]
  }

So basically when you limit the amount to 5 and the autocannon will not repeat over the requests that already have been called.

Is it a good enough solution? 'cause otherwise I could not really understand the issue you're facing nor the solution.