This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 32ea62f improve performance of checkPublishRate() (#8623)
32ea62f is described below
commit 32ea62fdb5385906bfba47a10afc6f9b8d6d9846
Author: WangJialing <[email protected]>
AuthorDate: Thu Nov 19 16:35:12 2020 +0800
improve performance of checkPublishRate() (#8623)
### Motivation
Currently `PublishRateLimiterImpl` is used for broker publisher throttling,
and checkPublishRate() is called in high frequency (default is 50ms every
time). Each time checkPublishRate() is called, `currentPublishByteCount.sum()`
and `currentPublishMsgCount.sum()` are executed. `LongAdder.sum()` will sum all
cells in the LongAdder object.
In case of only byte throttling (or msg count throttling) is enabled, only
do the necessary sum operation could improve the performace.
### Modifications
In case of only byte throttling (or msg count throttling) is enabled, only
do the necessary sum operation.
### Verifying this change
Already coverd by PublishRateLimiterTest()
---
.../pulsar/broker/service/PublishRateLimiterImpl.java | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PublishRateLimiterImpl.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PublishRateLimiterImpl.java
index 7e481ab..846b075 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PublishRateLimiterImpl.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PublishRateLimiterImpl.java
@@ -42,11 +42,19 @@ public class PublishRateLimiterImpl implements
PublishRateLimiter {
@Override
public void checkPublishRate() {
if (this.publishThrottlingEnabled && !publishRateExceeded) {
- long currentPublishMsgRate = this.currentPublishMsgCount.sum();
- long currentPublishByteRate = this.currentPublishByteCount.sum();
- if ((this.publishMaxMessageRate > 0 && currentPublishMsgRate >
this.publishMaxMessageRate)
- || (this.publishMaxByteRate > 0 && currentPublishByteRate
> this.publishMaxByteRate)) {
- publishRateExceeded = true;
+ if (this.publishMaxByteRate > 0) {
+ long currentPublishByteRate =
this.currentPublishByteCount.sum();
+ if (currentPublishByteRate > this.publishMaxByteRate) {
+ publishRateExceeded = true;
+ return;
+ }
+ }
+
+ if (this.publishMaxMessageRate > 0) {
+ long currentPublishMsgRate = this.currentPublishMsgCount.sum();
+ if (currentPublishMsgRate > this.publishMaxMessageRate) {
+ publishRateExceeded = true;
+ }
}
}
}