Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronized consume method in AbstractCacheRateLimiter impact performance #96

Closed
addozhang opened this issue Jul 19, 2018 · 10 comments
Closed

Comments

@addozhang
Copy link

addozhang commented Jul 19, 2018

Currently we are using 1.7.2 which is similar with AbstractCacheRateLimiter in latest version. The repository we use is redis.

We did performance test. With 1.7.2, the TPS is 600+. After remove synchronized , it is up to 2000+.

In AbstractCacheRateLimiter, it has a synchronized method. In redis implementation, there is no object shared among threads. This method is invoked by each incoming request.

@lchayoun
Copy link
Collaborator

@addozhang
I think that the synchronized method is important otherwise we might miss consumptions.

@addozhang
Copy link
Author

But in RedisRateLimiter, both RateLimiterErrorHandler and RedisTemplate are thread-safe. It is not necessary to use synchronized.

@lchayoun
Copy link
Collaborator

Hi, @addozhang we recently changed the code in #108 and it should has better performance.
Can you test it?

@marcosbarbero
Copy link
Owner

Closing due inactivity

@FangXiaoMing2021
Copy link

@lchayoun Why you think remove synchronized method, it might miss consumptions.

@addozhang
Copy link
Author

@Fangfeikun Let me answer it. synchronized is usually used in race condition. ZuulFilter should be stateless object among requests. RateLimiter object used in RateLimitPreFilter should be stateless object too. Otherwise, all requests in this filter will wait for the monitor of RateLimiter.

@addozhang
Copy link
Author

@lchayoun Sorry for late reply.
I am confused. What is protected by synchronized? In RedisRateLimiter, both RateLimiterErrorHandler and RedisTemplate are thread-safe. There are no objects cannot be shared among threads.

@taxus1
Copy link

taxus1 commented Aug 1, 2019

@addozhang How do you solve this? remove synchronized key word has any problem?

@addozhang
Copy link
Author

@taxus1 yes, by removing synchronized and no any other problem found.

@taxus1
Copy link

taxus1 commented Aug 1, 2019

@addozhang thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants