Skip to content

Improving ext storage with streaming #5949

Closed

Description

@PVince81

Currently the performance of external storage is bad because the file must first be downloaded into a temporary file, then fopen() is called on that file and the handle is returned. This means that downloading a 4 GB file from an ext storage will first create a 4 GB temporary file which is then passed to the client as download.

In some cases like downloading, mimetype scanning (if we keep it), antivirus app, etc we are only interested in getting either the first bytes of the stream (fread() then fclose()) or stream the whole file sequentially. No fseek() needed.

In such cases, it might be more efficient to do a fopen() on the stream directly, if possible. It seems that PHP allows fopen() on HTTP URLs. We could just stream the body of the response as it comes into the hooks and back to the client.

I had a quick look and it looks like most external storages could be modified to use streaming, as many of them use HTTP calls anyway.

The alternative to this would be to use a library like CURL that uses threads to pre-download the file into the temporary file. The control could be given back to the caller before the file is finished downloading, so that they can already start working on the start of the temporary file.

Please let me know what you think of this idea.
@icewind1991 @karlitschek @schiesbn @DeepDiver1975 @bantu

List of storages

Activity

  1. PVince81 commented on Nov 19, 2013

    @PVince81
    ContributorAuthor

    @schiesbn the only fseek() call I know so far is the one to detect whether a file is encrypted. As we discussed before, this can be replaced with an approach that simply detects whether keys exist for that file.

  2. PVince81 commented on Nov 19, 2013

    @PVince81
    ContributorAuthor

    Just saw that the webdav.php storage already uses curl, but it still does a full-download of the files.
    It also uses "php://temp" as temporary file instead of \OC_Helper::tmpFile($ext).
    From the doc it seems that "php://temp" is using memory for up to 2 MB.

    And the FTP storage does a fopen() directly on the ftp:// URL.
    Seems to work with http as well (haven't tried https yet)

  3. PVince81 commented on Nov 21, 2013

    @PVince81
    ContributorAuthor
    • Check whether thumbnail creation is using streaming (direct fopen) or temporary files (@georgehrke)
    • Find a way to stream with fopen() into avconv/ffmpeg instead of using a temp file (or raise an issue for that)
  4. modified the milestones: , , on Mar 6, 2014
  5. PVince81 commented on Mar 6, 2014

    @PVince81
    ContributorAuthor

    For OC7 we will try and introduce streaming to WebDAV mounts and SMB mounts.
    If time is left, then try and fix the other ones as well.

  6. bantu commented on Mar 6, 2014

    @bantu

    @PVince81 Doing WebDAV streaming should be not too hard to implement. How do you want to approach SMB/CIFS streaming?

  7. PVince81 commented on Mar 6, 2014

    @PVince81
    ContributorAuthor

    Piping with smbclient. I've already experimented with it and it works, see #4770 (comment)

    But first we need to get @icewind1991 's new SMB impl in: #4770

  8. georgehrke commented on Mar 6, 2014

    @georgehrke
    Contributor

    Find a way to stream with fopen() into avconv/ffmpeg instead of using a temp file (or raise an issue for that)

    We don't create a temp file of the whole file, just for the first 5MB.
    https://github.com/owncloud/core/blob/master/lib/private/preview/movies.php#L47

  9. PVince81 commented on Mar 6, 2014

    @PVince81
    ContributorAuthor

    @georgehrke yes I know, that's why streaming ext storage will improve that as well.
    Currently most ext storage will FIRST download the full file to the temp storage, then call fopen on the temp file and give the stream to you (the preview code)

  10. bantu commented on Mar 6, 2014

    @bantu

    @PVince81 Ah okay, I was expecting a PHP implementation of SMB/CIFS, hehe. :-D

  11. 34 remaining items

  12. modified the milestones: , on Jun 14, 2016
  13. modified the milestones: 10.0.1, 10.0 on Apr 11, 2017
  14. modified the milestones: 10.0.2, 10.0.1 on May 2, 2017
  15. modified the milestones: backlog, 10.0.2 on May 26, 2017
  16. removed their assignment
    on Jun 26, 2017
  17. stale commented on Sep 20, 2021

    @stale

    This issue has been automatically closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions