-
Notifications
You must be signed in to change notification settings - Fork 985
Configuring Client resources
Client resources are configuration settings for the client related to performance, concurrency, and events. A vast part of Client resources consists of thread pools (EventLoopGroup
s and a EventExecutorGroup
) which build the infrastructure for the connection workers. In general, it is a good idea to reuse instances of ClientResources
across multiple clients.
Client resources are stateful and need to be shut down if they are supplied from outside the client.
Client resources are required to be immutable. You can create instances using two different patterns:
The create()
factory method
By using the create()
method on DefaultClientResources
you create ClientResources
with default settings:
ClientResources res = DefaultClientResources.create();
This approach fits the most needs.
Resources builder
You can build instances of DefaultClientResources
by using the embedded builder. It is designed to configure the resources to your needs. The builder accepts the configuration in a fluent fashion and then creates the ClientResources at the end:
ClientResources res = DefaultClientResources.builder()
.ioThreadPoolSize(4)
.computationThreadPoolSize(4)
.build()
A RedisClient
and RedisClusterClient
can be created without passing ClientResources
upon creation. The resources are exclusive to the client and are managed itself by the client. When calling shutdown()
of the client instance ClientResources
are shut down.
RedisClient client = RedisClient.create();
...
client.shutdown();
If you require multiple instances of a client or you want to provide existing thread infrastructure, you can configure a shared ClientResources
instance using the builder. The shared Client resources can be passed upon client creation:
ClientResources res = DefaultClientResources.create();
RedisClient client = RedisClient.create(res);
RedisClusterClient clusterClient = RedisClusterClient.create(res, seedUris);
...
client.shutdown();
clusterClient.shutdown();
res.shutdown();
Shared ClientResources
are never shut down by the client. Same applies for shared EventLoopGroupProvider
s that are an abstraction to provide EventLoopGroup
s.
Netty requires different EventLoopGroup
s for NIO (TCP) and for EPoll (Unix Domain Socket) connections.
One additional EventExecutorGroup
is used to perform computation tasks. EventLoopGroup
s are started
lazily to allocate Threads on-demand.
Every client instance requires a call to shutdown()
to clear used resources. Clients with dedicated ClientResources
(i.e. no ClientResources
passed within the constructor/create
-method) will shut down ClientResources
on their own.
Client instances with using shared ClientResources
(i.e. ClientResources
passed using the constructor/create
-method)
won’t shut down the ClientResources
on their own. The ClientResources
instance needs to be shut down once its not used anymore.
The basic configuration options are listed in the table below:
Name | Method | Default |
---|---|---|
I/O Thread Pool Size |
|
|
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 |
||
Computation Thread Pool Size |
|
|
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 |
Values for the advanced options are listed in the table below and should not be changed unless there is a truly good reason to do so.
Name | Method | Default |
---|---|---|
Provider for EventLoopGroup |
|
|
For those who want to reuse existing netty infrastructure or the total control over the thread pools, the |
||
Provided EventExecutorGroup |
|
|
For those who want to reuse existing netty infrastructure or the total control over the thread pools can provide an existing |
||
Event bus |
|
|
The event bus system is used to transport events from the client to subscribers. Events are about connection state changes, metrics, and more. Events are published using a RxJava subject and the default implementation drops events on backpressure. Learn more about the link:Reactive API (5.0)[Reactive API]. You can also publish your own events. If you wish to do so, make sure that your events implement the |
||
Command latency collector options |
|
|
The client can collect latency metrics during while dispatching commands. The options allow configuring the percentiles, level of metrics (per connection or server) and whether the metrics are cumulative or reset after obtaining these. Command latency collection is enabled by default and can be disabled by setting |
||
Command latency collector |
|
|
The client can collect latency metrics during while dispatching commands. Command latency metrics is collected on connection or server level. Command latency collection is enabled by default and can be disabled by setting |
||
Latency event publisher options |
|
|
Command latencies can be published using the event bus. Latency events are emitted by default every 10 minutes. Event publishing can be disabled by setting |
||
DNS Resolver |
|
|
Since: 3.5, 4.2 Configures a DNS resolver to resolve hostnames to a Since 4.4: Defaults to |
||
Reconnect Delay |
|
|
Since: 4.2 Configures a reconnect delay used to delay reconnect attempts. Defaults to binary exponential delay with an upper boundary of |
||
Netty Customizer |
|
|
Since: 4.4 Configures a netty customizer to enhance netty components. Allows customization of |
Lettuce documentation was moved to https://redis.github.io/lettuce/overview/
Intro
Getting started
- Getting started
- Redis URI and connection details
- Basic usage
- Asynchronous API
- Reactive API
- Publish/Subscribe
- Transactions/Multi
- Scripting and Functions
- Redis Command Interfaces
- FAQ
HA and Sharding
Advanced usage
- Configuring Client resources
- Client Options
- Dynamic Command Interfaces
- SSL Connections
- Native Transports
- Unix Domain Sockets
- Streaming API
- Events
- Command Latency Metrics
- Tracing
- Stateful Connections
- Pipelining/Flushing
- Connection Pooling
- Graal Native Image
- Custom commands
Integration and Extension
Internals