public class IoEnvironment extends Object
IoEnvironment
holds the I/O event loops and state.
Note that this class only contains tunables and state for the I/O event loops that drive the actual operations
inside netty. If you are looking for general configuration if I/O properties, those are located inside the
IoConfig
class instead.
By default the IO environment creates 3 distinct EventLoopGroups
. One for HTTP services
(which includes query, search, analytics and views), one for the KV service and one for the management service. The
HTTP and the KV service try to occupy a "fair" number of thread pools for each. Usually it will be half the number
of reported logical CPUs by the JVM, but maximum of 8 and minimum of 2 each. The management service will only ever
occupy one thread. The HTTP and KV thread pools are split in SDK 3 (they were not in SDK 2) so that longer running
N1QL queries and larger streaming results do not interfere with high-throughput low-latency KV workloads as much.
By default, the SDK will use "native" event loop groups - epoll on linux and kqueue on OSX in favor of the more
generic and slower NIO transport. This should work fine out of the box nearly always, but you can disable it through
the enableNativeIo(boolean)
builder setting.
You cannot re-use your own event loop groups from your own application because the SDK ships a repackaged netty version to avoid version and classpath issues.
Modifier and Type | Class and Description |
---|---|
static class |
IoEnvironment.Builder |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_EVENT_LOOP_THREAD_COUNT |
static boolean |
DEFAULT_NATIVE_IO_ENABLED
Native IO is enabled by default.
|
Modifier and Type | Method and Description |
---|---|
Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> |
analyticsEventLoopGroup()
Returns the
EventLoopGroup to be used for analytics traffic. |
static IoEnvironment.Builder |
analyticsEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> |
backupEventLoopGroup()
Returns the
EventLoopGroup to be used for backup traffic. |
static IoEnvironment.Builder |
backupEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
static IoEnvironment.Builder |
builder()
Deprecated.
Instead of creating a new builder, please use
CoreEnvironment.Builder.ioEnvironment(Consumer)
and configure the builder passed to the consumer.
Note: CoreEnvironment is a base class; you'll
probably call that method via a subclass named
ClusterEnvironment . |
static IoEnvironment |
create()
Deprecated.
Instead, please use
CoreEnvironment.Builder.ioEnvironment(Consumer)
and configure the builder passed to the consumer.
Note: CoreEnvironment is a base class; you'll
probably call that method via a subclass named
ClusterEnvironment . |
static IoEnvironment.Builder |
enableNativeIo(boolean nativeIoEnabled)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> |
eventingEventLoopGroup()
Returns the
EventLoopGroup to be used for eventing traffic. |
static IoEnvironment.Builder |
eventingEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
int |
eventLoopThreadCount()
Returns the thread count per event loop.
|
static IoEnvironment.Builder |
eventLoopThreadCount(int eventLoopThreadCount)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> |
kvEventLoopGroup()
Returns the
EventLoopGroup to be used for Key/Value traffic. |
static IoEnvironment.Builder |
kvEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> |
managerEventLoopGroup()
Returns the
EventLoopGroup to be used for config traffic. |
static IoEnvironment.Builder |
managerEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
boolean |
nativeIoEnabled()
Returns true if native IO is enabled and can be used if supported.
|
Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> |
queryEventLoopGroup()
Returns the
EventLoopGroup to be used for N1QL Query traffic. |
static IoEnvironment.Builder |
queryEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> |
searchEventLoopGroup()
Returns the
EventLoopGroup to be used for search traffic. |
static IoEnvironment.Builder |
searchEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
Mono<Void> |
shutdown(Duration timeout)
Instructs all the owned event loops to shut down.
|
Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> |
viewEventLoopGroup()
Returns the
EventLoopGroup to be used for view traffic. |
static IoEnvironment.Builder |
viewEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
Deprecated.
This method creates a new builder. Please see the deprecation notice on
builder() . |
public static final boolean DEFAULT_NATIVE_IO_ENABLED
@Stability.Internal public static final int DEFAULT_EVENT_LOOP_THREAD_COUNT
@Deprecated public static IoEnvironment create()
CoreEnvironment.Builder.ioEnvironment(Consumer)
and configure the builder passed to the consumer.
Note: CoreEnvironment is a base class; you'll
probably call that method via a subclass named
ClusterEnvironment
.IoEnvironment
with default settings.@Deprecated public static IoEnvironment.Builder builder()
CoreEnvironment.Builder.ioEnvironment(Consumer)
and configure the builder passed to the consumer.
Note: CoreEnvironment is a base class; you'll
probably call that method via a subclass named
ClusterEnvironment
.IoEnvironment
to customize its settings.IoEnvironment.Builder
to customize the settings.@Deprecated public static IoEnvironment.Builder managerEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
builder()
.Note that you usually do not need to tweak the event loop for the manager service, only if you perform long-running management queries that interfere with regular traffic.
Note: tweaking the dedicated event loops should be done with care and only after profiling
indicated that the default event loop setup is not achieving the desired performance characteristics. Please
see the javadoc for the IoEnvironment
class for an explanation how the event loops play together for
all the services and what effect a custom pool might have.
eventLoopGroup
- the dedicated event loop group to use.IoEnvironment.Builder
for chaining purposes.@Deprecated public static IoEnvironment.Builder kvEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
builder()
.
Note: tweaking the dedicated event loops should be done with care and only after profiling
indicated that the default event loop setup is not achieving the desired performance characteristics. Please
see the javadoc for the IoEnvironment
class for an explanation how the event loops play together for
all the services and what effect a custom pool might have.
eventLoopGroup
- the dedicated event loop group to use.IoEnvironment.Builder
for chaining purposes.@Deprecated public static IoEnvironment.Builder queryEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
builder()
.
Note: tweaking the dedicated event loops should be done with care and only after profiling
indicated that the default event loop setup is not achieving the desired performance characteristics. Please
see the javadoc for the IoEnvironment
class for an explanation how the event loops play together for
all the services and what effect a custom pool might have.
eventLoopGroup
- the dedicated event loop group to use.IoEnvironment.Builder
for chaining purposes.@Deprecated public static IoEnvironment.Builder analyticsEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
builder()
.
Note: tweaking the dedicated event loops should be done with care and only after profiling
indicated that the default event loop setup is not achieving the desired performance characteristics. Please
see the javadoc for the IoEnvironment
class for an explanation how the event loops play together for
all the services and what effect a custom pool might have.
eventLoopGroup
- the dedicated event loop group to use.IoEnvironment.Builder
for chaining purposes.@Deprecated public static IoEnvironment.Builder searchEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
builder()
.
Note: tweaking the dedicated event loops should be done with care and only after profiling
indicated that the default event loop setup is not achieving the desired performance characteristics. Please
see the javadoc for the IoEnvironment
class for an explanation how the event loops play together for
all the services and what effect a custom pool might have.
eventLoopGroup
- the dedicated event loop group to use.IoEnvironment.Builder
for chaining purposes.@Deprecated public static IoEnvironment.Builder viewEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
builder()
.
Note: tweaking the dedicated event loops should be done with care and only after profiling
indicated that the default event loop setup is not achieving the desired performance characteristics. Please
see the javadoc for the IoEnvironment
class for an explanation how the event loops play together for
all the services and what effect a custom pool might have.
eventLoopGroup
- the dedicated event loop group to use.IoEnvironment.Builder
for chaining purposes.@Deprecated public static IoEnvironment.Builder eventingEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
builder()
.
Note: tweaking the dedicated event loops should be done with care and only after profiling
indicated that the default event loop setup is not achieving the desired performance characteristics. Please
see the javadoc for the IoEnvironment
class for an explanation how the event loops play together for
all the services and what effect a custom pool might have.
eventLoopGroup
- the dedicated event loop group to use.IoEnvironment.Builder
for chaining purposes.@Deprecated @Stability.Volatile public static IoEnvironment.Builder backupEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)
builder()
.
Note: tweaking the dedicated event loops should be done with care and only after profiling
indicated that the default event loop setup is not achieving the desired performance characteristics. Please
see the javadoc for the IoEnvironment
class for an explanation how the event loops play together for
all the services and what effect a custom pool might have.
eventLoopGroup
- the dedicated event loop group to use.IoEnvironment.Builder
for chaining purposes.@Deprecated public static IoEnvironment.Builder eventLoopThreadCount(int eventLoopThreadCount)
builder()
.
If not manually overridden, a fair thread count is calculated, see fairThreadCount()
for more
information on the heuristics.
It is important to understand that the event loops are asynchronous and non-blocking by nature, which means they can multiplex hundreds, if not thousands of connections. It is therefore not necessary (and in some cases even destructive to performance) to ramp up the number of threads to a high count (i.e. 100+). The value should only really be tuned higher if profiling indicates that the current pool size is exhausted with busy work (a RUNNABLE thread state alone is not indicative of this, since it might just be waiting on epoll/kqueue to be woken up). If in doubt, stick with the defaults.
Note that the count provided will only be used by event loops that the SDK creates. If you configure a custom
event loop (i.e. through kvEventLoopGroup(EventLoopGroup)
) you are responsible for sizing it
appropriately on your own.
eventLoopThreadCount
- the number of event loops to use per pool.IoEnvironment.Builder
for chaining purposes.@Deprecated public static IoEnvironment.Builder enableNativeIo(boolean nativeIoEnabled)
builder()
.Usually the native transports used (epoll on linux and kqueue on OSX) are going to be faster and more efficient than the generic NIO one. We recommend to only set this to false if you experience issues with the native transports or instructed by couchbase support to do so for troubleshooting reasons.
nativeIoEnabled
- if native IO should be enabled or disabled.IoEnvironment.Builder
for chaining purposes.public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> managerEventLoopGroup()
EventLoopGroup
to be used for config traffic.public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> kvEventLoopGroup()
EventLoopGroup
to be used for Key/Value traffic.public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> queryEventLoopGroup()
EventLoopGroup
to be used for N1QL Query traffic.public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> analyticsEventLoopGroup()
EventLoopGroup
to be used for analytics traffic.public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> searchEventLoopGroup()
EventLoopGroup
to be used for search traffic.public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> viewEventLoopGroup()
EventLoopGroup
to be used for view traffic.public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> eventingEventLoopGroup()
EventLoopGroup
to be used for eventing traffic.@Stability.Volatile public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> backupEventLoopGroup()
EventLoopGroup
to be used for backup traffic.public boolean nativeIoEnabled()
public int eventLoopThreadCount()
Copyright © 2024 Couchbase, Inc.. All rights reserved.