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

Preload spec in serving cache #152

Merged
merged 2 commits into from
Mar 10, 2019
Merged

Conversation

pradithya
Copy link
Collaborator

@pradithya pradithya commented Mar 6, 2019

This PR change 2 behaviour in serving component:

  1. All spec (feature spec, storage spec, and entity spec) is retrieved from Core and loaded to cache during start up.
  2. The cache refresh is now asynchronous and take place in a separate thread as the request's thread.

Fix #151

@pradithya
Copy link
Collaborator Author

/assign @tims

@tims
Copy link
Contributor

tims commented Mar 6, 2019

Can you summarise what your PR in words, so it's easier for me to review?

@pradithya
Copy link
Collaborator Author

Updated the PR description

@@ -177,4 +209,16 @@ public StorageSpec load(String key) throws Exception {
public boolean isConnected() {
return coreService.isConnected();
}

/** Preload all spec into cache. */
public void populateCache() {
Copy link
Contributor

@tims tims Mar 7, 2019

Choose a reason for hiding this comment

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

With a MAX_SPEC_COUNT of 1000, once you have more than that, you're going to be evicting things that might actually be commonly used every 5 minutes. Is that a problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that's probably introduce problem. Do you think it's better to not limit the cache size based on the number of entry?

}

@Test
public void testPopulateCache() {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a test for what happens when you exceed the max size of cache in populating. So we're explicit about the intended behaviour.

@@ -58,14 +59,25 @@ public EntitySpec load(String key) throws Exception {
}

@Override
public Map<String, EntitySpec> loadAll(Iterable<? extends String> keys) throws Exception {
return coreService.getEntitySpecs((Iterable<String>) keys);
public ListenableFuture<EntitySpec> reload(String key, EntitySpec oldValue)
Copy link
Contributor

@tims tims Mar 7, 2019

Choose a reason for hiding this comment

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

I think these can be simplified to:

entitySpecLoader = CacheLoader.asyncReloading(
        CacheLoader.from(
            (String key) -> coreService.getEntitySpecs(Collections.singletonList(key)).get(key)),
        executorService);

featureSpecLoader = CacheLoader.asyncReloading(
        CacheLoader.from(
            (String key) -> coreService.getFeatureSpecs(Collections.singletonList(key)).get(key)),
        executorService);

etc..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The asyncReloading won't return old value if anything goes wrong during refresh, that's why I used a more verbose implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah neat

@tims
Copy link
Contributor

tims commented Mar 10, 2019

/approve

@feast-ci-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tims

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tims
Copy link
Contributor

tims commented Mar 10, 2019

/lgtm

@feast-ci-bot feast-ci-bot merged commit 1c6b893 into feast-dev:master Mar 10, 2019
pradithya added a commit that referenced this pull request Mar 11, 2019
* Preload spec in serving cache

* Disable async refresh and only periodically refresh cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants