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

Remove expiringmap in favour of caffeine #112

Merged
merged 2 commits into from
Sep 23, 2020

Conversation

SimunKaracic
Copy link
Contributor

The expiringMap dependency has been replaced with caffeine https://github.com/ben-manes/caffeine.

This should fix #110.

I have a small reproduction example, based on https://github.com/akka/akka-samples/tree/2.6/akka-sample-distributed-workers-scala/src/main/scala/worker, and I've been unable to get this PR to deadlock in 2k startups of the app.

All tests pass, most Kamon tests pass (expect for kamon-annotation, which depend on expiringMap being inside the kanela jar, but I have that fixed locally and can open another PR if this goes through).

The only downside I see is that the agent jar file has grown in size from 5.4 MB to 6.4 MB.

Check it out and let me know what you think

@dpsoft
Copy link
Contributor

dpsoft commented Sep 22, 2020

Hi @SimunKaracic thanks for proposing this PR, I thinking that using this: https://github.com/raphw/weak-lock-free/blob/master/src/main/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMap.java + a ScheduledThreadPoolExecutor is enough WDYT?

[pseudocode]

import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap

private final WeakConcurrentMap<Object, TypePool.CacheProvider> cache =
        new WeakConcurrentMap<Object, TypePool.CacheProvider>(false);

Executors.newScheduledThreadPoolExecutor("cache-pool-cleaner") //deamon
            .scheduleWithFixedDelay(new Runnable() {
                @Override
                public void run() {
                    cache.expungeStaleEntries();
                }
            }, 1, 1, TimeUnit.MINUTES);

@SimunKaracic
Copy link
Contributor Author

SimunKaracic commented Sep 22, 2020

Sure I can try to put that in and run all the tests, should be simple enough.

The reason I used caffeine was because I wanted a popular, safe solution.
But I also wasn't sure of what exactly were the usage parameters for the ExpiringMap.

I'll put this in, rerun all the tests, and report back!

But on the final decision on this, I'll defer to your expertise

@SimunKaracic
Copy link
Contributor Author

Pushed the new version in, the deadlock tests are still running, but kamon tests pass.

A couple differences:

  1. Kamon-annotation will need an actual cache implementation (caffeine? :D), or some bigger code changes.
  2. There's no way to specify a loader, so I added a simple null check to the locate method that fills the map with data.
  3. The jar size did not go down :/

@dpsoft
Copy link
Contributor

dpsoft commented Sep 22, 2020

Awesome! I think in relation to the point 1 we have 2 options:

1 - Keep using ExpiringMap or
2 - Caffeine in favor to Expiring map

in both options we need shade the dependency in this manner:

https://github.com/kamon-io/Kamon/blob/master/build.sbt#L339-L342

agent/build.gradle Outdated Show resolved Hide resolved
@dpsoft dpsoft merged commit 9edc193 into kamon-io:master Sep 23, 2020
@dpsoft
Copy link
Contributor

dpsoft commented Sep 23, 2020

@SimunKaracic done!

@SimunKaracic
Copy link
Contributor Author

🎉
Thanks for the assist!

I'll go on kamon next, I'll keep the expiringmap and just add it as a shaded dependency!

@ivantopo
Copy link
Contributor

Please, don't keep expiring map! We already know it has a concurrency bug in there. We should not spread the chances of that bug biting us again.

@SimunKaracic SimunKaracic deleted the 110-remove-expiringmap branch September 23, 2020 12:37
@SimunKaracic
Copy link
Contributor Author

Good point!
WIll replace it with caffeine

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

Successfully merging this pull request may close these issues.

deadlock on jvm start
3 participants