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

Better callForAllUsers memory usage #24327

Merged
merged 2 commits into from
May 2, 2016

Conversation

nickvergessen
Copy link
Contributor

Should help to reduce the memory usage when callForAllUsers() is called https://github.com/owncloud/enterprise/issues/1298

@DeepDiver1975 @butonic

@nickvergessen nickvergessen added this to the 9.1-current milestone Apr 28, 2016
@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @icewind1991, @DeepDiver1975 and @blizzz to be potential reviewers

@nickvergessen nickvergessen changed the title Better call for all users performance Better callForAllUsers memory usage Apr 28, 2016
continue;
}
$user = $this->getUserObject($uid, $backend, false);
$return = $callback($user);
Copy link
Member

Choose a reason for hiding this comment

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

I'd say there is a unset($user) missing ...
... assuming we iterate once over all users (500k+ e.g.) - we only need each user once - but we should free the memory after calling the callback

Copy link
Contributor

Choose a reason for hiding this comment

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

php should gc the old $user instance when the variable is re-asigned

Copy link
Member

Choose a reason for hiding this comment

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

yeah ... should 🙈

Copy link
Member

Choose a reason for hiding this comment

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

is there a way to force gc on php?

I know from other systems that gc cycles need some idle time to be invoked - no idea if this applies to php as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this pr but useful knowledge for any php memory manipulations:

The most reliable way I have found to have php cleanup it's memory is to have a variable go out of scope (i.e. move the memory consuming task to a new function so all newly allocated objects go out of scope the moment the task is done)
Re-assigning a variable or unsetting it all seem to only work if the gc feels like it

Copy link
Member

Choose a reason for hiding this comment

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

@DeepDiver1975 an unset($user) here wont help. I think @nickvergessen is on the spot - the problem is $this->cachedUsers[$uid] = new User($uid, $backend, $this, $this->config); I like @icewind1991 s proposal to use a CappedMemoryCache.

For what it is worth, gc_collect_cycles() should run the garbage collector. It won't free the $this->cachedUsers[$uid] however.

Copy link
Member

Choose a reason for hiding this comment

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

For what it is worth, gc_collect_cycles() should run the garbage collector. It won't free the $this->cachedUsers[$uid] however.

sure - those are all cached and as a result will no gc'd 🙈

@icewind1991
Copy link
Contributor

icewind1991 commented Apr 28, 2016

A better approach might be to replace the cachedUsers array with a CappedMemoryCache

that way it also fixes the memory usage if any other situation where create query a lot of user objects

@nickvergessen
Copy link
Contributor Author

A better approach might be to replace the cachedUsers array with a CappedMemoryCache
that way it also fixes the memory usage if any other situation where create query a lot of user objects

@PVince81 suggested the same at lunch, but I think in general it's good to know where things like that happen and callForAllUsers should only happen on install/update/background job anyway, so this is my prefered way.

@DeepDiver1975
Copy link
Member

and callForAllUsers should only happen on install/update/background job anyway,

that's the current use case - but for sure not limited to this ...

@nickvergessen
Copy link
Contributor Author

So do we want to switch to cappedcache now, or use this for backport and use the cappedcache only in 9.1+ ?

@nickvergessen
Copy link
Contributor Author

Bump @DeepDiver1975 @PVince81

@DeepDiver1975
Copy link
Member

Yes - let's move this in 👍

@DeepDiver1975
Copy link
Member

backport request added @karlitschek

@karlitschek
Copy link
Contributor

nice. makes total sense. please backport 👍

@DeepDiver1975
Copy link
Member

nice. makes total sense. please backport 👍

@nickvergessen can I ask you to submit the pr? THX

@nickvergessen
Copy link
Contributor Author

Backport in #24384

Not sure if we have to (should) force this into 9.0.2 so shortly

@DeepDiver1975 DeepDiver1975 merged commit d7eb17b into master May 2, 2016
@DeepDiver1975 DeepDiver1975 deleted the better-callForAllUsers-performance branch May 2, 2016 11:12
@lock
Copy link

lock bot commented Aug 6, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants