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

chore: Update cache library #418

Merged
merged 6 commits into from
Jul 6, 2023
Merged

chore: Update cache library #418

merged 6 commits into from
Jul 6, 2023

Conversation

krithika369
Copy link
Collaborator

@krithika369 krithika369 commented Jul 1, 2023

What this PR does / why we need it:

This PR replaces the use of "github.com/coocood/freecache" in the codebase with "github.com/patrickmn/go-cache" for the following reasons:

  • The freecache library needs us to declare the size of the cache ahead of time. go-cache, on the other hand, is map-based and simpler.
  • The freecache library requires each entry to be less than 1/1024 of cache size. This would require us to calculate the cache size ahead of time and does not allow for the occasional large-sized entries. go-cache has no such restriction.

With this change, the transformer config CACHE_SIZE_IN_MB is no longer required and has been removed.

Other changes:

.env.sample is replaced by env-config.yaml, based on the changes introduced by #397

Does this PR introduce a user-facing change?:

Replace Project and Transformer caching library with one that can grow flexibly. Support for the transformer env var config CACHE_SIZE_IN_MB is now removed and if set, will be unused.

Checklist

  • Added unit test, integration, and/or e2e tests
  • Tested locally
  • Updated documentation
  • Update Swagger spec if the PR introduce API changes
  • Regenerated Golang and Python client if the PR introduce API changes

@@ -58,7 +57,7 @@ func (ps projectsService) List(ctx context.Context, name string) (mlp.Projects,
}
}
// Refresh cache and try filtering
err := ps.refreshProjects(ctx)
err := ps.refreshProjects(ctx, name)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When retrieving the projects list, use the name filter if supplied. Without the name filter, all the projects will be retrieved which may be wasteful if we are only interested in one.

Copy link
Contributor

@ariefrahmansyah ariefrahmansyah left a comment

Choose a reason for hiding this comment

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

LGTM with nit comments.

I found go-cache library is simpler because (1) it uses interface instead of []byte. Allowing us to just cast the cache value instead of encoding and decoding json. And (2) We don't need to specify cache size.

Makefile Outdated Show resolved Hide resolved
api/cmd/transformer/Makefile Outdated Show resolved Hide resolved
env-config.yaml Outdated Show resolved Hide resolved
@tiopramayudi
Copy link
Contributor

what happens if the cache keeps increasing? Can it cause OOM?

@krithika369
Copy link
Collaborator Author

what happens if the cache keeps increasing? Can it cause OOM?

@tiopramayudi, that's a good question. Most users set the TTL (using FEAST_CACHE_TTL) to 10 minutes or less. As long as the keys are set to expire frequently, they will be cleaned up routinely and there shouldn't be an explosion of memory.

That said, in theory, if there is lots of data added to the cache with a long expiration period, there can be OOM. So we can add a warning to the users when the feature is released, that they should allocate sufficient memory to the transformer containers if they query a lot of data in their transformation steps.

@krithika369 krithika369 merged commit c919cb1 into main Jul 6, 2023
41 checks passed
@krithika369 krithika369 deleted the fix_project_cache_call branch July 6, 2023 01:28
krithika369 added a commit that referenced this pull request Jul 19, 2023
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. Run unit tests and ensure that they are passing
2. If your change introduces any API changes, make sure to update the
e2e tests
3. Make sure documentation is updated for your PR!

-->

**What this PR does / why we need it**:
<!-- Explain here the context and why you're making the change. What is
the problem you're trying to solve. --->

#418 replaced the in-memory
caching library used in the code with `github.com/patrickmn/go-cache`
everywhere. However, this could be problematic for the transformer, as
indicated by [this
comment](#418 (comment)).
So, this PR reverts the changes to the caching library for the
transformer, so it can continue to rely on
`github.com/coocood/freecache`, which can bound the memory allocated for
the caching.

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required. Enter your extended release note in
the block below.
If the PR requires additional action from users switching to the new
release, include the string "action required".

For more information about release notes, see kubernetes' guide here:
http://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note
Replace Transformer caching library. Support for the transformer env var config CACHE_SIZE_IN_MB is now re-enabled.
```

**Checklist**

- [x] Added unit test, integration, and/or e2e tests
- [ ] Tested locally
- [ ] Updated documentation
- [ ] Update Swagger spec if the PR introduce API changes
- [ ] Regenerated Golang and Python client if the PR introduce API
changes
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