-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Offline download memory usage #1167
Comments
@danmo, what browser are you using and how are you checking memory consumption? I have run Chrome out of memory before by leaving the JavaScript console open. When the network panel in the console is recording traffic, it will keep every media segment in memory (so the developer can scroll back and examine them). It's an easy mistake to make. |
@joeyparrish I'm using Chrome on Win 7 32bit and using task manager to monitor memory consumption. Dev tools are closed. |
Hi @joeyparrish , this one is a pretty big blocker for us, any advice on how it can be resolved? Reproducing it is easy, for example, you can start downloading a 4k video in the demo app, you'll see the tab memory usage increasing. |
I'm sorry. We do our best, but we can't always triage and fix bugs in only a day or two. We'll get to this as soon as we can. |
Taking a look now |
Here's what I did:
The pre-storage snapshot in my case showed 8.8MB memory in use. The post-storage snapshot showed the same. On disk, the stored content is about 176MB. The in-progress snapshots show increased memory usage during storage. At 10% progress, this was about 26.3MB. At 20% progress, this was about 42.7MB. At 50% it was about 92.9MB. At 90% it was about 147MB. The bulk of this memory is used by the "JSArrayBufferData" type. During storage, we seem to be using a lot of memory. After storage, the memory is freed. So it does not appear to be an actual leak, but we could do better about freeing memory as we commit it to the database. |
@vaage, FYI, since you are working on other storage-related issues. I will try to tackle this for v2.2.x if possible. |
Similar results from the latest nightly build. |
Although this is not a leak, we are temporarily keeping all segment data in memory during the storage operation, which is pretty bad in its own right. It will probably take me a few days to publish a fix, because I need to write a test to go along with it. The test is the hard part by far. The storage system is in the middle of a serious refactor, so a test is extra important right now. We must be careful not to regress after fixing it. In the mean time, you can apply this small change to your own deployment to fix the issue: In this.storedSegments_.push(segment.segmentDb.key);
segment.segmentDb.data = response.data;
return this.storageEngine_.insertSegment(segment.segmentDb);
}.bind(this))
.then(function() {
if (!this.manifest_) {
return Promise.reject(new shaka.util.Error( Add one line to the Promise chain after this.storedSegments_.push(segment.segmentDb.key);
segment.segmentDb.data = response.data;
return this.storageEngine_.insertSegment(segment.segmentDb);
}.bind(this))
.then(function() {
// vvvvvvv
segment.segmentDb.data = null; // <--- ADD THIS
// ^^^^^^^
if (!this.manifest_) {
return Promise.reject(new shaka.util.Error( This will relieve memory pressure during storage, and should unblock your launch. We expect to have a more complete fix out early next week. |
I have been unable to create a regression test for this, so we will publish a fix without one. Here are the things I explored in my attempts to write an automated test in JavaScript:
The fix should be out today or Monday (pending code review internally), and it will be cherry-picked for the v2.2.9 release next week. |
Although DownloadManager clears the segment list as soon as it has started the download Promise chain, the entire list is bound into the each download function. This is subtle and difficult to address directly. Instead, we set the segment data to null explicitly after the segment is stored. In this way, we are sure to only have one segment buffer in memory at a time during a storage operation. Note that there is no regression test to go along with this, because ArrayBuffer memory consumption cannot be directly instrumented from JavaScript, weak references cannot be used to track which buffers are garbage collected, and the buffer references are bound into anonymous functions and therefore cannot be found by exploring object hierarchies. Closes #1167 Backported to v2.2.x Change-Id: Ifeccbfb2d15a1a0243524c92e36512f9308fd5c6
The fix has been cherry-picked for v2.2.9 and is available in the nightly build now: https://nightly-dot-shaka-player-demo.appspot.com/demo/ Please let us know if you have any questions. |
@joeyparrish many thanks, the provided solution has fixed the memory issue! |
Glad to hear it! Please let us know if you need anything else. |
Hi,
I'm using the latest shaka player version and using the Offline storage feature to download and playback content.
My issue is that while downloading memory consumption grows continuously, it seems that shaka is keeping everything in memory. Is there a way to limit memory consumption at a maximum value?
The text was updated successfully, but these errors were encountered: