Repository navigation
Description
Steps to reproduce
- Have a big file (mine is 6.8GB) on an SMB share mounted to oC
- Having a (important!) fast connection between server and client (LAN)
- Download this file via browser
Expected behaviour
Download should pass without problems
Actual behaviour
Download stops after a while (3-4GB downloaded), system becomes unresponsive, after some minutes, system is accessible again.
This does not occur when
- downloading small/smaller files via SMB
- downloading from local, means same file is not on SMB but in the users oC home. In my environment the datadirectory is on NFS
- downloading via a slow connection =eg internet, only a view mbit/s
Testing
Monitoring the system via htop under different scenarious
On fast/SMB, memory and swap gets eaten up, not from the beginning but after a while until system becomes unresponsive, download gets broken and recovers after a while beeing responsive againg and memory is recovered. Memory recovery also takes place if the file downloaded finishes earlier than memory becomes eaten up. This is monitorable.
libsmbclient installed in the latest public version (sudo pecl upgrade smbclient)
Network performance = browser (client) side, the SMB backend delivering the data is fast (55-60MB/s)
Slow Network, SMB: 3.2mbit/s (manually stopped after 510 MB = ~26min, no issues)

Fast Network, SMB 114mbit/s (memory starts raising from 345 to +603MB)
Memory raising appears between 1.2 and 3.7GB downloaded, mostly on higher numbers

Fast Network, SMB 114mbit/s (memory continues raising from 603 to +980MB)
Memory consumption continues

Pause or stop download at 980MB, waiting a minute
Memory gets freed up

Fast Network, Local (which is on an NFS mountpoint 200mbit/s (memory stays at ~380)

Server configuration
Operating system: ubuntu 16.04
Web server: nginx 1.13.6 (currently latest)
Database: mysql
PHP version: 7.0
ownCloud version: 10.0.3 production
Updated from an older ownCloud or fresh install: updated
Where did you install ownCloud from: tar
Signing status (ownCloud 9.0 and above):
No errors have been found.
The content of config/config.php:
config_report_20171023.txt
List of activated apps:
Enabled:
- activity: 2.3.6
- comments: 0.3.0
- configreport: 0.1.1
- dav: 0.3.0
- federatedfilesharing: 0.3.1
- federation: 0.1.0
- files: 1.5.1
- files_clipboard: 0.6.2
- files_external: 0.7.1
- files_external_dropbox: 1.0.0
- files_external_ftp: 0.2.0
- files_pdfviewer: 0.8.2
- files_sharing: 0.10.1
- files_texteditor: 2.2.1
- files_trashbin: 0.9.1
- files_versions: 1.3.0
- files_videoplayer: 0.9.8
- firstrunwizard: 1.1
- gallery: 16.0.2
- market: 0.2.2
- music: 0.5.3
- notifications: 0.3.1
- provisioning_api: 0.5.0
- systemtags: 0.3.0
- templateeditor: 0.1
- updatenotification: 0.2.1
Disabled:
- encryption
- external
- files_antivirus
- theme-example
- user_external
Are you using external storage, if yes which one: local / smb / sftp /
Are you using encryption: no
Are you using an external user-backend, if yes which one: no
Client configuration
Browser: Opera, Chrome, same behaviour
Operating system: W10x64
Logs
Web server error log
nothing related
ownCloud log (data/owncloud.log)
nothing related, because I paused/stopped it. Else upstream timeout for php-fpm if I let it crash
Browser log
nothing related
Activity
jvillafanez commentedon Oct 23, 2017
Is libsmbclient-php installed and used?
mmattel commentedon Oct 23, 2017
yes, as written above
hodyroff commentedon Oct 23, 2017
More RAM solves the issue, or?
mmattel commentedon Oct 23, 2017
More memory just delays the time to crash and is not the solution.
Low(er) memory systems for smaller environments suffer therefore most of it.
These issues are necessary to be fixed with low mem systems so we do not run into issues with higher mem systems which are then much harder to investigate.
I have 1.2GB of memory and the system fails to download a 6.8GB file ??
Thinking about big backup or multimedia files ?
mmattel commentedon Oct 23, 2017
mmattel commentedon Oct 23, 2017
phpini()mmattel commentedon Oct 23, 2017
@kdslkdsaldsal refering #29328 (comment)
even it has no impact to this case, pls adopt the documentation to reflect your statement.
jvillafanez commentedon Oct 24, 2017
@mmattel could you check running the following script from you nginx server? Adjust the parameters (workgroup, username, password and smbfile) in order to download your file.
I haven't seen any possible memory leak in our code, so it might be in the libsmbclient-php or lower libraries (libsmbclient), or maybe nginx could be buferring the whole response.
The above script is quite simple and should help to determine where the problem might be:
You can also check with apache. Last time I checked (with apache) in a VM with 2-3 GB of memory fetching a file of around 5 GB I didn't experience any issue. PHP memory limitations were the default (512 MB). This was between 2 different VM on the same host, although I didn't remember if I put some network constraint to test another issue.
I'll recheck anyway.
mmattel commentedon Oct 24, 2017
(Edited)
I tested as suggested, following results / comments:
Copying a file from SMB to a local mount which is on NFS with 6.8 GB went fine.
Memory consumtion was low and did not change. This means that there is no problem with libsmbclient-php or lower libraries without going thru the webserver
I have no coding experience in that and need help.
The chunk result is continiously written with fwrite. When writing to the browser we use in our code readfile which sends from my understanding from a source. The question is, where is the data buffered?
I reference https://zinoui.com/blog/download-large-files-with-php (chunked download) which uses echo and not readfile which is clear to me but not in how it seems we do it which looks to me as two seperate processes - or?
My phi.ini has
output_buffering = offand nginx is also configured withfastcgi_request_buffering off9 remaining items
mmattel commentedon Oct 25, 2017
@kdslkdsaldsal
I ran all tests not via cli but from the browser ! - forgot to mention...
@jvillafanez
I ran the test with the code adopted, it passes as fine, no memory issues. Which what I expected !
But the difference looking into your statement is, that oC uses - as far I can identify it -
readfileto pass the data to the browser while this tests useechoorfwriteinside a while block.jvillafanez commentedon Oct 26, 2017
Yes, all the tests should be done through nginx because the problem is there.
I don't think that's the case since all the file access should be done through the webdav interface, so downloads should be controlled by the webdav module, which is using
stream_copy_to_streamfunction (or it should).The reason we aren't using that function is because we need an open stream to read the data from, which is more difficult to get without using ownCloud's code.
You might want to check what happens if you add the following line in the apps/dav/lib/Connector/Sabre/FilesPlugin.php file (with the nginx buffering active):
That should disable the buffering for the file downloads
mmattel commentedon Oct 26, 2017
Just ran the test by commenting out
fastcgi_buffering(defaults now toon)and adding the
addHeader('X-Accel-Buffering', 'no')statement as suggested.I also tried it with:
addHeader('X-Accel-Buffering: no');Memory consumption raises again.
Personal opinion
This is a very good approach, but maybe it was the wrong or not the only place to be added ...
Maybe not all have the ability to change the nginx config because of hosting...
Thinking about the following situation:
Could that also become an issue on federated systems when loading multi GB files from one fed to the other in environments as described in the issue here??
jvillafanez commentedon Oct 31, 2017
I can confirm the problem with a similar configuration as the one proposed by ownCloud before removing the nginx buffering (data from "top")
nginx memory consumption keeps increasing (php-fpm7.0 is stable)
Adding the line said in #29328 (comment) seems to do the trick for me, keeping the nginx's memory usage low (0.2 comparing with the data above - php-fpm7.0 keeps a similar value of 2.2)
I'm using the following configuration (based on what it is in the documentation):
for the server configuration:
nginx configuration is the default provided by ubuntu (mail section is commented, so it's ignored here):
jvillafanez commentedon Oct 31, 2017
@mmattel you might want to recheck the custom header solution (#29400). If that doesn't work, you might want to post your nginx configuration so we can check what setup is the problematic one.
mmattel commentedon Oct 31, 2017
Retried - works 👍
It seems that I have put the code in my test before into the wrong line...
mmattel commentedon Oct 31, 2017
I have created an nginx ticket: https://trac.nginx.org/nginx/ticket/1408
mmattel commentedon Nov 2, 2017
Update from nginx ticket:
And
Because we have in our documentation
fastcgi_buffers 64 4K;as parameter set, I will do a doc PR asap to correct this (reducing to 8 4K respectively adding a note not to exeed 63).@jvillafanez we can add in the doc also the nginx conf parameter
fastcgi_ignore_headers “X-Accel-Buffering”which would reenable buffering when set properly. If the admin can not set it, we are fine because of your PR to disable buffering in the header...jvillafanez commentedon Nov 6, 2017
Makes sense 👍
lock commentedon Jul 30, 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.