-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
base: master
Are you sure you want to change the base?
Conversation
return; | ||
} | ||
LinkedHashMap<K, V> newCache = createEvictingMap(newSize); | ||
newCache.putAll(cache); |
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.
Because maxSize
is only updated after the map is created, this map will contain all the entries from cache
.
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.
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.
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.
Review comments.
return; | ||
} | ||
LinkedHashMap<K, V> newCache = createEvictingMap(newSize); | ||
newCache.putAll(cache); |
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.
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) { |
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'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.
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.
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; |
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.
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; |
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.
private final
?
(I see now that you are modifying it. No, it must not be modified.)
No description provided.