-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Memory leak issues when upgrading form parse server ‘~2.x’ to ‘~3.x’ #6061
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
Comments
@n-so You can check out this for possible solutions when not using enableSingleSchemaCache. I don't believe those solutions have been implemented since a solution already exists. Feel free to try and test them for yourself. We will try to look into it also. @acinader @davimacedo Should enableSingleSchemaCache be set to true by default? I think it pretty harmless. |
Yes. I think it should be set by default. We'd need to mention it in the next release and ideally also the downsides of it. |
Hi @davimacedo , |
The current implementation creates a new cache per request. This is to prevent side effects between requests. Using enableSingleSchemaCache is basically the same as disabling cache.clear() while using the same cache for all requests. Does cache.clear() gets called after every request? If not, implementing that would fix your memory issue while minimizing side effects |
@davimacedo does cache.clear() gets called. I couldn’t find it. Where should we put it? RestQuery / RestWrite execute? |
@dplewis @n-so Just to make sure that we are all in the same page. This is what happens at each request:
If enableSingleSchemaCache is enabled, a single key is used and therefore the same cache is re-used in all requests. On the other hand, if enableSingleSchemaCache is disabled, a new key is generated at each request. The memory leak happens because the cache that was stored in each request is never cleaned. So, at each request, more cache is accumulated unnecessarily, and the memory continues growing. I was first thinking about adding a middleware here to clean the cache at the end of each request. But I am afraid of jobs, push notifications (others?) routines that could have to continue running even after returning the response to the client. Another option would be a TTL (maybe an additional parameter to Parse Server) associated to each of these keys. Then we could have a process cleaning these caches. |
Worst case If something referenced the cache after it was cleared at end of requests, wouldn't it just refetch the schema from the DB? same as if the cache happened to expire.
This is different than Seems like Guess I'm not following how schema values in the various schema caches would be source of memory leak when there is a Edit: Looked at Does this mean that user/session cache will leak memory as well from same mechansism? We just switched one of our production servers to use in memory cache instead of redis (w/ enableSingleSchemaCache: true) and noticing memory usage slowly increasing when compared w/ the instances using redis cache still. |
@kcolton I agree, I don’t think clearing the cache after each request would have side effects. The SchemaCache is used to checking if classes and fields exist in the database without hitting the DB. Pushes and Jobs have already made writes and queries. After the request is over I don’t see how they would still use the cache. I can do a PR and see how this would run against tests. |
If you take a look here, you will see that the job is started and left executing while the response is returned right away. It means that the request will end (and the cache will be cleaned) before the job finishes to execute. The push notification has a similar process. Probably other features as well. I believe that cleaning the session will not generate bugs as the schema will probably be cached again in the next time that the job needs it. But processes like jobs and push notifications will continue being cause of memory leak. That's why I think that a TTL solution would be the best one. But cleaning the cache in the end of each request will probably solve 99% of the problem. And since it seems really easy to be implemented, we should probably go for it. Will you tackle this one, @dplewis ? |
Issue Description
Hi,
When upgrading from parse-server ‘~2.x’ to ‘~3.x’
I started getting memory leaks issues.
I searched the web and tried many ways to fix this, the only solution that worked was to set enableSingleSchemaCache: true,
But I do not what to use this solution for production .(I don't want to take any risks)
Is there any other solution for this?
attached is a screenshot : comparison of two heap dumps taken 2 minutes apart

Environment Setup
Server
Database
Logs/Trace
No errors or strange messages reported, everything working as usual, just memory increasing.
The text was updated successfully, but these errors were encountered: