Skip to content

Session cache being deleted too often #6726

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

Open
SebC99 opened this issue Jun 2, 2020 · 9 comments
Open

Session cache being deleted too often #6726

SebC99 opened this issue Jun 2, 2020 · 9 comments
Labels
type:feature New feature or improvement of existing feature

Comments

@SebC99
Copy link
Contributor

SebC99 commented Jun 2, 2020

Issue Description

When we monitor our calls to the redis cache, we can see that the user session is regularly missed even (sometimes every minutes, sometimes after 5 or 10 minutes) with a TTL of one hour.

It's hard to figure out why, but this line could be a (small) part of the explanation.

Instead of just removing all keys (of all sessionTokens) of that user, wouldn't it be possible to refresh them with the updated user?

It's clearly not the only reason, as when investigating we see cache misses for a sessionToken even with the user not being updated (no change in the updatedAt field), but it's the only reason we've figured for now...

If you have other ideas, I would be happy to test them :)

Server version: 4.2.0 on AWS Elasticbeanstalk (or local)
Database : MongoDB on Mongo Atlas

@SebC99
Copy link
Contributor Author

SebC99 commented Jun 4, 2020

While investigating, I also found that each time we add a role to a user, the whole roles cache is cleared, instead of just removing that specific role... any idea why?

@stale
Copy link

stale bot commented Nov 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 8, 2020
@mtrezza mtrezza removed the stale label Nov 8, 2020
@SebC99
Copy link
Contributor Author

SebC99 commented Jul 21, 2021

Old thread, but I've noticed something weird.
Due to these lines :

  if (this.className === '_Role') {
    this.config.cacheController.role.clear();
  }

each time a user is added to a role (or a role is created), the cacheController clear the whole Roles cache... or at least it's what is supposed to be done.
BUT, when looking at this cacheController.role.clear() method here:

  clear() {
    return this.cache.clear();
  }

we can see it's clearing the whole cache and not the "Role" one (the Role subCache is only defined by a key prefix, which is not used here).
So if I understand that well, it means each time a Role is updated, all the caches (users, sessions and roles) are cleared.
And maybe the same occurs when a session or a user's password is updated as well

@SebC99
Copy link
Contributor Author

SebC99 commented Jul 22, 2021

@mtrezza I'm not really confortable with Roles management in Parse, so I'm not sure of all the ways Roles can be modify, but wouldn't it be sufficient to replace this

  if (this.className === '_Role') {
    this.config.cacheController.role.clear();
  }

by

  if (this.className === '_Role') {
    if (this.data.users && this.data.users.objects) {
      this.data.users.objects.forEach(({objectId}) => this.config.cacheController.role.del(objectId));
    } else {
      this.config.cacheController.role.clear();
    }
  }

Otherwise, the only way to ensure we clear the right subCache would be to leverage the cacheAdapter client to list all the keys with Role: prefix and delete them.

What do you think?

@mtrezza
Copy link
Member

mtrezza commented Jul 22, 2021

Maybe someone who recently looked into cache optimization in parse server can better answer that, @dplewis ?

@SebC99
Copy link
Contributor Author

SebC99 commented Aug 18, 2021

@dplewis did you have time to look into this? I'm guessing the perf impact can be big as we clear the entire cache each time a role is modified

@SebC99
Copy link
Contributor Author

SebC99 commented Sep 23, 2021

@mtrezza how do you want to proceed with this one? I guess it could have quite huge performance implication as the cache is clearly deleted far too often

@mtrezza
Copy link
Member

mtrezza commented Sep 23, 2021

We are currently focused on fixing long-time open bugs, so enhancements like this are currently not internally prioritized. For now, this will probably stay open until someone in the community picks it up, or it becomes clear that this is a pain point that is so significant that we should reclassify it as a bug.

@SebC99
Copy link
Contributor Author

SebC99 commented Sep 23, 2021

It makes a lot of sense
Thanks for the answer, and I'll try to help as much as I can

@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

2 participants