Skip to content

High CPU Load on the Server while syncing #11240

Closed

Description

@matzex

When a user sync his files with the server and use ~75% or more of his quota, the cpu load on the server side is very high and the owncloud web interface and also the whole server slows down.

Steps to reproduce

  1. Set a storage limit for a user (quota)
  2. Let the user fill his storage with a lot of files and more then 75% of his space
  3. Server slows down when the user sync more files in his space

Expected behaviour

Server should be responsible as always and shouldn't have a very high cpu load.

Actual behaviour

The server side is very slow, syncing with the client is working, but the whole server has a load of 20 and high cpu usage and other services on the box are very unresponsive due the high load. After set the quota for the user to a higher value all problems are resolved. So i think it is an owncloud server side bug in the quota management.

Server configuration

Operating system:
Ubuntu 12.04 on the server side

Web server:
Apache/2.2.22 (Ubuntu)

Database:
mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (i686) using readline 6.2

PHP version:
5.3.10-1ubuntu3.13

ownCloud version:
7.0.2 (stable)

Updated from an older ownCloud or fresh install:
updated

List of activated apps:
News, Roundcube, Calendar, Contacts, Files

The content of config/config.php:

'???', 'passwordsalt' => '???', 'datadirectory' => '???/data', 'dbtype' => 'mysql', 'version' => '7.0.2.1', 'dbname' => '???', 'dbhost' => 'localhost', 'dbtableprefix' => 'oc_', 'dbuser' => '???', 'dbpassword' => '???', 'installed' => true, 'maxZipInputSize' => 0, 'allowZipDownload' => true, 'loglevel' => '4', 'theme' => '', 'maintenance' => false, 'forcessl' => true, 'trashbin_retention_obligation' => '30', 'trusted_domains' => array ( 0 => '???.com', ), 'mail_smtpmode' => 'php', 'mail_from_address' => 'mail', 'mail_domain' => '???.com', ); **Are you using external storage, if yes which one:** local/smb/sftp/... No **Are you using encryption:** yes/no No ### Client configuration **Browser:** Chromium 37.0.2062.94 Ubuntu 14.04 (290621) (64-bit) **Operating system:** Ubuntu 14.04

Activity

  1. PVince81 commented on Sep 23, 2014

    @PVince81
    Contributor

    Does that user have many files in the trashbin ?
    If yes then the CPU load might be the trashbin clearing code that runs when uploading new files.

    The logic is as follows (if I remember correctly): the trashbin size is not allowed to be more than 50% of available size. So when space is becoming less, it will find then discard the older files inside the trashbin.

    CC @schiesbn

  2. matzex commented on Sep 23, 2014

    @matzex
    Author

    Yes this is possible. I will deactivate the Add-On "Deleted files" and hope it will be better then. But also i think this is not the behaviour which owncloud should show.
    Do you think the problem is in the implementation of the Trashbin cleaning? If i understand this correct this would fit to my server cpu load. I had not always problems with the load when the client uploads files. Most time the high load came in cycles and had high peaks.

  3. PVince81 commented on Sep 23, 2014

    @PVince81
    Contributor

    The other thing to try is to ask that user to clear their trashbin and see whether the spike disappears.
    Because if the trashbin is empty, no deletion logic is required.

    The other possibily is also files_versions: I believe this app has a similar cleaning logic (@schiesbn can you confirm ?).

    I can't think of anything else that could be triggered when reaching 70% of the free space (or quota space)

  4. matzex commented on Sep 23, 2014

    @matzex
    Author

    I deactivated both, trash bin and the versions plugin. But unfortunately the deactivation do not delete files in the trash bin or older versions from the version plugin. So i manually emptied the trash bin. How it is possible to delete all old versions of all files? (I want to retain the current versions)
    I have to note, if the admin disable the trash bin plugin or the files_versions plugin owncloud should delete all files or ask to delete all files in the trash bin and older file versions.

  5. 31SFX4 commented on Feb 26, 2015

    @31SFX4

    I also see very high CPU load and it looks related to the trashbin as you explain above. I have one "user" that's connected to a security camera that uploads several images per minute, which are then deleted after a month, so the trashbin contains thousands of files if I don't empty it manually. When this happens, then load goes up to extreme values (so much that we had to kill apache to get it back working). This happened several times.

    There seems to be something broken in the delete code. Even when I stop uploads and let the load go down, when I then try to delete a few files from the web interface it takes dozens of minutes, during which the user can't do anything else at all. Other users can login at the same time and I don't see performance issues for them.

    I'm on 7.0.3 with PHP 5.3.3. (I know I should upgrade).

  6. PVince81 commented on Feb 26, 2015

    @PVince81
    Contributor

    Okay. Something must be wrong in the auto-expire function of the trashbin. (CC @schiesbn)

    Did you set a quota for that specific user or is the trashbin "full" whenever the disk space itself is full ?

  7. 31SFX4 commented on Feb 26, 2015

    @31SFX4

    @PVince81 No, I didn't set a quota for the user. The disk is not full, actually quite a lot of space free, but if I remember correctly the disk usage/free space reported by OC doesn't match disk space either. I'm not at the same computer so I can't give numbers right now, can try to investigate if you think that's relevant.

  8. PVince81 commented on Feb 26, 2015

    @PVince81
    Contributor

    Can you try setting a quota for that user ?
    There's a chance that the trashbin will work better and auto-expire.

    From what I remember the trashbin auto-expires files whenever its contents is > 50% of the total space. But I'm not sure how the total space is computed when no quota is set.

    There's still a bug to be looked into. But that info could help a bit. 😄

  9. 31SFX4 commented on Feb 26, 2015

    @31SFX4

    Ok, the user used 11.3Gb (reported in OC), trashbin is 3.8 Gb (with du -s). Total free space is 173Gb (reported in OC, consistent with df). I've now set the quota to 15GB, and it reports "11.3 of 15 used".

    Looking at the numbers I'm not exactly sure if trashbin emptying is triggered. I also checked the timestamps in the file_trashbin directory and it seems that files are not removed, except after 30 days. is the 30day cleanup also triggered by uploads (I though it's cron, I'm using webcron)?

    I noticed something else: When I remove a file in the trashbin through the web interface, I get the spinning wheel thing for at least 15 minutes, load goes slowly up and the web interface doesn't respond any more. The file (and keys and versions) in the files_trashbin directory are deleted quite quickly but OC is then still doing something for a very long time afterwards.

  10. PVince81 commented on Feb 26, 2015

    @PVince81
    Contributor

    There is also logic to auto-expire the oldest files to make sure the trashbin size does not exceed 50% of the free space. (I thought it was total storage but I re-read this https://doc.owncloud.org/server/8.0/user_manual/files/deletedfiles.html#managing-deleted-files that says it's the free space).

    So your free space is 15-11.3=3.7 GB. So the trashbin content is not allowed to exceed 3.7*50% = 1.85 GB. But you said your trash size is about "3.8GB" which is much more.
    You could check the trash size as seen by OC in the database with select * from oc_filecache fc, oc_storages s where path = 'files_trashbin' and fc.storage=s.numeric_id. Check the entry that has the storage id of your user.

    Either the size known to OC is wrong, or it takes so much time to expire that it runs into a timeout and never finishes.

  11. 31SFX4 commented on Feb 26, 2015

    @31SFX4

    ... further to my last comment, removing a file from trashbin using web interface. File & keys are deleted from server directory after 11 minutes, web interface becomes responsive again another 6 minutes later. Server load goes up to 15-20 during all this time. I can see that the server gets easily overwhelmed if many files are emptied out of the bin.

  12. PVince81 commented on Feb 26, 2015

    @PVince81
    Contributor

    A theory is that if you manage to reduce its size under the maximum, it might work properly again.

    But there is definitely something wrong with it.
    How many files to you have in total ? Do you have many subdirectories ?

    I remember seeing a "scan()" command there which might or might not recurse through all the files to gather information.

  13. 31SFX4 commented on Feb 26, 2015

    @31SFX4

    @PVince81 Sorry, wasn't clear: My free space was 173 Gb. I only set the quota to 15Gb an hour ago after your suggestion, so the 3.8Gb was less than 50% of 173. I have now started uploading again with the quota of 15Gb so I expect the trash should be emptied down to 1.85 for the new quota.

    The SQL reports -1 as size for this user (but I don't know what it was before I reduced the quota) The values for the other users look more ok (e.g. 105090548).

    I have to go now but will keep an eye on this.

  14. PVince81 commented on Feb 26, 2015

    @PVince81
    Contributor

    -1 means SPACE_NOT_COMPUTED which means that the internal scanner (probably the scan() I referred to before) does not know how much space the trashbin uses. Might be a clue.

    I suspect that the scanner never manages to actually finish scanning the trashbin (timeout or error?) so the size calculation fails and stays -1.

    Let me know how it goes.

    A few notes for devs to try later:

    1. Have a trashbin which size is several times bigger than the free space
    2. Have a trashbin where scan times out
    3. Manually set the size of "files_trashbin" to -1 and see what happens when deleting files
  15. PVince81 commented on Mar 2, 2015

    @PVince81
    Contributor

    I just remembered something: the trashbin expiration is only triggered when files are deleted, not when files are uploaded... I think this was decided due to potential performance issues, because if OC would run the expire logic for every uploaded file, it would get slow.

    But it seems that it is what you guys experienced. The question is whether the slow syncing operation you had included file deletion or just uploads ?

  16. PVince81 commented on Mar 2, 2015

    @PVince81
    Contributor

    Ok, wrong. I see there's a "post_write_hook" that would trigger expiration.

    GOT IT: when expiring files after upload, it calls the scanner for EVERY deleted file.
    The scanner is used to discover versions. The scanner is slow.

    Steps to reproduce:

    1. Create a user "user1"
    2. Set the quota of "user1" to 10GB
    3. Upload several files with a total of 500MB with the sync client
    4. Delete those files again and check that they do appear in the trashbin
    5. Set the quota of "user1" to 300MB
    6. Put breakpoint here: https://github.com/owncloud/core/blob/stable7/apps/files_trashbin/lib/trashbin.php#L889
    7. Upload a 100MB file

    You'll notice that it stops at the breakpoint (the scanner call) for every file that gets expired.

  17. PVince81 commented on Mar 2, 2015

    @PVince81
    Contributor

    @DeepDiver1975 see previous comment.
    Even if expiration is moved to a background job, the problem above should be looked into to make expiry faster and avoid CPU spikes.

  18. 31SFX4 commented on Mar 2, 2015

    @31SFX4

    Thanks for the update. I haven't more time to do more tests, but your explanation sounds consistent with my case. If it really scans for every deleted file, I can see problems for cases like mine (creating and deleting some hundreds to thousands of files every day).

  19. PVince81 commented on Mar 2, 2015

    @PVince81
    Contributor

    Fix is here: #14640

  20. PVince81 commented on Mar 6, 2015

    @PVince81
    Contributor

    Closing in favor of #13974

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions