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

Locking contention on com.cognitect.transit.impl.Cache #38

Open
wilkerlucio opened this issue Jul 1, 2024 · 0 comments
Open

Locking contention on com.cognitect.transit.impl.Cache #38

wilkerlucio opened this issue Jul 1, 2024 · 0 comments

Comments

@wilkerlucio
Copy link

Hello,

During a performance tuning task, we notice a high locking time on com.cognitect.transit.impl.Cache during service startup.

cleanshot_2024-06-26_at_09 56 52_2x

I tracked it down to this code snippet:

synchronized (handlerCache) {
writeHandlerMap = handlerCache.get(customHandlers);
if (writeHandlerMap == null) {
writeHandlerMap = new WriteHandlerMap(customHandlers);
handlerCache.put(customHandlers, writeHandlerMap);
}
}

Without changing the library itself, I wrapped our write handlers here with a WriteHandlerMap class to avoid that block, getting into this code path instead:

if (customHandlers instanceof WriteHandlerMap)
return new WriteHandlerMap(customHandlers);

Doing so significantly improved our locking times; in comparable scenarios, it dropped from 53 minutes of locking time on com.cognitect.transit.impl.Cache to 1 minute and 30 seconds.

I think if we can improve this locking block, maybe replacing it with a ConcurrentHashMap or something else that avoids global locking, we may be able to improve transit performance in high concurrency scenarios.

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

No branches or pull requests

1 participant