Package org.apache.zookeeper.server
Class RequestThrottler
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.zookeeper.server.ZooKeeperThread
-
- org.apache.zookeeper.server.ZooKeeperCriticalThread
-
- org.apache.zookeeper.server.RequestThrottler
-
- All Implemented Interfaces:
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 theglobalOutstandingLimit
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 theglobalOustandingLimit
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 separatemaxRequests
limit. If the total number of outstanding requests is higher thanmaxRequests
, the throttler will continually stall forstallTime
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
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description RequestThrottler(ZooKeeperServer zks)
-
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 org.apache.zookeeper.server.ZooKeeperCriticalThread
handleException
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
RequestThrottler
public RequestThrottler(ZooKeeperServer zks)
-
-
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)
-
throttleWake
public void throttleWake()
-
submitRequest
public void submitRequest(Request request)
-
getInflight
public int getInflight()
-
shutdown
public void shutdown()
-
-