6.28.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.netty.event-loops.default.

The event loop configuration under micronaut.server.netty.worker will only be used if the event-loop-group is set to a name and that name doesn’t correspond to any micronaut.netty.event-loops configuration. This behavior is deprecated and will be removed in a future version. Use micronaut.netty.event-loops.* for any event loop group configuration beyond setting the name through event-loop-group. This does not apply to the parent event loop configuration (micronaut.server.netty.parent).

🔗

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

micronaut.server.netty.worker.shutdown-quiet-period

java.time.Duration

Set the shutdown quiet period

micronaut.server.netty.worker.shutdown-timeout

java.time.Duration

Set the shutdown timeout (must be >= shutdownQuietPeriod)

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

micronaut.netty.event-loops..shutdown-quiet-period

java.time.Duration

micronaut.netty.event-loops..shutdown-timeout

java.time.Duration

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.