Class IoEnvironment
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.
- Since:
- 2.0.0
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIoEnvironment.Builder -
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_NATIVE_IO_ENABLEDNative IO is enabled by default. -
Method Summary
Modifier and Type Method Description Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup>analyticsEventLoopGroup()Returns theEventLoopGroupto be used for analytics traffic.static IoEnvironment.BuilderanalyticsEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the analytics service.static IoEnvironment.Builderbuilder()Creates a Builder for theIoEnvironmentto customize its settings.static IoEnvironmentcreate()Creates theIoEnvironmentwith default settings.static IoEnvironment.BuilderenableNativeIo(boolean nativeIoEnabled)If set to false (enabled by default) will force using the java NIO based IO transport.static IoEnvironment.BuildereventLoopThreadCount(int eventLoopThreadCount)Overrides the number of threads used per event loop.Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup>kvEventLoopGroup()Returns theEventLoopGroupto be used for Key/Value traffic.static IoEnvironment.BuilderkvEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the management service.Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup>managerEventLoopGroup()Returns theEventLoopGroupto be used for config traffic.static IoEnvironment.BuildermanagerEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the management service.booleannativeIoEnabled()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 theEventLoopGroupto be used for N1QL Query traffic.static IoEnvironment.BuilderqueryEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the query service.Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup>searchEventLoopGroup()Returns theEventLoopGroupto be used for search traffic.static IoEnvironment.BuildersearchEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the search service.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 theEventLoopGroupto be used for view traffic.static IoEnvironment.BuilderviewEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the view service.
-
Field Details
-
DEFAULT_NATIVE_IO_ENABLED
public static final boolean DEFAULT_NATIVE_IO_ENABLEDNative IO is enabled by default.- See Also:
- Constant Field Values
-
-
Method Details
-
create
Creates theIoEnvironmentwith default settings.- Returns:
- the created environment.
-
builder
Creates a Builder for theIoEnvironmentto customize its settings.- Returns:
- the
IoEnvironment.Builderto customize the settings.
-
managerEventLoopGroup
public static IoEnvironment.Builder managerEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the management service.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
IoEnvironmentclass for an explanation how the event loops play together for all the services and what effect a custom pool might have.- Parameters:
eventLoopGroup- the dedicated event loop group to use.- Returns:
- this
IoEnvironment.Builderfor chaining purposes.
-
kvEventLoopGroup
public static IoEnvironment.Builder kvEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the management service.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
IoEnvironmentclass for an explanation how the event loops play together for all the services and what effect a custom pool might have.- Parameters:
eventLoopGroup- the dedicated event loop group to use.- Returns:
- this
IoEnvironment.Builderfor chaining purposes.
-
queryEventLoopGroup
public static IoEnvironment.Builder queryEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the query service.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
IoEnvironmentclass for an explanation how the event loops play together for all the services and what effect a custom pool might have.- Parameters:
eventLoopGroup- the dedicated event loop group to use.- Returns:
- this
IoEnvironment.Builderfor chaining purposes.
-
analyticsEventLoopGroup
public static IoEnvironment.Builder analyticsEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the analytics service.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
IoEnvironmentclass for an explanation how the event loops play together for all the services and what effect a custom pool might have.- Parameters:
eventLoopGroup- the dedicated event loop group to use.- Returns:
- this
IoEnvironment.Builderfor chaining purposes.
-
searchEventLoopGroup
public static IoEnvironment.Builder searchEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the search service.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
IoEnvironmentclass for an explanation how the event loops play together for all the services and what effect a custom pool might have.- Parameters:
eventLoopGroup- the dedicated event loop group to use.- Returns:
- this
IoEnvironment.Builderfor chaining purposes.
-
viewEventLoopGroup
public static IoEnvironment.Builder viewEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup eventLoopGroup)Allows to specify a custom event loop group (I/O event loop thread pool) for the view service.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
IoEnvironmentclass for an explanation how the event loops play together for all the services and what effect a custom pool might have.- Parameters:
eventLoopGroup- the dedicated event loop group to use.- Returns:
- this
IoEnvironment.Builderfor chaining purposes.
-
eventLoopThreadCount
Overrides the number of threads used per event loop.If not manually overridden, a fair thread count is calculated, see
fairThreadCount()for more information on the heuristics.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.- Parameters:
eventLoopThreadCount- the number of event loops to use per pool.- Returns:
- the
IoEnvironment.Builderfor chaining purposes.
-
enableNativeIo
If set to false (enabled by default) will force using the java NIO based IO transport.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.
- Parameters:
nativeIoEnabled- if native IO should be enabled or disabled.- Returns:
- this
IoEnvironment.Builderfor chaining purposes.
-
managerEventLoopGroup
public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> managerEventLoopGroup()Returns theEventLoopGroupto be used for config traffic.- Returns:
- the selected event loop group.
-
kvEventLoopGroup
Returns theEventLoopGroupto be used for Key/Value traffic.- Returns:
- the selected event loop group.
-
queryEventLoopGroup
public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> queryEventLoopGroup()Returns theEventLoopGroupto be used for N1QL Query traffic.- Returns:
- the selected event loop group.
-
analyticsEventLoopGroup
public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> analyticsEventLoopGroup()Returns theEventLoopGroupto be used for analytics traffic.- Returns:
- the selected event loop group.
-
searchEventLoopGroup
public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> searchEventLoopGroup()Returns theEventLoopGroupto be used for search traffic.- Returns:
- the selected event loop group.
-
viewEventLoopGroup
public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> viewEventLoopGroup()Returns theEventLoopGroupto be used for view traffic.- Returns:
- the selected event loop group.
-
nativeIoEnabled
public boolean nativeIoEnabled()Returns true if native IO is enabled and can be used if supported.- Returns:
- true if enabled.
-
shutdown
Instructs all the owned event loops to shut down.- Parameters:
timeout- the maximum amount of time to wait before returning back control.- Returns:
- a mono that completes once finished.
-