6.28 Configuring the HTTP Server

The HTTP server features a number of configuration options you may wish to tweak. They are defined in the NettyHttpServerConfiguration configuration class, which extends HttpServerConfiguration.

The following example shows how to tweak configuration options for the server via application.yml:

Configuring HTTP server settings

  1. micronaut:
  2. server:
  3. maxRequestSize: 1MB
  4. host: localhost (1)
  5. netty:
  6. maxHeaderSize: 500KB (2)
  7. worker:
  8. threads: 8 (3)
  9. childOptions:
  10. autoRead: true (4)
1By default Micronaut will bind to all the network interfaces. Use localhost to bind only to loopback network interface
2Maximum size for headers
3Number of netty worker threads
4Auto read request body

🔗

Table 1. Configuration Properties for NettyHttpServerConfiguration
PropertyTypeDescription

micronaut.server.netty.child-options

java.util.Map

Sets the Netty child worker options.

micronaut.server.netty.options

java.util.Map

Sets the channel options.

micronaut.server.netty.max-initial-line-length

int

Sets the maximum initial line length for the HTTP request. Default value (4096).

micronaut.server.netty.max-header-size

int

Sets the maximum size of any one header. Default value (8192).

micronaut.server.netty.max-chunk-size

int

Sets the maximum size of any single request chunk. Default value (8192).

micronaut.server.netty.chunked-supported

boolean

Sets whether chunked transfer encoding is supported. Default value (true).

micronaut.server.netty.validate-headers

boolean

Sets whether to validate incoming headers. Default value (true).

micronaut.server.netty.initial-buffer-size

int

Sets the initial buffer size. Default value (128).

micronaut.server.netty.log-level

io.netty.handler.logging.LogLevel

Sets the Netty log level.

micronaut.server.netty.compression-threshold

int

Sets the minimum size of a request body must be in order to be compressed. Default value (1024).

micronaut.server.netty.compression-level

int

Sets the compression level (0-9). Default value (6).

micronaut.server.netty.use-native-transport

boolean

Sets whether to use netty’s native transport (epoll or kqueue) if available . Default value (false).

micronaut.server.netty.fallback-protocol

java.lang.String

Sets the fallback protocol to use when negotiating via ALPN.

Using Native Transports

The native Netty transports add features specific to a particular platform, generate less garbage, and generally improve performance when compared to the NIO based transport.

To enable native transports first add a necessarily dependency:

For macOS:

  1. runtime("io.netty:netty-transport-native-kqueue:osx-x86_64")
  1. <dependency>
  2. <groupId>io.netty</groupId>
  3. <artifactId>netty-transport-native-kqueue</artifactId>
  4. <scope>runtime</scope>
  5. <classifier>osx-x86_64</classifier>
  6. </dependency>

For Linux on ARM64:

  1. runtime("io.netty:netty-transport-native-epoll:linux-aarch_64")
  1. <dependency>
  2. <groupId>io.netty</groupId>
  3. <artifactId>netty-transport-native-epoll</artifactId>
  4. <scope>runtime</scope>
  5. <classifier>linux-aarch_64</classifier>
  6. </dependency>

For Linux on x86:

  1. runtime("io.netty:netty-transport-native-epoll:linux-x86_64")
  1. <dependency>
  2. <groupId>io.netty</groupId>
  3. <artifactId>netty-transport-native-epoll</artifactId>
  4. <scope>runtime</scope>
  5. <classifier>linux-x86_64</classifier>
  6. </dependency>

Then configure the default event loop group to prefer native transports:

Configuring The Default Event Loop to Prefer Native Transports

  1. micronaut:
  2. netty:
  3. event-loops:
  4. default:
  5. prefer-native-transport: true