guava icon indicating copy to clipboard operation
guava copied to clipboard

Lock contention performance issues:com.google.common.util.concurrent.RateLimiter#acquire(int) -->reserve()#synchronized

Open yuyu414 opened this issue 2 years ago • 3 comments

image

I noticed RateLimiter recently and had a question in the ‘com.google.common.util.concurrent.RateLimiter#acquire(int)’ method。 What I want to ask is the performance issue of synchronized (mutex()) in reserve method. If there are 10,000 requests to synchronize (mutex()) to compete for locks, then the semantics of synchronized will cause these requests to block here, which may cause lock escalation and eventually become heavyweight locks. Why not use optimistic locking to deal with it?

yuyu414 avatar Oct 12 '22 05:10 yuyu414

image

com.google.common.util.concurrent.RateLimiter#tryAcquire(int, long, java.util.concurrent.TimeUnit) also has the same question. For example, my maximum acquisition timeout is 5 seconds, but because there are 10,000 lock competitions If the mutex() resource is obtained after 10 seconds, isn't the timeout of the tryAcquire method useless?

yuyu414 avatar Oct 12 '22 05:10 yuyu414

Hi @cgdecker , is any one working on this issue? if not i want to work on this, please let me know

akhilambati avatar Dec 27 '22 17:12 akhilambati

Hi @cgdecker , is any one working on this issue? if not i want to work on this, please let me know

Not yet @akhilambati

yuyu414 avatar Dec 28 '22 09:12 yuyu414