public class RateLimiting
extends java.lang.Object
RateLimiter to process elements
at the desired rate.
For example, to limit each worker to 10 requests per second:
PCollection<T> data = ...;
data.apply(
RateLimiting.perWorker(new MyDoFn())
.withRateLimit(10)));
An uncaught exception from the wrapped DoFn will result in the exception
being rethrown in later calls to RateLimiting.RateLimitingDoFn.processElement(com.google.cloud.dataflow.sdk.transforms.DoFn<I, O>.ProcessContext)
or a call to RateLimiting.RateLimitingDoFn.finishBundle(com.google.cloud.dataflow.sdk.transforms.DoFn<I, O>.Context).
Rate limiting is provided as a PTransform
(RateLimiting.RateLimitingTransform), and also as a DoFn
(RateLimiting.RateLimitingDoFn).
| Modifier and Type | Class and Description |
|---|---|
static class |
RateLimiting.RateLimitingDoFn<I,O>
A rate-limiting
DoFn wrapper. |
static class |
RateLimiting.RateLimitingTransform<I,O>
A
PTransform which applies rate limiting to a DoFn. |
| Constructor and Description |
|---|
RateLimiting() |
| Modifier and Type | Method and Description |
|---|---|
static <I,O> RateLimiting.RateLimitingTransform<I,O> |
perWorker(DoFn<I,O> doFn)
Creates a new per-worker rate-limiting transform for the given
DoFn. |
public static <I,O> RateLimiting.RateLimitingTransform<I,O> perWorker(DoFn<I,O> doFn)
DoFn.
The default behavior is to process elements with multiple threads, but no rate limit is applied.
Use RateLimiting.RateLimitingTransform.withRateLimit(double) to limit the processing
rate, and RateLimiting.RateLimitingTransform.withMaxParallelism(int) to control the
maximum concurrent processing limit.
Aside from the above, the DoFn will be executed in the same manner
as in ParDo.
Rate limiting is applied independently per-worker.