I developed a small tool for load testing of a microservice via REST. The tool is based on Ktor Client. At the moment, for each simulated user and for each test iteration a HttpClient is instantiated and closed at the end of the test iteration. At the moment I am using the Apache Engine.
I noticed that a lot of threads are created - with simulated 500 concurrent users there are up to 3000 threads. Most of the threads come from Ktor and Apache HttpClient. I think it is too much.
My question is: should I reuse the HttpClients, i.e. use them across the CUs? What would be the right pattern for such application?
I tried to use the CIO engine, but it failed: at a higher number of CUs the program crashes. The exception looks something like this:
Caused by: java.net.BindException: Address already in use: no further information
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
… 4 common frames omitted
With thanks in advance, Vladimir