caffeine: putIfAbsent() regression?

We recently upgraded from 2.7.0 to 2.8.8 and noticed that our putIfAbsent code-paths are contending more heavily than before (at least that’s our observation):

   java.lang.Thread.State: BLOCKED (on object monitor)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache.put(BoundedLocalCache.java:2030)
	- waiting to lock <0x00007f00ba087828> (a com.github.benmanes.caffeine.cache.PSWMS)
	at com.github.benmanes.caffeine.cache.BoundedLocalCache.putIfAbsent(BoundedLocalCache.java:1965)

We are aware of the commit https://github.com/ben-manes/caffeine/commit/614fe6053e343481c15c55f1d696517d73baae0d that should have improved putIfAbsent but we are somehow seeing the opposite. This is a bounded (1M) synchronous cache with a 1-day expiration.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 43 (22 by maintainers)

Commits related to this issue

Most upvoted comments

great!

By the way, your benchmark has a shared Random used by threaded tests. This uses a lock internally, so that will cause synchronous access. You can use ThreadLocalRandom or create unique data sets by thread scoping (usage example). It may be that the perf difference is noise since JIT’ing, background tasks, etc. can cause skew. I look for large differences and do not put much weight on small changes.

I pushed the patch to v2.dev. I think it will be hard to test or benchmark, but a nice catch. I didn’t see anything cleaner than copying the 10 lines of code.

This is available on jitpack (via commit hash) or Sonatype’s snapshot repository (as 2.9.1-SNAPSHOT).

yeah, that does seem to have been overlooked. I think you’re right that the optimization could be added there too.