Class IoEnvironment

java.lang.Object
com.couchbase.client.core.env.IoEnvironment

public class IoEnvironment extends Object
The 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
  • Field Details

    • DEFAULT_NATIVE_IO_ENABLED

      public static final boolean DEFAULT_NATIVE_IO_ENABLED
      Native IO is enabled by default.
      See Also:
    • DEFAULT_EVENT_LOOP_THREAD_COUNT

      @Internal public static final int DEFAULT_EVENT_LOOP_THREAD_COUNT
  • Method Details

    • create

      @Deprecated public 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.
      Creates the IoEnvironment with default settings.
      Returns:
      the created environment.
    • builder

      @Deprecated public 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.
      Creates a Builder for the IoEnvironment to customize its settings.
      Returns:
      the IoEnvironment.Builder to customize the settings.
    • managerEventLoopGroup

      @Deprecated public 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().
      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 IoEnvironment class 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.Builder for chaining purposes.
    • kvEventLoopGroup

      @Deprecated public 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().
      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 IoEnvironment class 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.Builder for chaining purposes.
    • queryEventLoopGroup

      @Deprecated public 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().
      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 IoEnvironment class 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.Builder for chaining purposes.
    • analyticsEventLoopGroup

      @Deprecated public 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().
      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 IoEnvironment class 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.Builder for chaining purposes.
    • searchEventLoopGroup

      @Deprecated public 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().
      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 IoEnvironment class 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.Builder for chaining purposes.
    • viewEventLoopGroup

      @Deprecated public 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().
      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 IoEnvironment class 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.Builder for chaining purposes.
    • eventingEventLoopGroup

      @Deprecated public 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().
      Allows to specify a custom event loop group (I/O event loop thread pool) for the eventing 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 IoEnvironment class 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.Builder for chaining purposes.
    • backupEventLoopGroup

      @Deprecated @Volatile public 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().
      Allows to specify a custom event loop group (I/O event loop thread pool) for the backup 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 IoEnvironment class 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.Builder for chaining purposes.
    • eventLoopThreadCount

      @Deprecated public static IoEnvironment.Builder eventLoopThreadCount(int eventLoopThreadCount)
      Deprecated.
      This method creates a new builder. Please see the deprecation notice on builder().
      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.

      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.

      Parameters:
      eventLoopThreadCount - the number of event loops to use per pool.
      Returns:
      the IoEnvironment.Builder for chaining purposes.
    • enableNativeIo

      @Deprecated public static IoEnvironment.Builder enableNativeIo(boolean nativeIoEnabled)
      Deprecated.
      This method creates a new builder. Please see the deprecation notice on builder().
      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.Builder for chaining purposes.
    • managerEventLoopGroup

      public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> managerEventLoopGroup()
      Returns the EventLoopGroup to be used for config traffic.
      Returns:
      the selected event loop group.
    • kvEventLoopGroup

      public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> kvEventLoopGroup()
      Returns the EventLoopGroup to 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 the EventLoopGroup to 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 the EventLoopGroup to 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 the EventLoopGroup to 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 the EventLoopGroup to be used for view traffic.
      Returns:
      the selected event loop group.
    • eventingEventLoopGroup

      public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> eventingEventLoopGroup()
      Returns the EventLoopGroup to be used for eventing traffic.
      Returns:
      the selected event loop group.
    • backupEventLoopGroup

      @Volatile public Supplier<com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup> backupEventLoopGroup()
      Returns the EventLoopGroup to be used for backup 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.
    • eventLoopThreadCount

      public int eventLoopThreadCount()
      Returns the thread count per event loop.
    • shutdown

      public Mono<Void> shutdown(Duration timeout)
      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.