You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, as far as I'm concerned it is well known that precise publish rate limiting does not function well. I believe my PR fixes problem number 3 stated in the issue above.
@danielsinai:
"3. Rate limit function passed only to the msg/s rate limiter (and that's in order to avoid calling it twice)"
It was passed to message rate limiter only due to the fact that there was no implementation of a way to throttle the connection whenever only **one of the limiters was exceeded**.
This PR will allow both message rate & byte rate to co-exist, limit and enable socket reading only when necessary.
- _tryAcquire_ function in **PublishRateLimiterDisable** will return true. If publish rate was null, this function would get called and return false, thus throttling the client for no reason. If the publish rate is null, it means it was not set by anyone so there's no reason to throttle any connection.
```java
public boolean tryAcquire(int numbers, long bytes) {
return true;
}
```
- **RateLimiter** _permits_ and _acquiredPermits_ were changed to volatile.
```java
private volatile long permits;
private volatile long acquiredPermits;
```
in order to allow reading access from multiple threads at the same time.
also the removal of _synchronized_ keyword from _getAvailablePermits()_ function.
```java
public long getAvailablePermits() {
return Math.max(0, this.permits - this.acquiredPermits);
}
```
**This is required, since a thread dead lock will happen if not.**
- Created ~a HashMap to manage the byte and message rate limiters, and~ a function _releaseThrottle()_ to handle the auto read enable.
If one of the rate limiters has no available permits we will not re-enable the auto read from the socket.
(cherry picked from commit 7f2ca8f)
(cherry picked from commit ab5fb72)
0 commit comments