Skip to content

docs: add default threads count about NioEventLoopGroup #3221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,19 @@ instance needs to be shut down once it’s not used anymore.

The basic configuration options are listed in the table below:

| Name | Method | Default |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------|------------------------|
| **I/O Thread Pool Size** | `ioThreadPoolSize` | `Number of processors` |
| The number of threads in the I/O thread pools. The number defaults to the number of available processors that the runtime returns (which, as a well-known fact, sometimes does not represent the actual number of processors). Every thread represents an internal event loop where all I/O tasks are run. The number does not reflect the actual number of I/O threads because the client requires different thread pools for Network (NIO) and Unix Domain Socket (EPoll) connections. The minimum I/O threads are `3`. A pool with fewer threads can cause undefined behavior. | | |
| **Computation Thread Pool Size** | `comput ationThreadPoolSize` | `Number of processors` |
| The number of threads in the computation thread pool. The number defaults to the number of available processors that the runtime returns (which, as a well-known fact, sometimes does not represent the actual number of processors). Every thread represents an internal event loop where all computation tasks are run. The minimum computation threads are `3`. A pool with fewer threads can cause undefined behavior. | | |
| Name | Method | Default |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------|-------------|
| **I/O Thread Pool Size** | `ioThreadPoolSize` | `See below` |
| The number of threads in the I/O thread pools. Every thread represents an internal event loop where all I/O tasks are run. The number does not reflect the actual number of I/O threads because the client requires different thread pools for Network (NIO) and Unix Domain Socket (EPoll) connections. The minimum I/O threads are `2`. | | |
| **Computation Thread Pool Size** | `comput ationThreadPoolSize` | `See below` |
| The number of threads in the computation thread pool. Every thread represents an internal event loop where all computation tasks are run. The minimum computation threads are `2`. | | |

#### Default thread pool size

Unless configured otherwise by the settings above, the number of threads (for both computation and I/O) is determined in the following order:
* if there is an environment variable setting for `io.netty.eventLoopThreads` we use it as default setting
* otherwise we take the number of available processors, retrieved by `Runtime.getRuntime().availableProcessors()` _(which, as a well-known fact, sometimes does not represent the actual number of processors)_
* in any case if the chosen number is lower than the minimum, which is `2` threads, then we use the minimum.

### Advanced settings

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/io/lettuce/core/AbstractRedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,26 @@
import io.netty.channel.EventLoopGroup;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.EventExecutorGroup;
import io.netty.util.concurrent.Future;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

/**
* Base Redis client. This class holds the netty infrastructure, {@link ClientOptions} and the basic connection procedure. This
* class creates the netty {@link EventLoopGroup}s for NIO ({@link NioEventLoopGroup}) and EPoll (
* {@link io.netty.channel.epoll.EpollEventLoopGroup}) with a default of {@code Runtime.getRuntime().availableProcessors() * 4}
* threads. Reuse the instance as much as possible since the {@link EventLoopGroup} instances are expensive and can consume a
* huge part of your resources, if you create multiple instances.
* class creates different Netty {@link EventLoopGroup}s depending on the {@link NativeTransports} used.
* <p>
* You can set the number of threads per {@link NioEventLoopGroup} by setting the {@code io.netty.eventLoopThreads} system
* property to a reasonable number of threads.
* You can set the number of threads by using the {@link ClientResources} configuration. For more details, check the
* documentation of the {@link DefaultClientResources} class.
* </p>
*
* @author Mark Paluch
* @author Jongyeol Choi
* @author Poorva Gokhale
* @author Tihomir Mateev
* @since 3.0
* @see ClientResources
* @see DefaultClientResources
*/
public abstract class AbstractRedisClient implements AutoCloseable {

Expand Down