Synchronizing small files = very slow
Expected behaviour
Files sync at about the speed of the broadband connection, independent of size unless limited by CPU or IO on client or server.
Actual behaviour
Synchronizing a folder with many small files is terribly slow. For instance a test folder with 10k 3-byte-files synchronizes with a speed of about 1 file per second over a broadband connection. The load on both client and server while doing this is negligible. Tested with server running Ubuntu 12.04 with current owncloud 6.0.1-1, client current Linux or Macos clients. The transfer rates on the broadband connection are very low as well, so this is not the bottleneck.
Steps to reproduce
- Download http://xn--grgen-jua.name/owncloudStressTest.tar.bz2
- unpack it into an owncloud folder that syncs with a remote owncloud machine.
- Observe upload speeds of one to a few 3-byte-files per second.
Server configuration
Operating system: Ubuntu 12.04
Web server: lighttpd
Database: mysql
PHP version: PHP 5.3.10-1ubuntu3.9
ownCloud version: 6.0.1-1
Updated from an older ownCloud or fresh install: Updated from ownCloud 5
The content of config/config.php:
$CONFIG = array ( 'instanceid' => 'removed', 'passwordsalt' => 'removed', 'datadirectory' => '/var/www/owncloud/data', 'dbtype' => 'mysql', 'version' => '6.0.0.16', 'dbname' => 'dropbox', 'dbhost' => 'localhost', 'dbtableprefix' => 'removed', 'dbuser' => 'removed', 'dbpassword' => 'removed', 'installed' => true, 'theme' => '', 'maintenance' => false, );
no external storage used.
Log files do not show error messages or warnings that seem related.
Client configuration
Both MacosX and Ubuntu 13.10 running current owncloud versions are affected. Browser was not used.
Why I think this is an issue
I regularly sync folders with several thousands of files. I think I am not the only one.
What I think is the reason
I am guessing that owncloud does at least one if not several http requests per file sent. It works sequentially, so the next file can only be sent when the last file is acknowledged. Therefore while preparing the request takes no time and effort, and storing the file does not either, the network delay comes into play: For each file to be sent you have to wait at least one if not several round-trip times.
Another indication is that syncing the folder on the local network or between two VMs on the same machine is much faster. This emphasizes the network delay being of importance in this scenario.
How I think it could be circumvented
Sync not file-by-file but instead several files per request, at least if the files are small.
Or, sync with multiple threads and split the work. Much more easy. Only one thread search for the files to sync, splits the list of files to be uploaded, and starts the threads.
@dragotin did you guys have plans looking into uploading multiple files through the same connection ?
Just had a try locally, using "localhost" and the sync client is able to upload many files within a second:

I can imagine that each connection might take more time over the internet, also if it includes name resolution.
Have you tried directly with the IP address to rule out the name resolution case ?
I used the IP directly (or rather a name, but one which is taken from /etc/hosts, not looked up via DNS). I can reproduce your results when uploading locally. Unfortunately fast local performance is academic as the usual case will be a server somewhere on the internet.
It still feels a bit slow, this is about 41 M which I'd expect to be uploaded much faster. The problem also is that it might wait for the server to finish creating/saving/indexing the file before continuing, as the server won't give an answer until that happened.
I tried with the tar file without compression (bunzip2) which is 11Mb big, it took less than a second to upload. I'd almost think that before uploading many files those could be tar'ed together, uploaded then untarred on the server...
Yes I was thinking about something like that when I said "multiple files per request". I think the issue is really delay somehwere on the way. However It seems to be not only the round-trip time. A ping to my server says roundtrip is only 6 miliseconds, so I am wondering where the rest of the time is spent. My accesslog looks like:
<my ip> frickel - [04/Feb/2014:19:20:38 +0100] "PUT /owncloud/remote.php/webdav/owncloudtest/36/42.txt HTTP/1.1" 201 0 "-" "Mozilla/5.0 (Macintosh) csyncoC/0.91.4 neon/0.30.0"
<my ip> frickel - [04/Feb/2014:19:20:40 +0100] "PUT /owncloud/remote.php/webdav/owncloudtest/36/43.txt HTTP/1.1" 201 0 "-" "Mozilla/5.0 (Macintosh) csyncoC/0.91.4 neon/0.30.0"
<my ip> frickel - [04/Feb/2014:19:20:42 +0100] "PUT /owncloud/remote.php/webdav/owncloudtest/36/44.txt HTTP/1.1" 201 0 "-" "Mozilla/5.0 (Macintosh) csyncoC/0.91.4 neon/0.30.0"
<my ip> frickel - [04/Feb/2014:19:20:44 +0100] "PUT /owncloud/remote.php/webdav/owncloudtest/36/45.txt HTTP/1.1" 201 0 "-" "Mozilla/5.0 (Macintosh) csyncoC/0.91.4 neon/0.30.0"
<my ip> frickel - [04/Feb/2014:19:20:46 +0100] "PUT /owncloud/remote.php/webdav/owncloudtest/36/46.txt HTTP/1.1" 201 0 "-" "Mozilla/5.0 (Macintosh) csyncoC/0.91.4 neon/0.30.0"
Load on both client and server are negligible. Still only 1 file in two seconds.
The results are reproducable on a second server (also ubuntu 12.04, but apache instead of lighttpd). Round trip (ping) for the second server is 14ms.
Uploading several files at once might also allow to add several files to the database at once, in case that is the bottleneck.
@PVince81 Are you sure it is several files a second locally? The timestamp in the image you posted are in hours:minutes.
@gluap hmm right. I was actually looking at the progress bar and saw the file name changing 3-4 times within a second and thought the log would reflect that.
@gulap
You might also want to check one of this reported issues: https://github.com/owncloud/mirall/issues/331, https://github.com/owncloud/core/issues/5084, https://github.com/owncloud/core/issues/3118, https://github.com/owncloud/mirall/issues/209 and many more of the same/similar reports.
@RealRancor: thanks for the hint. Apparently my search before creating the issue was not thorough enough. My apologies. I think I am seeing the same problems as #3118 and owncloud/mirall#209 and possibly owncloud/mirall#331. I hope my method of reproducing the issue helps a little. For me this issue is a real dealbreaker.
Dont know if it helps you guys, but theese are my results.
100/10 Mbit/s Server 100/10 Mbit Client.


We are in the same boat (and have filed #6937 ). I have traced the application with New Relic and I see hundreds of SELECTs for every file uploaded - that slows the processing down considerably.
@jcfischer Would it be correct to summarize the current results of #6937 as "The main delay of transferring a small file comes from the fact that a) every file transfer generates a ton of SQL requests and b) files are transferred serially"?
I can't say conclusively yet. Yes, there are a ton of SQL requests which cost time.
Yes, every HTTP request incurs startup cost (I measure 60ms as the baseline for ownCloud - this is the time it takes status.php to load and I assume that this is loading and initializing the complete ownCloud stack.
I don't know if there are more time sinks involved.
Sent from my iPhone
On 05.02.2014, at 10:42, gluap [email protected] wrote:
@jcfischer Would it be correct to summarize the current results of #6937 as "The main delay of transferring a small file comes from the fact that a) every file transfer generates a ton of SQL requests and b) files are transferred serially"?
— Reply to this email directly or view it on GitHub.
I´m using the OwnCloud Sync Tool for windows to sync about 100.000 files. In my activity log I can see, that it takes more and more time for uploading a file as the number of uploaded files increase. The first files took about 2 seconds, now I uploaded 9000 files to 1und1.de and it takes about 17 seconds. The more files there are uploaded, the more time needs a file to upload. Because of small files the internet transfer speed does not play any role. I would say, Owncloud has a very bad database / transaction design. It needs a much better structure / programming for much better performance.
@bantu @DeepDiver1975 @karlitschek @icewind1991 any idea ?
Having worked with a variety of backup transfer products professionally for some years I am afraid to say there appears to be a fundamental problem with the methodology being used for Client syncing.
Without going into the specifics of how OC is working it clearly should not rely on sequential transfer of individual files when 'adding' a new folder and yet it appears to be issuing multiple queries to the server before even considering uploading each file.
Clearly this type of activity should be handled in a batch fashion - perhaps by allowing the client to toggle a setting - or simply warning that the number of 'new' files means it will work in batch mode only until the new folder sync is completed.
As an example, Batch Mode could mean that all files from the 'New Folder' are uploaded to a temporary location on the server, the server resources are then used to 'Scan' the folder and create records for each of the new files, setting timestamps etc and migrating the files to their proper place. At the end of the process Batch Mode is turned off and a consistency check is performed.
After tweaking MySQL settings and cache and so forth I have got to a situation where OC running on Ubuntu 12.04, with 1.5.1 on Windows 7 works well enough to be usable for general day to day updates but if you need to include another folder; do it like this:- Use Filezilla or similar to copy the original files to the correct location on the Server. Change the permissions on the uploaded files to match the rest of the OC files. Add the folder to Owncloud at the Client side. Wait while the Client syncs all the 'New Files' down from the server. [It still takes a while, but hours rather than weeks].
This project has fantastic potential, but the fundamental architecture just doesn't appear to scale, sadly.
@sunny-user I experienced this as well and tracked it down to the oc_jobs table - as the number of jobs increases the cost of adding a new one increases as well, leading to higher web transactional latency and cpu% on the DBMS getting higher and higher.
Turns out the cron job which processes scheduled jobs wasn't running. This made a huge difference right away.
But... I have other problems. Specifically, discovering that sync performance scales linearly with # of directories.
Migrating to ownCloud from Dropbox, and currently feeling the pain of this issue as well :(