Production checklist

Note

Note that the advices in this page are not always applicable for every use case and thus should be applied with caution. Do not apply the changes you really do not need.

You may want to consider the following options before putting your Armeria application into production.

  • Specify the maximum number of accepted connections. The default is unbounded.

    import com.linecorp.armeria.server.ServerBuilder;
    
    ServerBuilder sb = new ServerBuilder();
    sb.maxNumConnections(500);
  • Specify an alternative blockingTaskExecutor based on expected workload if your server has a Service that uses it, such as TomcatService, JettyService and THttpService with synchronous service implementation. The default is a simple ThreadPoolExecutor with 200 threads and an unbounded queue, provided by CommonPools.

    import com.linecorp.armeria.server.ServerBuilder;
    
    ServerBuilder sb = new ServerBuilder();
    sb.blockingTaskExecutor(myBoundedExecutor);
  • Specify the default limits of an HTTP request or response.

    import java.time.Duration;
    import com.linecorp.armeria.client.ClientBuilder;
    import com.linecorp.armeria.server.ServerBuilder;
    
    // Server-side
    ServerBuilder sb = new ServerBuilder();
    sb.defaultMaxRequestLength(1048576); // bytes (default: 10 MiB)
    sb.defaultRequestTimeout(Duration.ofSeconds(7)); // (default: 10 seconds)
    
    // Client-side
    ClientBuilder cb = new ClientBuilder(...); // or HttpClientBuilder
    cb.defaultMaxResponseLength(1048576); // bytes (default: 10 MiB)
    cb.defaultResponseTimeout(Duration.ofSeconds(10)); // (default: 15 seconds)
  • Decorate your services with ThrottlingService which lets you fail the incoming requests based on a policy, such as ‘fail if the rate of requests exceed a certain threshold.’

    import com.linecorp.armeria.server.throttling.RateLimitingThrottlingStrategy;
    import com.linecorp.armeria.server.throttling.ThrottlingHttpService;
    
    ServerBuilder sb = new ServerBuilder();
    sb.service("/my_service", // Allow up to 1000 requests/sec.
               myService.decorate(ThrottlingHttpService.newDecorator(
                       new RateLimitingThrottlingStrategy(1000.0))));
  • Decorate your clients with RetryingClient. See Automatic retry.

  • Decorate your clients with CircuitBreakerClient. See Circuit breaker.

    Tip

    You can use Armeria’s CircuitBreaker API for non-Armeria clients without circuit breaker support. See Using CircuitBreaker with non-Armeria client.

  • Tune the socket options.

    import com.linecorp.armeria.client.ClientBuilder;
    import com.linecorp.armeria.client.ClientFactory;
    import com.linecorp.armeria.client.ClientFactoryBuilder;
    import com.linecorp.armeria.server.ServerBuilder;
    import io.netty.channel.ChannelOption;
    
    // Server-side
    ServerBuilder sb = new ServerBuilder();
    sb.channelOption(ChannelOption.SO_BACKLOG, ...);
    sb.channelOption(ChannelOption.SO_SNDBUF, ...);
    sb.channelOption(ChannelOption.SO_RCVBUF, ...);
    
    // Client-side
    ClientFactoryBuilder cfb = new ClientFactoryBuilder();
    cfb.channelOption(ChannelOption.SO_REUSEADDR, ...);
    cfb.channelOption(ChannelOption.SO_SNDBUF, ...);
    cfb.channelOption(ChannelOption.SO_RCVBUF, ...);
    ClientFactory cf = cfb.build();
    ClientBuilder cb = new ClientBuilder(...);
    cb.factory(cf);