-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
PUT request causes server to stop responding and memory use increases when user is a part of many Roles #1380
Comments
edit: after some discussion offline, it sounds like we could improve performance here by changing how roles are queried and cached. |
The hierarchy is just one level deep. I have one Admin role that is the only role relation on a TeamAdmin role that is made for every Team object that is created. |
@spenceps I've refactored the code in the PR it should run in O(n) time. As you only have 1 level of hierarchy that should be constant time. For the memory usage, can you let us know how it's behaving with the fix? You can run it from the development package through babel node |
@flovilmart It is working a lot better now. The request is taking 10-15 seconds now as opposed to never returning. Memory looks a lot better too. I tried to get the changes pushed up to Heroku to make it easier to quantify the memory improvements but for some reason Heroku wasn't recognizing the submodule. When this change gets released I'll look at the memory closer. Thanks. |
That's still a pretty long time. We'll need to provide some caching opportunity so you can handle that caching yourself. and prevent fetching all those roles. What would be interesting is to have a trace of the requests, so we can understand where we spend the time. |
It would be cool to be able to cache to Redis. I forgot to mention the first time that only the first request was slow, subsequent requests were very fast, but that probably wouldn't be the case all the time if I was in production mode and had more than one server. I'm thinking that the best thing for me to do at this point is to change the way I do security on a couple classes so that I don't have a few users that are a part of 14k roles. |
That would be bring a serious improvement. What I suggest is that you create a SuperAdmin role and attach that role to all the objects that would require it. Then add your users to SuperAdmin. That would work, but also increase the burden to flag all the correct objects.
We could expose a role Cache somewhere, with |
@flovilmart Here is the difference that this change made. Before v35 is without this change and after is the same thing done with the change. It comes close to using 1 GB before and 150 MB after. This is on a Heroku dyno with 512 MB RAM so Heroku might have done something because it was over the limit. |
that's a dramatic improvement! |
Environment Setup
Steps to reproduce
A user needs to be logged in and be a part of many Roles. The situation I have is that the user is a part of 14k roles (Mainly through roles relation).
Update an object:
Server never responds running locally or in Heroku's case a 30 second timeout is hit.
Memory usage keeps climbing.
Logs/Trace
Parse-server logs with VERBOSE
Server Errors (Heroku)
What I've figured out so far
I tried stepping through the save process with a local running parse-server and a remote database (Object Rocket). I found that in the RestQuery.js execute function,
_this.runFind()
gets called alot but_this.runCount()
not so much. So I added the print statement shown below.I found that this was being executed on every Role that the user was a part of via the roles relation. There are around 14K roles in this DB with each role having a roles relation to an
Admin
role that the user I logged in was a part of. An exerpt from the console showed the following (somewhere around 14k times):It appears that in order to make an authorized update request parse-server gets all of the roles that the authorized user is a part of. It would make more sense to see what roles would be required by the object that is being updated and get those if needed. It is possible in my situation to change the ACL on a couple classes so that no user has more than a few Roles that they are a part of. However, for compatiblity from the Parse hosted server to self-hosted, open source parse-server it would make more sense to change the way auth handles Roles for update requests.
The text was updated successfully, but these errors were encountered: