Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing downloaded cache takes very long time #5136

Closed
levz opened this issue Nov 22, 2018 · 12 comments
Closed

Removing downloaded cache takes very long time #5136

levz opened this issue Nov 22, 2018 · 12 comments
Assignees
Labels

Comments

@levz
Copy link

levz commented Nov 22, 2018

//Version
2.8.0

//Source code
Not provided - general question

//Description
I use SimpleCache to download HLS donwload streams as desribed in
https://medium.com/google-exoplayer/downloading-streams-6d259eec7f95

And removal of these downloaded cache takes really long time. (Several hours for 1GB of data)
I suppose this is because of SimpleCache saving every chunk to a separate file and so it then takes a lot of time to remove all one by one.

My question is - can I somehow make SimpleCache save the whole thing into one big file?
I have tried creating my own version of CacheDataSink and sending everything to one file, but it seems to break the content index and download throws exception.

Is there some way to do it with SimpleCache or does saving to single file require a new Cache implementation?

@ojw28
Copy link
Contributor

ojw28 commented Nov 28, 2018

Most of the overhead is caused by repeatedly updating the cache index on disk. We should batch up the updates instead, and/or come up with an on-disk representation that's more efficient to update.

@levz
Copy link
Author

levz commented Nov 30, 2018

Here is a workaround, until there is a better solution.

I ended with cloning a couple of classes to create a separate SimpleCache folders for each download.
I created clones of DownloadManager and DownloadService. (Could not override them, since they are final).

In MyDownloadManager I create a new helper with a new SimpleCache folder for each download.
And in task run() method, for remove action I simply remove the whole folder. This works fast since there
is no cache index update involved.

@jandresakis
Copy link

@levz I see the same issue and was hoping not to do what your talking about in your solution. Did you have to copy/refactor most of the SimpleCache and task logic or just pieces?

@levz
Copy link
Author

levz commented Dec 3, 2018

@jandresakis

No, SimpleCache stays the same.

But you will need to clone DownloadManager with changes that will 1) create a new SimpleCache folder for every download 2) delete cache folder (related to the specific download) from disk when necessary.
And you will have to clone DownloadService to make it work with cloned DownloadManager.

@jandresakis
Copy link

@levz thanks for the info. @ojw28 are there currently any plans to do what levs is speaking of? I would like to avoid refactoring/copying and private classes in the exo library if possible to avoid maintaining something that you will provide in the future any way.

@ojw28
Copy link
Contributor

ojw28 commented Dec 3, 2018

We're planning to simply not write the cache index to disk on key removal (because it's not actually necessary to do so). This should happen pretty soon (e.g. before the end of the year).

@jandresakis
Copy link

@ojw28 any updates as to a possible eta for that fix for the slow download removal to find its way into a release?

@ojw28 ojw28 assigned ojw28 and unassigned erdemguven Dec 13, 2018
ojw28 added a commit that referenced this issue Dec 14, 2018
@ojw28
Copy link
Contributor

ojw28 commented Dec 14, 2018

This is fixed in the dev-v2 branch. We don't have an ETA for a release that will include it. We're making some pretty big download changes at the moment, so we'll need to decide whether to package this up in a release that comes before those changes all land, or whether to wait and release everything together.

@levz

This comment has been minimized.

@ojw28

This comment has been minimized.

@ojw28 ojw28 closed this as completed Dec 19, 2018
ojw28 added a commit that referenced this issue Dec 20, 2018
@ojw28
Copy link
Contributor

ojw28 commented Dec 20, 2018

This will be included in 2.9.3. I tested the change above with an HLS download consisting of 1125 segments, and removal time was reduced from ~16 seconds to ~250 ms.

@jandresakis
Copy link

@ojw28 thanks for the early christmas gift ;)

@google google locked and limited conversation to collaborators May 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants