Skip to content

Cache grows when not using enableSingleSchemaCache #4247

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

Closed
flovilmart opened this issue Oct 11, 2017 · 13 comments
Closed

Cache grows when not using enableSingleSchemaCache #4247

flovilmart opened this issue Oct 11, 2017 · 13 comments

Comments

@flovilmart
Copy link
Contributor

Issue Description

It has been observer that the new caching mechanism (LRUCache) would not prune proactively it's cache after a certain amount of time, leading to memory growth and explosion.

Steps to reproduce

  • Startup a parse-server, without enableSingleSchemaCache
  • use heapdump through require('heapdump') in your startup script
  • notice that the memory keeps growing after each request.

Expected Results

Memory usage should somewhat remain constant, unused data should not be kept indefinitely.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : >= 2.5.1
    • Operating System: n/a
    • Hardware: n/a
    • Localhost or remote server? local
  • Database

    • MongoDB version: n/a
    • Storage engine: n/a
    • Hardware: n/a
    • Localhost or remote server? n/a

Logs/Trace

See discussion over: #4235

Suggested resolution:

1- make singleSChemaCache default (this should be pretty harmless)
2- actively cleanup upon response end the schema cache used for the request
3- actively prune LRU cache dropping older values periodically

@iamvajid
Copy link

@flovilmart any updates on this issue ? Still looking for someone to take this up ? The label good first issue is tempting me if you can give some courage

@flovilmart
Copy link
Contributor Author

Yes that should be an easy one, the suggested resolution should be solid at the moment, and it will give you a good insight on the underskirts of parse-server :)

If you run into any issue, just let me know!

@cyrixmorten
Copy link

cyrixmorten commented Nov 30, 2017

Can confirm that setting enableSingleSchemaCache: true effectively stops the memory consumption from growing.

Exceeded my memory quota on Heroku this morning and after setting enableSingleSchemaCache to true it has been steady at ~100mb

screen shot 2017-11-30 at 13 43 14

@montymxb
Copy link
Contributor

montymxb commented Dec 2, 2017

Yeah we need to address this. I took a look at some of the code at one point. Haven't confirmed it but it does just seem to be a bad case of not cleaning up the multitude of schema caches that accumulate over time. Interesting code being here in SchemaCache.js. Over time with random prefix ids I imagine you could fill up memory no sweat. One way would be to track formerly used caches (particularly stale?) and flush those after a certain count. Maybe a cache of existing cache prefixes that still exist so we can keep track of them?

@flovilmart
Copy link
Contributor Author

The issue is that:
1- we don’t cleanup the cache / request after the request is over
2- The LRUCache don’t actively prune

We could manually prune the cache just after each requests or periodically, and/or when the request is over; remove the key associated in the cache with it.

@NicksonYap
Copy link

Any fix for this so far?
Does enableSingleSchemaCache: true affect anything?

@flovilmart
Copy link
Contributor Author

It reduces the cache sizes for sure

@NicksonYap
Copy link

I suppose a reduced cache size = reduced performance?

@flovilmart
Copy link
Contributor Author

Nope increased performance. But may yield issues if multiple Schema mutations are run concurrently

@JacobJT
Copy link

JacobJT commented May 21, 2018

The _Schema query has been in our slow queries tab on mLab for a while. Will setting this affect the number of _Schema queries, or only the memory due to caching the results?

Edit - I found this in Definitions.js

  "enableSingleSchemaCache": {
    "env": "PARSE_SERVER_ENABLE_SINGLE_SCHEMA_CACHE",
    "help": "Use a single schema cache shared across requests. Reduces number of queries made to _SCHEMA. Defaults to false, i.e. unique schema cache per request.",
    "action": parsers.booleanParser,
    "default": false
  },

So it should also reduce the number of queries run.

@flovilmart
Copy link
Contributor Author

Yes that’s what it’s meant for

@fsufyan
Copy link

fsufyan commented May 31, 2018

I can confirm that setting the enableSingleSchemaCache to true fixes the memory issue and stabilize the RAM usage between 90-150 MB. It was hitting the 440 MB easily before.
Check the screenshot and notice the highlighted area.

Parse 2.7.1
Ubuntu 16.04

parse-01

@dplewis
Copy link
Member

dplewis commented Jul 10, 2019

Closing via #5612

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

No branches or pull requests

8 participants