-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Cache accumulator factory #11358
Cache accumulator factory #11358
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Add getUnchecked to NonEvictableCache"
I do think we shouldn't add this method.
// this can not happen because a supplier can not throw a checked exception | ||
throw new RuntimeException("Unexpected checked exception from cache load", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can -> should
(actually "it can happen", if you do some things you shouldn't do)
/** | ||
* A {@link com.google.common.cache.Cache} that does not support eviction. | ||
*/ | ||
public interface NonEvictableCache<K, V> | ||
extends Cache<K, V> | ||
{ | ||
default V getUnchecked(K key, Supplier<V> loader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Guava, getUnchecked
is available on a LoadingCache only (and only without a loader).
I would prefer to stay in line with Guava APIs, so that we don't need to undo these simplifications, eg when switching back to Guava (should they fix the issue), or refactoring the code.
Thus, while I introduced all the "EvictableCache" related class, I wouldn't yet want to embrace them as "an API".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If, however, we wanted to depart from Guava APIs, i would prefer we have a different signature
V <T extends Exception> get(K key, ThrowingSupplier<T> loader) throws T;
this would erase the (logically useless) distinction between get
and getUnchecked
, i.e. the caller wouldn't need to make the choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@findepi and I talked about this off line. The problem with an API like this is exceptions can cross threads when there are concurrent calls to a single element. The cache synchronizes and shares the result for all callers, which means the threads will shared the stacks from the one thread that actuallu executed the loader.
Was the leak only due to the fact we weren't caching things? |
There are still other generated classes that are not garbage-collected like:
|
these are actually cached. Do you say cache is disabled and they are not GCed anyway? |
JVM is up for more than 4 hours and I can still see generated classes from
|
I can approve that |
|
Got it. And the default is 10,000 entries |
It seems that we need also time based cache here
|
After running a load test for almost 2 days, I approve that this fix did the job. |
@sopel39 we should consider limiting it to an hour like the others |
for "Add getUnchecked to NonEvictableCache" -- discussed the plan
@dain can you please explain this? |
I believe so. Based on @guyco33's testing I'm pretty confident. |
Yes, the "leak" is not truly a leak -- the VM will eventually collect those classes if they are no longer referenced. The performance issue is due to not reusing the generated classes, so the VM is in an eternal warming up state for aggregations. |
11d268c
to
2c04ca5
Compare
but it seems that they retained since the reference never gone |
The uncheckedCacheGet method uses a Supplier instead of a Callable and therefore can not throw a checked exception, so a checked is not thrown from uncheckedCacheGet. This simplifies most callers which do not use checked exceptions.
Remove LambdaProvider instances from AccumulatorFactory to simplify caching of the factories.
2c04ca5
to
081f153
Compare
Maybe you are interesting in this #15237 why reference never gone |
Description
Cache generated aggregation accumulator classes. When accumulator factory was split from function management we lost the caching of part of the generated code.
Related issues, pull requests, and links
Documentation
(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.
Release notes
( ) No release notes entries required.
(x) Release notes entries required with the following suggested text: