java.lang.Object
org.elasticsearch.common.util.concurrent.EsExecutors

public class EsExecutors extends Object
A collection of static methods to help create different ES Executor types.
  • Field Details

    • NODE_PROCESSORS_SETTING

      public static final Setting<Processors> NODE_PROCESSORS_SETTING
      Setting to manually control the number of allocated processors. This setting is used to adjust thread pool sizes per node. The default value is Runtime.availableProcessors() but should be manually controlled if not all processors on the machine are available to Elasticsearch (e.g., because of CPU limits). Note that this setting accepts floating point processors. If a rounded number is needed, always use allocatedProcessors(Settings).
    • DIRECT_EXECUTOR_SERVICE

      public static final ExecutorService DIRECT_EXECUTOR_SERVICE
      ExecutorService that executes submitted tasks on the current thread. This executor service does not support being shutdown.
  • Method Details

    • allocatedProcessors

      public static int allocatedProcessors(Settings settings)
      Returns the number of allocated processors. Defaults to Runtime.availableProcessors() but can be overridden by passing a Settings instance with the key node.processors set to the desired value.
      Parameters:
      settings - a Settings instance from which to derive the allocated processors
      Returns:
      the number of allocated processors
    • nodeProcessors

      public static Processors nodeProcessors(Settings settings)
    • newSinglePrioritizing

      public static PrioritizedEsThreadPoolExecutor newSinglePrioritizing(String name, ThreadFactory threadFactory, ThreadContext contextHolder, ScheduledExecutorService timer)
    • newScaling

      public static EsThreadPoolExecutor newScaling(String name, int min, int max, long keepAliveTime, TimeUnit unit, boolean rejectAfterShutdown, ThreadFactory threadFactory, ThreadContext contextHolder, EsExecutors.TaskTrackingConfig config)
      Creates a scaling EsThreadPoolExecutor using an unbounded work queue.

      The EsThreadPoolExecutor scales the same way as a regular ThreadPoolExecutor until the core pool size (and at least 1) is reached: each time a task is submitted a new worker is added regardless if an idle worker is available.

      Once having reached the core pool size, a ThreadPoolExecutor will only add a new worker if the work queue rejects a task offer. Typically, using a regular unbounded queue, task offers won't ever be rejected, meaning the worker pool would never scale beyond the core pool size.

      Scaling EsThreadPoolExecutors use a customized unbounded LinkedTransferQueue, which rejects every task offer unless it can be immediately transferred to an available idle worker. If no such worker is available, the executor will add a new worker if capacity remains, otherwise the task is rejected and then appended to the work queue via the EsExecutors.ForceQueuePolicy rejection handler.

    • newScaling

      public static EsThreadPoolExecutor newScaling(String name, int min, int max, long keepAliveTime, TimeUnit unit, boolean rejectAfterShutdown, ThreadFactory threadFactory, ThreadContext contextHolder)
      Creates a scaling EsThreadPoolExecutor using an unbounded work queue.

      The EsThreadPoolExecutor scales the same way as a regular ThreadPoolExecutor until the core pool size (and at least 1) is reached: each time a task is submitted a new worker is added regardless if an idle worker is available.

      Once having reached the core pool size, a ThreadPoolExecutor will only add a new worker if the work queue rejects a task offer. Typically, using a regular unbounded queue, task offers won't ever be rejected, meaning the worker pool would never scale beyond the core pool size.

      Scaling EsThreadPoolExecutors use a customized unbounded LinkedTransferQueue, which rejects every task offer unless it can be immediately transferred to an available idle worker. If no such worker is available, the executor will add a new worker if capacity remains, otherwise the task is rejected and then appended to the work queue via the EsExecutors.ForceQueuePolicy rejection handler.

    • newFixed

      public static EsThreadPoolExecutor newFixed(String name, int size, int queueCapacity, ThreadFactory threadFactory, ThreadContext contextHolder, EsExecutors.TaskTrackingConfig config)
    • rethrowErrors

      public static Throwable rethrowErrors(Runnable runnable)
      Checks if the runnable arose from asynchronous submission of a task to an executor. If an uncaught exception was thrown during the execution of this task, we need to inspect this runnable and see if it is an error that should be propagated to the uncaught exception handler.
      Parameters:
      runnable - the runnable to inspect, should be a RunnableFuture
      Returns:
      non fatal exception or null if no exception.
    • threadName

      public static String threadName(Settings settings, String namePrefix)
    • threadName

      public static String threadName(String nodeName, String namePrefix)
    • executorName

      public static String executorName(String threadName)
    • executorName

      public static String executorName(Thread thread)
    • daemonThreadFactory

      public static ThreadFactory daemonThreadFactory(Settings settings, String namePrefix)
    • daemonThreadFactory

      public static ThreadFactory daemonThreadFactory(String nodeName, String namePrefix)
    • daemonThreadFactory

      public static ThreadFactory daemonThreadFactory(String nodeName, String namePrefix, boolean isSystemThread)
    • daemonThreadFactory

      public static ThreadFactory daemonThreadFactory(String name)