6.29 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
micronaut:
server:
maxRequestSize: 1MB
host: localhost (1)
netty:
maxHeaderSize: 500KB (2)
worker:
threads: 8 (3)
childOptions:
autoRead: true (4)
1 | By default Micronaut will bind to all the network interfaces. Use localhost to bind only to loopback network interface |
2 | Maximum size for headers |
3 | Number of netty worker threads |
4 | Auto read request body |
Property | Type | Description |
---|---|---|
| java.util.Map | Sets the Netty child worker options. |
| java.util.Map | Sets the channel options. |
| int | Sets the maximum initial line length for the HTTP request. Default value (4096). |
| int | Sets the maximum size of any one header. Default value (8192). |
| int | Sets the maximum size of any single request chunk. Default value (8192). |
| boolean | Sets whether chunked transfer encoding is supported. Default value (true). |
| boolean | Sets whether to validate incoming headers. Default value (true). |
| int | Sets the initial buffer size. Default value (128). |
| io.netty.handler.logging.LogLevel | Sets the Netty log level. |
| int | Sets the minimum size of a request body must be in order to be compressed. Default value (1024). |
| int | Sets the compression level (0-9). Default value (6). |
| boolean | Sets whether to use netty’s native transport (epoll or kqueue) if available . Default value (false). |
| 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:
runtime("io.netty:netty-transport-native-kqueue:osx-x86_64")
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
<scope>runtime</scope>
<classifier>osx-x86_64</classifier>
</dependency>
For Linux on ARM64:
runtime("io.netty:netty-transport-native-epoll:linux-aarch_64")
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<scope>runtime</scope>
<classifier>linux-aarch_64</classifier>
</dependency>
For Linux on x86:
runtime("io.netty:netty-transport-native-epoll:linux-x86_64")
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<scope>runtime</scope>
<classifier>linux-x86_64</classifier>
</dependency>
Then configure the default event loop group to prefer native transports:
Configuring The Default Event Loop to Prefer Native Transports
micronaut:
netty:
event-loops:
default:
prefer-native-transport: true