public class RateLimitingSearcher extends Searcher
This takes these query parameter arguments:
Whenever quota is exceeded for an id this searcher will reject queries from that id by returning a result containing a status 429 error.
If rate.id or rate.quota is not set in Query.properties this searcher will do nothing.
Metrics: This will emit the count metric requestsOverQuota with the dimension [rate.idDimension=rate.id] counting rejected requests.
Ordering: This searcher Provides rateLimiting
Modifier and Type | Class and Description |
---|---|
private static class |
RateLimitingSearcher.AvailableCapacity
This keeps track of the current "capacity" (total cost) available to each client (rate id)
across all threads.
|
private static class |
RateLimitingSearcher.CapacityAllocation |
Modifier and Type | Field and Description |
---|---|
private ThreadLocal<Map<String,Double>> |
allocatedCapacity
Capacity already allocated to this thread
|
private RateLimitingSearcher.AvailableCapacity |
availableCapacity
Shared capacity across all threads.
|
private double |
capacityIncrement
How much capacity to allocate to a thread each time it runs out.
|
static com.yahoo.processing.request.CompoundName |
costKey |
static com.yahoo.processing.request.CompoundName |
dryRunKey |
static com.yahoo.processing.request.CompoundName |
idDimensionKey |
static com.yahoo.processing.request.CompoundName |
idKey |
private int |
nodeCount
Used to divide quota by nodes.
|
private com.yahoo.metrics.simple.Counter |
overQuotaCounter
For emitting metrics
|
static com.yahoo.processing.request.CompoundName |
quotaKey |
static String |
RATE_LIMITING
Constant containing the name this Provides - "rateLimiting", for ordering constraints
|
private double |
recheckForCapacityProbability
How often to check for new capacity if we have run out
|
private static String |
requestsOverQuotaMetricName |
Constructor and Description |
---|
RateLimitingSearcher(RateLimitingConfig rateLimitingConfig,
com.yahoo.cloud.config.ClusterInfoConfig clusterInfoConfig,
com.yahoo.metrics.simple.MetricReceiver metric) |
RateLimitingSearcher(RateLimitingConfig rateLimitingConfig,
com.yahoo.cloud.config.ClusterInfoConfig clusterInfoConfig,
com.yahoo.metrics.simple.MetricReceiver metric,
Clock clock)
For testing - allows injection of a timer to avoid depending on the system clock
|
Modifier and Type | Method and Description |
---|---|
private void |
addAllocatedCapacity(String id,
double newCapacity) |
private com.yahoo.metrics.simple.Point |
createContext(String dimensionName,
String dimensionValue) |
private double |
getAllocatedCapacity(String id) |
private void |
requestCapacity(String id,
double rate) |
Result |
search(Query query,
Execution execution)
Override this to implement your searcher.
|
ensureFilled, fill, getLogger, process, toString
getAnnotatedDependencies, getDefaultAnnotatedDependencies, getDependencies, initDependencies
public static final String RATE_LIMITING
public static final com.yahoo.processing.request.CompoundName idKey
public static final com.yahoo.processing.request.CompoundName costKey
public static final com.yahoo.processing.request.CompoundName quotaKey
public static final com.yahoo.processing.request.CompoundName idDimensionKey
public static final com.yahoo.processing.request.CompoundName dryRunKey
private static final String requestsOverQuotaMetricName
private final int nodeCount
private final RateLimitingSearcher.AvailableCapacity availableCapacity
private final ThreadLocal<Map<String,Double>> allocatedCapacity
private final com.yahoo.metrics.simple.Counter overQuotaCounter
private final double capacityIncrement
private final double recheckForCapacityProbability
@Inject public RateLimitingSearcher(RateLimitingConfig rateLimitingConfig, com.yahoo.cloud.config.ClusterInfoConfig clusterInfoConfig, com.yahoo.metrics.simple.MetricReceiver metric)
public RateLimitingSearcher(RateLimitingConfig rateLimitingConfig, com.yahoo.cloud.config.ClusterInfoConfig clusterInfoConfig, com.yahoo.metrics.simple.MetricReceiver metric, Clock clock)
public Result search(Query query, Execution execution)
Searcher
Searcher implementation subclasses will, depending on their type of logic, do one of the following:
Hits come in two kinds - concrete hits are actual content of the kind requested by the user, meta hits are hits which provides information about the collection of hits, on the query, the service and so on.
The query specifies a window into a larger result list that must be returned from the searcher through hits and offset; Searchers which returns list of hits in the top level in the result must return at least hits number of hits (or if impossible; all that are available), starting at the given offset. In addition, searchers are allowed to return any number of meta hits (although this number is expected to be low). For hits contained in nested hit groups, the concept of a window defined by hits and offset is not well defined and does not apply.
Error handling in searchers:
private com.yahoo.metrics.simple.Point createContext(String dimensionName, String dimensionValue)
private double getAllocatedCapacity(String id)
private void addAllocatedCapacity(String id, double newCapacity)
private void requestCapacity(String id, double rate)
Copyright © 2018. All rights reserved.