guyinyou commented on PR #4601:
URL: https://github.com/apache/rocketmq/pull/4601#issuecomment-1184206529
When I benchmarked rocketmq before, there was a need for back pressure. My
approach was to maintain a semaphore to control the concurrent number of
asynchronous sending, which achieved a very ideal effect. You can try it.
```
UniformRateLimiter rateLimiter = new UniformRateLimiter(1024);
AtomicLong windowsCnt = new AtomicLong(0);
while(true) {
try {
if(Producer.windowsCnt.incrementAndGet() >= windowsSize){
while (Producer.windowsCnt.get() >= windowsSize) {
Thread.yield();
}
}
producer.send(new Message(xxxxxxx), new SendCallback() {
@Override public void onSuccess(SendResult sendResult) {
windowsCnt.decrementAndGet();
}
@Override public void onException(Throwable e) {
windowsCnt.decrementAndGet();
throw new RuntimeException(e);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
```
Of course, this implementation is very rough. In actual scenarios, this
rateLimiter should be a dynamic value, which may be increased or decreased
according to the number of failed messages sent recently, the delay in sending,
etc. If you are interested, you can communicate and discuss together.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]