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

xds: float LRU cache across interceptors #11992

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

shivaspeaks
Copy link
Member

No description provided.

@shivaspeaks shivaspeaks requested a review from ejona86 April 7, 2025 18:46
return;
}
LinkedHashMap<K, V> newCache = createEvictingMap(newSize);
newCache.putAll(cache);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because maxSize is only updated after the map is created, this map will contain all the entries from cache.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createEvictingMap is creating an empty LinkedHashMap. There are separator constructors

LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
LinkedHashMap(Map<? extends K,? extends V> m)

but none that both take an old map and specify the initialCapacity.

@shivaspeaks shivaspeaks requested a review from ejona86 April 8, 2025 02:27
Copy link
Contributor

@kannanjgithub kannanjgithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review comments.

return;
}
LinkedHashMap<K, V> newCache = createEvictingMap(newSize);
newCache.putAll(cache);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createEvictingMap is creating an empty LinkedHashMap. There are separator constructors

LinkedHashMap(int initialCapacity, float loadFactor, boolean accessOrder)
LinkedHashMap(Map<? extends K,? extends V> m)

but none that both take an old map and specify the initialCapacity.

}

V getOrInsert(K key, Function<K, V> create) {
return cache.computeIfAbsent(key, create);
}

private void resizeCache(int newSize) {
if (newSize >= maxSize) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't understand this. I thought if you get a bigger new size you should resize, and if you get an equal or smaller new size only that should be a no-op because decreasing cache size doesn't make since when another filter instance created a bigger cache.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your point but well, cache_size is configuration coming externally. We should adhere to the configuration. If the cache size decreases, then we can't use the normal code to discard entries, as that only discards a single entry. So without special code, the configuration wouldn't be observed.

It is generally really bad to not observe configuration updates, from a testing/debugging perspective. You do a config push and see behavior X, but then after restarting you see behavior Y. It can be really hard to track down the bugs.

The cache size doesn't change often, so the performance hit would be temporary (although there are still issues with that). It's also much easier to figure out what happened. If you keep the old cache, then someone may be debugging something and it matters what happened a month ago.

I discussed this with Eric offline on the similar lines and understood this POV.

static final class Provider implements Filter.Provider {
long cacheSize = 10;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you making a long constant to always cast it to int?

Oh, you've deleted the default in parseFilterConfig(). No, no. parseFilterConfig() should not have any side-effects. The default is 10, not "whatever the last cache size was."

static final class Provider implements Filter.Provider {
long cacheSize = 10;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private final?

(I see now that you are modifying it. No, it must not be modified.)

@shivaspeaks shivaspeaks requested a review from ejona86 April 8, 2025 17:11
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.

3 participants