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

Cache project #837

Merged
merged 3 commits into from
Nov 27, 2024
Merged

Cache project #837

merged 3 commits into from
Nov 27, 2024

Conversation

stephenwf
Copy link
Member

This adds 3 features:

  • Disables server-side rendering on the 2 review/task pages.
  • Adds a Stale-while-revalidate memory cache and uses it for slow project queries
  • Adds a new request trace and in-memory store of the slowest requests. (avg, max, count)

The request trace is visible on the System page in the admin.
image

It can be disabled with the environment variable flag: DISABLE_SLOW_REQUEST_TRACKING=true

Copy link

netlify bot commented Nov 26, 2024

Deploy Preview for madoc-storybook ready!

Name Link
🔨 Latest commit 1bf3ce0
🔍 Latest deploy log https://app.netlify.com/sites/madoc-storybook/deploys/6745db02f75aa30008ba44bf
😎 Deploy Preview https://deploy-preview-837--madoc-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +33 to +40
if (Object.keys(slowRequestStore).length > 50) {
// Sort by slowest.
const sorted = Object.values(slowRequestStore).sort((a, b) => b.slowest - a.slowest);
const slowest = sorted.pop();
if (slowest && slowest.key) {
delete slowRequestStore[slowest.key];
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't ideal, but it prevents looping every entry on line 23. There is a finite number route too - so if it is a problem it can be removed completely.

Copy link

Preview docker image available

docker pull ghcr.io/digirati-co-uk/madoc-api:pr-837

Comment on lines +36 to +37
cache.put(key, result, timeInMs);
cache.put(`@stale/${key}`, result, staleTimeInMs);
Copy link
Member Author

Choose a reason for hiding this comment

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

I checked the source code of memory-cache. It doesn't copy the result, so the extra memory to keep a stale copy is only the size of the key. The memory is released when you put the stale copy. It will mean that for infrequent requests we will hold onto stale data for longer. I've set it to 8 hours for now. (The service will also restart the node process if max memory is reached).

@stephenwf stephenwf merged commit 879746e into main Nov 27, 2024
6 checks passed
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.

1 participant