Ktor, Netty and increasing the number of threads per endpoint

Viewed 753

Using Ktor and Kotlin 1.5 to implement a REST service backed by Netty. A couple of things about this service:

  1. "Work" takes non-trivial amount of time to complete.
  2. A unique client endpoint sends multiple requests in parallel to this service.
  3. There are only a handful of unique client endpoints.

The service is not scaling as expected. We ran a load test with parallel requests coming from a single client and we noticed that we only have two threads on the server actually processing the requests. It's not a resource starvation problem - there is plenty of network, memory, CPU, etc. and it doesn't matter how many requests we fire up in parallel - it's always two threads keeping busy, while the others are sitting idle.

Is there a parameter we can configure to increase the number of threads available to process requests for specific endpoints?

2 Answers

You might need to check the following configuration options for Netty https://ktor.io/docs/engines.html#configure-engine

connectionGroupSize = x
workerGroupSize = y
callGroupSize = z

Default values usually are set rather low and tweaking them could be useful for the time-consuming 'work'. The exact values might vary depending on the available resources.

Related