Class TaskExecutionTimeTrackingEsThreadPoolExecutor

All Implemented Interfaces:
AutoCloseable, Executor, ExecutorService

public final class TaskExecutionTimeTrackingEsThreadPoolExecutor extends EsThreadPoolExecutor
An extension to thread pool executor, which tracks statistics for the task execution time.
  • Field Details

    • QUEUE_LATENCY_HISTOGRAM_BUCKETS

      public static final int QUEUE_LATENCY_HISTOGRAM_BUCKETS
      See Also:
  • Method Details

    • setupMetrics

      public List<Instrument> setupMetrics(MeterRegistry meterRegistry, String threadPoolName)
    • wrapRunnable

      protected Runnable wrapRunnable(Runnable command)
      Overrides:
      wrapRunnable in class EsThreadPoolExecutor
    • unwrap

      protected Runnable unwrap(Runnable runnable)
      Overrides:
      unwrap in class EsThreadPoolExecutor
    • getTaskExecutionEWMA

      public double getTaskExecutionEWMA()
      Returns the exponentially weighted moving average of the task execution time
    • getTotalTaskExecutionTime

      public long getTotalTaskExecutionTime()
      Returns the total time (in nanoseconds) spend executing tasks in this executor.
    • getCurrentQueueSize

      public int getCurrentQueueSize()
      Returns the current queue size (operations that are queued)
    • getMaxQueueLatencyMillisSinceLastPollAndReset

      public long getMaxQueueLatencyMillisSinceLastPollAndReset()
      Returns the max queue latency seen since the last time that this method was called. Every call will reset the max seen back to zero. Latencies are only observed as tasks are taken off of the queue. This means that tasks in the queue will not contribute to the max latency until they are unqueued and handed to a thread to execute. To see the latency of tasks still in the queue, use peekMaxQueueLatencyInQueueMillis(). If there have been no tasks in the queue since the last call, then zero latency is returned.
    • peekMaxQueueLatencyInQueueMillis

      public long peekMaxQueueLatencyInQueueMillis()
      Returns the queue latency of the next task to be executed that is still in the task queue. Essentially peeks at the front of the queue and calculates how long it has been there. Returns zero if there is no queue.
    • pollUtilization

      public double pollUtilization(TaskExecutionTimeTrackingEsThreadPoolExecutor.UtilizationTrackingPurpose utilizationTrackingPurpose)
      Returns the fraction of the maximum possible thread time that was actually used since the last time this method was called. There are two periodic pulling mechanisms that access utilization reporting: TaskExecutionTimeTrackingEsThreadPoolExecutor.UtilizationTrackingPurpose distinguishes the caller.
      Returns:
      the utilization as a fraction, in the range [0, 1]. This may return >1 if a task completed in the time range but started earlier, contributing a larger execution time.
    • beforeExecute

      protected void beforeExecute(Thread t, Runnable r)
      Overrides:
      beforeExecute in class ThreadPoolExecutor
    • afterExecute

      protected void afterExecute(Runnable r, Throwable t)
      Overrides:
      afterExecute in class EsThreadPoolExecutor
    • appendThreadPoolExecutorDetails

      protected void appendThreadPoolExecutorDetails(StringBuilder sb)
      Description copied from class: EsThreadPoolExecutor
      Append details about this thread pool to the specified StringBuilder. All details should be appended as key/value pairs in the form "%s = %s, "
      Overrides:
      appendThreadPoolExecutorDetails in class EsThreadPoolExecutor
      Parameters:
      sb - the StringBuilder to append to
    • getOngoingTasks

      public Map<Runnable,Long> getOngoingTasks()
      Returns the set of currently running tasks and their start timestamp.

      Note that it is possible for a task that has just finished execution to be temporarily both in the returned map, and its total execution time to be included in the return value of getTotalTaskExecutionTime(). However, it is guaranteed that the task is reflected in at least one of those two values.

    • getExecutionEwmaAlpha

      public double getExecutionEwmaAlpha()
    • trackingMaxQueueLatency

      public boolean trackingMaxQueueLatency()