Skip to content

Shares Plugin really slow when listing lots of files in folder with high php-fpm load #25266

Closed

Description

@slade87

Steps to reproduce

  1. Enable Shares Plugin
  2. Create a folder with with more than 1000 files
  3. Go into folder to list the files
  4. I made a blackfire.io log with just a small folder : https://blackfire.io/profiles/5829bcdd-a0b0-443b-97bb-832bcac8c0d8/graph for analysis

Expected behaviour

Tell us what should happen
Site should show files in the folders almost immediately (maybe 1 - 2 seconds) (sql query of entire oc_filecache takes less than 0.01 seconds when testing)

Actual behaviour

Tell us what happens instead
In my case it takes from 10 seconds upwards for less than 1000 files
for more than 1000 files it takes more than 15 seconds to just display the list of files. Only the "loading" icon is showing.

Server configuration

Operating system:
Linux ubuntu 16.04
Web server:
nginx
Database:
mariadb
PHP version:
7.0.8
ownCloud version: (see ownCloud admin page)
9.0.2
Updated from an older ownCloud or fresh install:
fresh or updated same effect
Where did you install ownCloud from:
ubuntu package repository

Login as admin user into your ownCloud and access
No errors have been found.

List of activated apps:
Music, Documents, SharesPlugin, ExternalStorage, Gallery

The content of config/config.php:
"system": {
"updatechecker": false,
"instanceid": "ocqqq4thcgry",
"passwordsalt": "_REMOVED SENSITIVE VALUE",
"secret": "_REMOVED SENSITIVE VALUE
",
"trusted_domains": [
"xxxxx",
"xxxxx",
"xxxxx"
],
"datadirectory": "/var/www/owncloud/data",
"overwrite.cli.url": "xxxxxxxxxx",
"dbtype": "mysql",
"version": "9.0.2.2",
"dbname": "owncloud",
"dbhost": "localhost:/var/run/mysqld/mysqld.sock",
"dbtableprefix": "oc_",
"dbuser": "_REMOVED SENSITIVE VALUE",
"dbpassword": "_REMOVED SENSITIVE VALUE
",
"installed": true,
"maintenance": false,
"theme": "",
"filelocking.enabled": "true",
"memcache.local": "\OC\Memcache\APCu",
"memcache.locking": "\OC\Memcache\Redis",
"filesystem_check_changes": 0,
"cron_log": true,
"log_rotate_size": 10485760,
"debug": false,
"redis": {
"host": "/var/run/redis/redis.sock",
"port": 0,
"timeout": 0,
"dbindex": 0
},
"trashbin_retention_obligation": "auto",
"logtimezone": "UTC"

Are you using external storage, if yes which one: local/smb/sftp/...
Yes smb

Are you using encryption: yes/no
no
Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/...
no

Blackfire.io performance log
https://blackfire.io/profiles/5829bcdd-a0b0-443b-97bb-832bcac8c0d8/graph

Activity

  1. slade87 commented on Jun 25, 2016

    @slade87
    Author

    I have been able to workaround this slowdown by editing SharesPlugin.php:148
    handleGetProperties()
    {
    $shares = [];
    return new SharesTypeList( $shares );
    ...
    }

    and now listing files in folders is back to normal (about 1-2 seconds for my 2800 files folder) and sharing still seems to work without any issues?!?!
    Any ideas on how to improve this?

  2. PVince81 commented on Jun 27, 2016

    @PVince81
    Contributor

    @slade87 if I understand your change, it seems you discarded the sharing information completely, so the web UI will not show the sharing indicators at all.

    The share manager needs to implement a new method that leverages the database better, something like select * from oc_share where item_source in (select fileid from oc_filecache where parent = $parentFolderId) or using a join, where $parentFolderId is the fileid of the parent folder in which to retrieve the shares.

    @owncloud/sharing

  3. added this to the milestone on Jun 27, 2016
  4. PVince81 commented on Jun 27, 2016

    @PVince81
    Contributor

    hmm and even that might not work 100% in case of mount points, but could be used as a base to pre-retrieve the share statuses. And then a second query might be needed to make sure to also cover reshares and mount points.

  5. slade87 commented on Jun 27, 2016

    @slade87
    Author

    @PVince81
    Yes my change bypasses and returns immediately out of shares Plugin. However shares still seem to work without any issues for me which seems very strange. If you have any change i can help testing. Thanks alot for looking into the issue.

  6. PVince81 commented on Jun 27, 2016

    @PVince81
    Contributor

    Yes, shares will still work. The purpose of this part is only for the user experience, so that a user can see the sharing indicators on the file list.

    Whenever the user opens the share panel, the share details for that file will be loaded again (indicator is only minimal info)

  7. PVince81 commented on Jun 27, 2016

    @PVince81
    Contributor

    without the share indicators a user might need to click on "Share" on every file to find out which one was actually shared

  8. rullzer commented on Jun 27, 2016

    @rullzer
    Contributor

    I agree we need fancier methods. But keep in mind that we want to operate on an abstract level. E.g. You pass in an \OCP\Files\Folder to a function, then that should have a method to get all the id's for the children etc.

    Joining is basically not done if we want to provide a modular setup.

  9. PVince81 commented on Jun 27, 2016

    @PVince81
    Contributor

    Hmm, right. But this only applies if we consider that the Folder interface can be a different implementation. I think this was relevant in the discussions about custom storages which might store the file ids somewhere else than the database.

    So if we'd want to use the join anyhow, it would need to check that we're dealing with a default implementation.

    But as you say, maybe the solution that asks for a list of ids on the Folder object would already improve performance.

  10. rullzer commented on Jun 27, 2016

    @rullzer
    Contributor

    Yeah it is not ideal. But I prefer to keep the sharing stuff simple and clean. It is already a bit to cluttered in some scenarios (and needs to be cleaned up more). But I think this would already be a step in the right direction.

    Also here applies I'd rather have 1 path then a check if we have the default implementation etc. Duplication will lead to bugs eventually or untested stuff.

    Adding a getShareStatus function that takes a folder (and some other args) should be a good start I think

  11. self-assigned this
    on Dec 6, 2016
  12. 4 remaining items

  13. PVince81 commented on Feb 28, 2017

    @PVince81
    Contributor
  14. self-assigned this
    on Feb 28, 2017
  15. mrow4a commented on Feb 28, 2017

    @mrow4a
    Contributor

    @PVince81 Will try to rebuild it and levarage sth like
    public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0); with pageing instead one query per file. Probably we cannot just use the function above

    https://github.com/owncloud/core/blob/master/apps/dav/lib/Connector/Sabre/SharesPlugin.php#L113

  16. PVince81 commented on Feb 28, 2017

    @PVince81
    Contributor

    Sounds good. You could go even further and take an array of fileids and plug it directly into the query with a select ... where file_source in (...)

  17. mrow4a commented on Feb 28, 2017

    @mrow4a
    Contributor

    Dont spoil, I am having fun here :>

  18. DeepDiver1975 commented on Feb 28, 2017

    @DeepDiver1975
    Contributor

    Sounds good. You could go even further and take an array of fileids and plug it directly into the query with a select ... where file_source in (...)

    but chunk it in blocks of 1000 - dbs have limits in IN conditions

  19. PVince81 commented on Feb 28, 2017

    @PVince81
    Contributor

    @DeepDiver1975 you heard the man, don't spoil it. 😉
    I was reserving this as a surprise for later in his PR.

    Since we're already there, here is an example how to chunk https://github.com/owncloud/core/blob/master/lib/private/Repair/CleanTags.php#L190

  20. mrow4a commented on Feb 28, 2017

    @mrow4a
    Contributor

    Can we decouple file_target in oc_shares into folder_target and file_target? Then we can index on folder and share owner? We dont even need IN() there and to know the files, we just need to know the parent folder, thats it. IN() on varchar might not be a too good idea because it is long (EDIT: ok, digging more into the code I see that I can do it also with ids having getDirectoryListing). We would need to limit to small batches like 10-100. Or at least provide parent_hash column (hash of parent folder path) on which we could index. Is it also viable option?

  21. mrow4a commented on Feb 28, 2017

    @mrow4a
    Contributor

    The other thing we might look at after decoupling is how we can link it. Imagine that you have 15 shares in the folder, and you move the folder. What you need to do is update 1 record instead of 15, because you just update parent varchar :>

  22. PVince81 commented on Mar 1, 2017

    @PVince81
    Contributor

    Can we decouple file_target in oc_shares into folder_target and file_target

    I suggest that in the future we rather use oc_mounts for that. (together with #26190). Then we can discuss to decouple there. "file_target" in oc_share is anyway an abberation. Try the following:

    1. Create three users "user1", "user2", "user3"
    2. Add these users in group "group1"
    3. Login as admin
    4. Share a folder "test" with group "group1"
    5. Login as "user1"
    6. Rename "test" to "test_user1"
    7. Look at oc_share

    You'll see that a new special entry (share type 2) was inserted just to be able to track the specific "file_target" for "user1" due to the rename. Additionally it adds redundant info. We need to use oc_mounts instead for tracking mount point names specific to users instead.

  23. PVince81 commented on Mar 1, 2017

    @PVince81
    Contributor

    What you need to do is update 1 record instead of 15, because you just update parent varchar :>

    That could happen in oc_mounts later. But now thinking of it, if we had the mount point directly in oc_filecache as suggested in #14396, the "move and change all parents" logic already exists in the oc_filecache specific logic.

  24. PVince81 commented on Mar 15, 2017

    @PVince81
    Contributor

    Fixed through #27284

  25. lock commented on Aug 2, 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.

  26. locked as resolved and limited conversation to collaborators on Aug 2, 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