-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML] Implement CCMCache #137743
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
[ML] Implement CCMCache #137743
Conversation
Implements a lazy-loading cache in front of the CCM Inference index. By default, the cache holds a single entry for 15 minutes, and cache misses search the CCM index and load the responses into the cache. Some design decisions: - The cache maintains an "empty" entry so that the `isPresent` call can reuse the "empty" response to quickly return false. Invalidating the cache or calling get will drop this "empty" entry. - Invalidating the cache will broadcast a message to all nodes so that all caches on all nodes will invalidate their caches. - Since the broadcast message only works if all nodes are on the latest version, there is a new NodeFeature to enable the cache once all nodes in the cluster have upgraded.
|
Pinging @elastic/ml-core (Team:ML) |
jonathan-buttner
left a comment
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.
Thanks Pat! Left a few suggestions.
| return state.clusterRecovered() && featureService.clusterHasFeature(state, InferenceFeatures.INFERENCE_CCM_CACHE); | ||
| } | ||
|
|
||
| private void enabled(ProjectId projectId, CCMModel ccmModel) { |
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.
nit: It was a bit hard to understand enabled/disabled, cacheEnabled, isEnabled, and CCMModelEntry::enabled. What about for the methods that do the put we call them enabledEntry(), setEnabled, or createEnabledEntry?
| this.client = client; | ||
| } | ||
|
|
||
| public void get(ActionListener<CCMModel> listener) { |
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.
Could you add a comment mentioning that the expectation is that a caller would first interact with isEnabled before calling get() and mention that if the configuration entry is in the disabled state that this call with read through to the backing index.
|
|
||
| public class CCMCacheTests extends ESSingleNodeTestCase { | ||
|
|
||
| private static final TimeValue TIMEOUT = new TimeValue(30, TimeUnit.SECONDS); |
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.
Instead of using this could we use TimeValue.THIRTY_SECONDS?
| assertFalse(isPresent()); | ||
| assertThat(ccmCache.stats().getHits(), equalTo(1L)); | ||
| assertThat(ccmCache.stats().getMisses(), equalTo(1L)); | ||
| } |
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 might have missed it but do we have a test for the else case in this block:
CCMCache::get
if (cachedEntry != null && cachedEntry.enabled()) {
listener.onResponse(cachedEntry.ccmModel());
} else {
Could we add a test that when the internal entry is in the disabled state (but present and not null) that we get a cache miss aka hit the else case?
Implements a lazy-loading cache in front of the CCM Inference index. By default, the cache holds a single entry for 15 minutes, and cache misses search the CCM index and load the responses into the cache.
Some design decisions:
isPresentcall can reuse the "empty" response to quickly return false. Invalidating the cache or calling get will drop this "empty" entry.