alexfernandez / loadtest

Runs a load test on the selected URL. Fast and easy to use. Can be integrated in your own workflow using the API.
MIT License
2.55k stars 206 forks source link

keepAlive and maxSockets #199

Closed marcelkottmann closed 10 months ago

marcelkottmann commented 2 years ago

Hi, I would like to understand why maxSockets is set here to a magic value of 10. Additionally I don't understand why the maxSockets depends on the requestsPerSecond in lib/httpClient.js.

if (this.params.agentKeepAlive) {
...
  let maxSockets = 10;
  if (this.params.requestsPerSecond) {
    maxSockets += Math.floor(this.params.requestsPerSecond);
  }
...
}

I think it's sufficient and I also expected to have a single socket for all http requests if keepAlive option is enabled. So my code change proposal would be to change this to

if (this.params.agentKeepAlive) {
...
  let maxSockets = 1;
...
}

Maybe there is a usecase I don't see, which makes it necessary to set maxSockets to a higher value.

alexfernandez commented 11 months ago

Wow, talk about responding late to issues! :open_mouth: I think that you are right, with keepalive on there should be no need for max sockets, but it shouldn't hurt either.

When there is a spec for requests per second, each client will have multiple high resolution timers making independent requests. This is because you can specify concurrency (number of clients) and requests per second separately, therefore each client can be responsible for making several requests per second, and can have them open in flight.

HTH, and sorry for the inexcusable delay!