Decaton provides a way for you to control the processing rate.
Note that the processing rate is at partition level. Assume that there is a topic has 3 partitions and you limit the processing rate to 10 msgs/s, then you can expect that Decaton will process 30 msgs/s in total.
When you need to limit the number of tasks that can be processed in a second.
Typically most of the services need to protect themselves from excessive use to improve service availability. The most common way is to utilize rate limiting. Suppose you are developing a Decaton processor that will access the underlying database. You may apply rate limiting to protect the database from a large number of requests in a short period. By setting the rate limiting, Decaton will pause for a while for you to prevent from such sudden traffic.
You can use CONFIG_PROCESSING_RATE
to set rate limit.
Before getting started with the example, you need to know that the behavior of rate limiting will be different depends on the value you set.
The value can have three different meanings:
Value | Description |
---|---|
0 |
Stop all processing but the task currently being processed isn’t interrupted |
-1 (default) |
Unlimited |
Any positive number |
Do the best to process tasks with the given value per second. Note that the actual processing rate may not reach the given value if a task takes over a second to process or the value is greater than actual throughput per second. |
Just like other properties, you can set it through SubscriptionBuilder#properties
, as shown in the following example:
...
SubscriptionBuilder.newBuilder("rate-limit-processor")
.properties(
StaticPropertySupplier.of( // (1)
Property.ofStatic(CONFIG_PROCESSING_RATE, 100L)))
...
-
In this example we use
StaticPropertySupplier
to set static processing rate. Note that the property can also be set with Dynamic property configuration.
The rate limiter used in Decaton is implemented based on a kind of token bucket algorithm which has the following features:
-
When the processing rate reaches configured rate limit, rate limiter will slow down the processing rather than discarding tasks.
-
Decaton’s rate limiter allows sudden increase in traffic.