Skip to content

change propagator updates parent too often #18359

Closed

Description

@schiessle

I discovered a issue with sharing in combination with encryption. If you share a folder containing 6 files with 4 users the share operation will take 24 seconds and runs 2500 queries !!!!

The problem seems to be that every time we write a file- or share-key the cache propagator propagates the changes to all parents although the cache updater already calls the propagator for each parent.

See the profile below.
https://blackfire.io/profiles/03cdaffa-bc31-4f17-921e-df0da04ed0c3/graph

@icewind1991 This needs urgent fixing, can you have a look? Thanks!

cc @nickvergessen @DeepDiver1975

Activity

  1. added this to the milestone on Aug 17, 2015
  2. icewind1991 commented on Aug 17, 2015

    @icewind1991
    Contributor

    although the cache updater already calls the propagator for each parent.

    That's not the case, there are 2 propagation steps, correcting folder sizes and propagating mtimes/etags, they are done separate because they have different requirements

  3. icewind1991 commented on Aug 17, 2015

    @icewind1991
    Contributor

    The problem is that the encryption code makes 48 filessystem calls with an average folder depth of 8.

    Since there is no knowledge in the filesystem layer about how things are grouped the only way to handle that is to do 48 * 8 * 2 = 786 cache updates (the remaining queries are cache reads from what I can tell)

  4. schiessle commented on Aug 17, 2015

    @schiessle
    ContributorAuthor

    The problem is that the encryption code makes 48 filessystem calls with an average folder depth of 8.

    We still need to find a solution how to improve this. On the encryption level there is not much we can do about it. We need to write a file-key for each file and a share key for each user and create the folder before we can create the files. I don't see how this can be improved on the encryption side, we perform the absolute minimum of operations in order to update the keys.

    I also don't really understand how the 786 cache updated leads to 2578 queries at the end. According to the graph they all come from OC\File\Cache\Cache::update, something which shouldn't be triggered by a read operation

  5. schiessle commented on Aug 17, 2015

    @schiessle
    ContributorAuthor

    That's not the case, there are 2 propagation steps, correcting folder sizes and propagating mtimes/etags, they are done separate because they have different requirements

    Just thinking: Couldn't this for example be done in a way that we first collect the data for mtime/etag and folder size in two steps but then perform the actual db update in one step once we have collected all the new values?

  6. icewind1991 commented on Aug 17, 2015

    @icewind1991
    Contributor

    According to the graph they all come from OC\File\Cache\Cache::update

    The graph is lying, if you click on executeAudited you see that it has 6 callers, the graph only shows callers which are significant in time and since updates are way more expensive (~87% for 786 updates, and ~5% for the remaining ~1800 reads)

  7. icewind1991 commented on Aug 17, 2015

    @icewind1991
    Contributor

    We still need to find a solution how to improve this. On the encryption level there is not much we can do about it. We need to write a file-key for each file and a share key for each user and create the folder before we can create the files. I don't see how this can be improved on the encryption side, we perform the absolute minimum of operations in order to update the keys.

    Currently the only way to improve it is to bypass the view, work directly on the storage and call the updater yourself when you're done doing all operations. Since the crypt code knows how it will be using the filesystem it doesn't need to keep the cache uptodate during every step, just needs to make sure it's consistent at the end.

    I've been thinking about adding some sort of "operation grouping" api to the filesystem to make things like this easier, something like

    $view->grouped(function($view){
        $view->doSomething();
        $view->doMore();
    });
    
    Where the cache updates will only happen once the entire group is done
  8. schiessle commented on Aug 18, 2015

    @schiessle
    ContributorAuthor

    The graph is lying, if you click on executeAudited you see that it has 6 callers, the graph only shows callers which are significant in time and since updates are way more expensive (~87% for 786 updates, and ~5% for the remaining ~1800 reads)

    So it seems that we still need to optimize the ~95%, even if it is "only" 786 queries from ~2500.
    If we could update each file cache entry only once instead of twice we could already reduce the time by almost 50% (still thinking if something like this could be possible #18359 (comment)). It would be still way to much but a step in the right direction.

    I also checked the encryption code once more and I don't see where the read opertions come from, we don't do any of them while writing the keys. I tried to cache some file_exists()/is_dir() calls which are used relatively often (https://github.com/owncloud/core/blob/master/lib/private/encryption/keys/storage.php#L306), but this doesn't make much sense because at least for the local storage this are only file system operations and no db operations. Maybe some of the read operations come from the update process and probably some from the sharing code? But it is probably not worth thinking hard about optimizing 1,9% of this issue, let us better try to get the 95% down.

    I've been thinking about adding some sort of "operation grouping" api to the filesystem to make things like this easier, something like...

    could be a step in the right direction. Any chance we can see something like this for 8.2 or 8.3?

  9. PVince81 commented on Aug 18, 2015

    @PVince81
    Contributor

    Is this about etag / size propagation when writing to "files_encryption" or to "files" ?
    Because if this is happening outside of "files" we can probably skip such updates as we don't need etags there.

  10. schiessle commented on Aug 18, 2015

    @schiessle
    ContributorAuthor

    It's all updates, size, etag and mtime. According to @icewind1991 every file/folder is touched twice. Once for to update the size and once to update the mtime and etag

  11. schiessle commented on Aug 31, 2015

    @schiessle
    ContributorAuthor

    @michaelstingl for your information

  12. 37 remaining items

  13. PVince81 commented on Feb 29, 2016

    @PVince81
    Contributor

    I don't want to merge #22733 now, it's too risky (moved to 9.0.1).

    #22648 seems to be an oversight from another perf fix you did before, so we need to get that one in too for 9.0 to get some benefit. Is that correct ?

  14. icewind1991 commented on Feb 29, 2016

    @icewind1991
    Contributor

    (all comparisons are made against stable8.2)

    @icewind1991 is there any improvement already without #22733 ? At least with #22648 alone ?

    Just #22648 ~19%

  15. icewind1991 commented on Feb 29, 2016

    @icewind1991
    Contributor

    I don't want to merge #22733 now, it's too risky (moved to 9.0.1).

    #22648 seems to be an oversight from another perf fix you did before, so we need to get that one in too for 9.0 to get some benefit. Is that correct ?

    I think you're mixing up the 2, #22733 is a fairly small fix that I missed before, #22648 I agree is to risky

  16. PVince81 commented on Feb 29, 2016

    @PVince81
    Contributor

    Yeah, mixed up sorry.

  17. MorrisJobke commented on Mar 1, 2016

    @MorrisJobke
    Contributor

    Only #22648 is not merged and will not get into 9.1 -> moving this issue to 9.1 too, because the 9.0 issues are resolved.

  18. modified the milestones: , on Mar 1, 2016
  19. MorrisJobke commented on Mar 1, 2016

    @MorrisJobke
    Contributor

    @PVince81 Or should we create a new issue?

  20. PVince81 commented on Mar 1, 2016

    @PVince81
    Contributor

    I'm fine keeping this issue.

  21. ghost changed the title [-]change propagator updates parent to often[/-] [+]change propagator updates parent too often[/+] on Mar 31, 2016
  22. icewind1991 commented on May 3, 2016

    @icewind1991
    Contributor

    Can we close this issue with #22648 merged?

  23. lock commented on Aug 4, 2019

    @lock

    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.

  24. locked as resolved and limited conversation to collaborators on Aug 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions