6.27.1 Configuring Server Thread Pools

The HTTP server is built on Netty which is designed as a non-blocking I/O toolkit in an event loop model.

The Netty worker event loop uses the “default” named event loop group. That event loop can be configured through micronaut.server.netty.worker, or micronaut.netty.event-loops.default, with the latter having precedence.

🔗

Table 1. Configuration Properties for NettyHttpServerConfiguration$Worker
PropertyTypeDescription

micronaut.server.netty.worker.event-loop-group

java.lang.String

Sets the name to use.

micronaut.server.netty.worker.threads

int

Sets the number of threads for the event loop group.

micronaut.server.netty.worker.io-ratio

java.lang.Integer

Sets the I/O ratio.

micronaut.server.netty.worker.executor

java.lang.String

Sets the name of the executor.

micronaut.server.netty.worker.prefer-native-transport

boolean

Set whether to prefer the native transport if available

The parent event loop can be configured with micronaut.server.netty.parent with the same configuration options.

The server can also be configured to use a different named worker event loop:

Using a different event loop for the server

  1. micronaut:
  2. server:
  3. netty:
  4. worker:
  5. event-loop-group: other
  6. netty:
  7. event-loops:
  8. other:
  9. num-threads: 10
The default value for the number of threads is the value of the system property io.netty.eventLoopThreads, or if not specified, the available processors x 2.

See the following table for configuring event loops:

🔗

Table 2. Configuration Properties for DefaultEventLoopGroupConfiguration
PropertyTypeDescription

micronaut.netty.event-loops..num-threads

int

micronaut.netty.event-loops..io-ratio

java.lang.Integer

micronaut.netty.event-loops..prefer-native-transport

boolean

micronaut.netty.event-loops..executor

java.lang.String

Blocking Operations

When dealing with blocking operations, Micronaut will shift the blocking operations to an unbound, caching I/O thread pool by default. You can configure the I/O thread pool using the ExecutorConfiguration named io. For example:

Configuring the Server I/O Thread Pool

  1. micronaut:
  2. executors:
  3. io:
  4. type: fixed
  5. nThreads: 75

The above configuration will create a fixed thread pool with 75 threads.