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

add spec cache #1066

Merged
merged 5 commits into from
Nov 24, 2020
Merged

add spec cache #1066

merged 5 commits into from
Nov 24, 2020

Conversation

cgardens
Copy link
Contributor

@cgardens cgardens commented Nov 24, 2020

What

  • The UI is becoming unusable because it is so slow. I was getting frustrated trying to debug the snowflake issues today because UI couldn't keep up. The slowness is because we are always fetching specs (especially now with multiple destinations there are even more specs to fetch).

How

  • Cache calls to get spec.
  • If you need to invalidate the cache for dev purposes restart the server.
  • Cache entries are re set when using the admin UI

}

@Override
public void put(String imageName, ConnectorSpecification spec) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

opted not to use the LoadingCache that guava has (where it does fetch-if-absent behavior). mostly, i didn't like the error handling.

this whole iface exists though because i want to be able to change my impl easily if i decide i messed up here.

Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

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

Nice.

My main concern is that caching is leaking outside the scheduler handler. Why don't we encapsulate it inside the get spec method of the scheduler handler entirely? This means we need to restart the dev server if we ever hotfix an image, but this can be handled internally by using the SHA of the image we use or something like that (or for now add a time-based expiry to the cache).

.withDestinationDefinitionId(currentDestination.getDestinationDefinitionId())
.withDockerImageTag(destinationDefinitionUpdate.getDockerImageTag())
.withDockerRepository(currentDestination.getDockerRepository())
.withName(currentDestination.getName())
.withDocumentationUrl(currentDestination.getDocumentationUrl());

configRepository.writeStandardDestinationDefinition(newDestination);
// we want to re-fetch the spec for updated definitions.
specCache.evict(destinationDefinitionUpdate.getDockerImageTag());
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be the whole image name? right now it's just the tag

@cgardens
Copy link
Contributor Author

cgardens commented Nov 24, 2020

@sherifnada

Why don't we encapsulate it inside the get spec method of the scheduler handler entirely?

could you say more about what you mean by this? what you're saying may be clarified with this: keep in mind that the handlers are all ephemeral. there is no guarantee that they survive from one api call to another or that the same handlers are used to field api calls from the same caller. in order for the cache to be used across all handlers it has to be up in ServerApp.

this can be handled internally by using the SHA of the image we use

so what you're proposing is that the handler shells out to docker and tries to look up the sha has of an image to see if it has changed? i'm reticent to add a docker dependency on the server. do you think it's worth it?

for now add a time-based expiry to the cache

i feel pretty strongly that i don't want to do this now. adding time-based anything to this adds a really obnoxious set of cases you need to think about when you're debugging these things. we should only use it if it serves an important use case. in this case, we are adding very few entries to the cache and other than changing the tags we never want to change the entries (except in a well known development use case for which there is a workaround).

Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

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

Sync'd offline, keeping current approach (and adding unit tests) to leave the door open for a smoother hotfixing experience.

@cgardens cgardens merged commit ae5c630 into master Nov 24, 2020
@cgardens cgardens deleted the cgardens/add_spec_caching branch November 24, 2020 18:49
@michel-tricot
Copy link
Contributor

I believe there must a way to hide the caching logic so that it doesn't spread in the codebase like it does right now.

Also It is not completely clear to me why we need an eviction logic since spec is supposed to be immutable and tied to (imagename,version)

Let's take sometime to discuss it.

@cgardens
Copy link
Contributor Author

Sounds good!

Also It is not completely clear to me why we need an eviction logic since spec is supposed to be immutable and tied to (imagename,version)

This is contributor DX. If the version of the connector to you are using is "dev" as you iterate on it, you want to be able to overwrite the existing one. Was one of the things that zazmic got stuck on.

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