Class RequestThrottler

  • All Implemented Interfaces:
    java.lang.Runnable

    public class RequestThrottler
    extends ZooKeeperCriticalThread
    When enabled, the RequestThrottler limits the number of outstanding requests currently submitted to the request processor pipeline. The throttler augments the limit imposed by the globalOutstandingLimit that is enforced by the connection layer (NIOServerCnxn, NettyServerCnxn). The connection layer limit applies backpressure against the TCP connection by disabling selection on connections once the request limit is reached. However, the connection layer always allows a connection to send at least one request before disabling selection on that connection. Thus, in a scenario with 40000 client connections, the total number of requests inflight may be as high as 40000 even if the globalOustandingLimit was set lower. The RequestThrottler addresses this issue by adding additional queueing. When enabled, client connections no longer submit requests directly to the request processor pipeline but instead to the RequestThrottler. The RequestThrottler is then responsible for issuing requests to the request processors, and enforces a separate maxRequests limit. If the total number of outstanding requests is higher than maxRequests, the throttler will continually stall for stallTime milliseconds until underlimit. The RequestThrottler can also optionally drop stale requests rather than submit them to the processor pipeline. A stale request is a request sent by a connection that is already closed, and/or a request whose latency will end up being higher than its associated session timeout. The notion of staleness is configurable, @see Request for more details. To ensure ordering guarantees, if a request is ever dropped from a connection that connection is closed and flagged as invalid. All subsequent requests inflight from that connection are then dropped as well.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean getDropStaleRequests()  
      int getInflight()  
      static int getMaxRequests()  
      static int getStallTime()  
      void run()  
      static void setDropStaleRequests​(boolean drop)  
      static void setMaxRequests​(int requests)  
      static void setStallTime​(int time)  
      protected boolean shouldThrottleOp​(Request request, long elapsedTime)  
      void shutdown()  
      void submitRequest​(Request request)  
      void throttleWake()  
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • shouldThrottleOp

        protected boolean shouldThrottleOp​(Request request,
                                           long elapsedTime)
      • getMaxRequests

        public static int getMaxRequests()
      • setMaxRequests

        public static void setMaxRequests​(int requests)
      • getStallTime

        public static int getStallTime()
      • setStallTime

        public static void setStallTime​(int time)
      • getDropStaleRequests

        public static boolean getDropStaleRequests()
      • setDropStaleRequests

        public static void setDropStaleRequests​(boolean drop)
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • throttleWake

        public void throttleWake()
      • submitRequest

        public void submitRequest​(Request request)
      • getInflight

        public int getInflight()
      • shutdown

        public void shutdown()