com.google.cloud.bigtable.grpc.async
Class ResourceLimiter
- java.lang.Object
-
- com.google.cloud.bigtable.grpc.async.ResourceLimiter
-
public class ResourceLimiter extends Object
This class limits access by RPCs to system resources- Version:
- $Id: $Id
- Author:
- sduskis
-
-
Constructor Summary
Constructors Constructor and Description ResourceLimiter(ResourceLimiterStats stats, long maxHeapSize, int maxInFlightRpcs)
Constructor for ResourceLimiter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description int
getAbsoluteMaxInFlightRpcs()
Getter for the fieldmaxInFlightRpcs
.int
getCurrentInFlightMaxRpcs()
Getter for the fieldcurrentInFlightMaxRpcs
.long
getHeapSize()
getHeapSize.long
getMaxHeapSize()
Getter for the fieldmaxHeapSize
.boolean
hasInflightRequests()
hasInflightRequests.boolean
isFull()
isFull.void
markCanBeCompleted(long id)
Mark an operation id, as returned byregisterOperationWithHeapSize
, as completelong
registerOperationWithHeapSize(long heapSize)
Register an operation with the given size before sending.void
setCurrentInFlightMaxRpcs(int currentInFlightMaxRpcs)
Setter for the fieldcurrentInFlightMaxRpcs
.void
throttle(int bulkMutationRpcTargetMs)
Enable an experimental feature that will throttle requests made fromBulkMutation
.
-
-
-
Constructor Detail
-
ResourceLimiter
public ResourceLimiter(ResourceLimiterStats stats, long maxHeapSize, int maxInFlightRpcs)
Constructor for ResourceLimiter.- Parameters:
maxHeapSize
- a long.maxInFlightRpcs
- a int.
-
-
Method Detail
-
registerOperationWithHeapSize
public long registerOperationWithHeapSize(long heapSize) throws InterruptedException
Register an operation with the given size before sending. This call WILL BLOCK until resources are available. This method must be paired with a call tomarkCanBeCompleted
in order to make sure resources are properly released.- Parameters:
heapSize
- The serialized size of the RPC to be sent- Returns:
- A unique operation id
- Throws:
InterruptedException
- if any.
-
markCanBeCompleted
public void markCanBeCompleted(long id)
Mark an operation id, as returned byregisterOperationWithHeapSize
, as complete- Parameters:
id
- a long.
-
getMaxHeapSize
public long getMaxHeapSize()
Getter for the fieldmaxHeapSize
.- Returns:
- The maximum allowed number of bytes across all across all outstanding RPCs
-
getAbsoluteMaxInFlightRpcs
public int getAbsoluteMaxInFlightRpcs()
Getter for the fieldmaxInFlightRpcs
.- Returns:
- The maximum allowed number of in-flight RPCs
-
getCurrentInFlightMaxRpcs
public int getCurrentInFlightMaxRpcs()
Getter for the fieldcurrentInFlightMaxRpcs
.- Returns:
- The current maximum number of allowed in-flight RPCs
-
setCurrentInFlightMaxRpcs
public void setCurrentInFlightMaxRpcs(int currentInFlightMaxRpcs)
Setter for the fieldcurrentInFlightMaxRpcs
.
-
getHeapSize
public long getHeapSize()
getHeapSize.- Returns:
- The total size of all currently outstanding RPCs
-
isFull
public boolean isFull()
isFull.- Returns:
- true if no more RPCs can be started, false otherwise
-
hasInflightRequests
public boolean hasInflightRequests()
hasInflightRequests.- Returns:
- true if there are currently in-flight RPCs
-
throttle
public void throttle(int bulkMutationRpcTargetMs)
Enable an experimental feature that will throttle requests made fromBulkMutation
. The logic is as follows:- To start:
- reduce parallelism to 25% -- The parallelism is high to begin with. This reduction should reduce the impacts of a bursty job, such as those found in Dataflow.
- every 20 seconds:
NOTE: increases are capped by the initial maximum. Decreases are floored at 1% of the original maximum so that there is some level of throughput.if (rpc_latency > threshold) { decrease parallelism by 10% of original maximum. } else if (rpc_latency < threshold && rpcsWereThrottled()) { increase parallelism by 5% of original maximum. }
- Parameters:
bulkMutationRpcTargetMs
- the target for latency of MutateRows requests in milliseconds.
- To start:
-
-