popcorn-official / popcorn-desktop

Popcorn Time is a multi-platform, free software BitTorrent client that includes an integrated media player ( Windows / Mac / Linux ) A Butter-Project Fork
https://popcorn-time.site
Other
9.45k stars 625 forks source link

Extreme RAM usage and unresponsive #1373

Closed artikweb closed 11 months ago

artikweb commented 4 years ago

Not really sure what kind of updates are being applied to PCT, but the latest version is absolutely unusable. There's an extreme memory leak, the app just gobbles RAM during playback until it crawls to a halt. It seems versions are not being tested before being released, perhaps that's something that can be addressed? I can help with testing and/or debugging.

Operating System Version: Windows 10

Popcorn Time Version: 0.4.4.0 Download date: 18/04/2020

Expected Behaviour

Normal, responsive behaviour

Actual Behaviour

The app is using 5GB of RAM after watching 20 minutes of a movie and becomes completely unresponsive. Pausing takes seconds to actually take place and, at one point, playback just begins to stop altogether.

Steps to reproduce the behaviour

Just watch anything. Tested with Avengers Endgame (1080p) and Star Wars Rise of Skywalker.

Persei08 commented 4 years ago

Check in advanced settings...

What is the value of "Connection Limit" ? Is "Continue seeding torrents after restart app ?" checked ? What is the value of "Maximum number of active torrents" ?

Thx

artikweb commented 4 years ago

Here you go: image Let me know if you need anything else :)

KingOrdinaryCitizen commented 4 years ago

Can you try reinstalling? Just watched 40 minutes of the Avengers Endgame in 1080p, whilst RAM usage only once spiked above 1GB.

ahmedashed commented 4 years ago

I have almost exactly the same, I tried reinstalling fresh multiple times and I have recorded a 15 minute video showing the escalation of ram usage, please fix it because otherwise it is a very good application

https://www.youtube.com/watch?v=1-gdIca9ycM

Thanks in advance Team

Persei08 commented 4 years ago

@artikweb thx, I was thinking it could be related to keep seeding feature, but your settings show it isn't.

artikweb commented 4 years ago

@Persei08 Is there anything I can provide to help troubleshoot this bug? Logs? Screenshots? Let me know and I'll get them for you.

Persei08 commented 4 years ago

I'm not sure. Run PT from terminal with --remote-debugging-port=9222 arguments.
Connect to localhost:9222 so you will be able to check console logs here for both main and background page process.

Reproduce the issue, check teminal output and both console logs. Share them here (eventually mask your ip, username too)

KingOrdinaryCitizen commented 4 years ago

I managed to get my memory leaking, couldn't manage to reproduce it yesterday.

When the memory leak started to happen, the JSArrayBufferData was expanding exponentially. I took various heap snapshots and this is what I found:

Before the memory leak was happening, the ArrayBuffer was about 12 mb. But when the memory leak happend it expanded to 140 mb in mere seconds: image

Leakage is happening in the Torrent (from the node module WebTorrent), specifically here: Before memory leak: image After/During: image

So I've tried to update the WebTorrent module to the latest version didn't seem to make a difference (they stopped updating their changelog on their GitHub and can't find any references to a memory leak). So I guess it has to be in our implementation of the WebTorrent.

My knowledge with memory leak is quite low, so I'd like to share this hoping someone will realize what's going on.

Persei08 commented 4 years ago

This is out of my knowledges.

team-pct commented 4 years ago

Try reduce Connection Number on settings

Persei08 commented 4 years ago

Similar issues #1299

KingOrdinaryCitizen commented 4 years ago

Did some more digging, found out what's causing it. Atleast I think... image

Each of these InternalNodes/V8IdleRequestCallbacks are created (according to the allocation stack) by webtorrent's torrent.js. In this module there is a update function which looks like this: image

From what I've been able to gather, this is what's leaking memory. These V8IdleRequestCallbacks never get garbage collected and just keep chilling. I'd say webtorrent should've found this by now if the issue was on their side. However since there hasn't been a single mention of a memory leak (that I could find) on PT version or better, I'm starting to believe that it's the implementation of WebTorrent in PopcornTime.

Is there anyone, with more experience dealing with either PopcornTime's webtorrent or with memory leaks that's able to fix this? Kinda a big issue... Or should we take it up to webtorrent, that it might be a problem on their side?

Edit 27th April: As of now I've been able to confirm that's a problem regarding webtorrent. Downgrading (using the package.json) to 0.102.4 solves the memory leak. I'd like to hear from @team-pct what their thought on this issue is? As far as I know, we could even push a temporary fix, which just downgrades webtorrent to 0.102.4 as I haven't been able to find anything broken. If someone else could verify this, that'd be great!

kotenok2000 commented 4 years ago

I will be using 0.3.10-0 with new api patch untill fixed

KingOrdinaryCitizen commented 4 years ago

It's getting on my nerves as well, haven't been able to get it to leak again using the latest patch, but then again, I wasn't able to do that at first either.

I'd (and I think many others) really appreciate a response from @team-pct regarding this issue, as it's really big issue. I've done a lot of research and testing with this and as far as I'm concerned it's still due to the WebTorrent library.

triffid commented 4 years ago

This affects me too - I watch one movie, and popcorn's process has eaten 11GB of ram.

I have to keep killing it to keep the rest of my desktop responsive.

I'm currently on 5eb53fc0ef1, running on Gentoo Linux

kotenok2000 commented 4 years ago

https://ci.popcorntime.app/job/Popcorn-Time-Desktop/424/ memory leaks when i start update seeding

triffid commented 3 years ago

I tried a5025d1 last night for a few hours and I did not encounter this issue - so bug can remain closed for now.

artikweb commented 3 years ago

Can confirm, as of the latest build available (#452) the memory leak is no longer happening. I think it'd be a good idea to release a hotfix asap.

ghost commented 2 years ago

Guys/gals, is it possible to re-open this issue? There are multiple people around the web mentioning how Popcorn Time is nigh unusable while downloading for a huge number of users, myself included.

I'm on Windows 10 21H1 (19043.1949), 8 GB RAM, using the latest stable Popcorn Time release. This bug has never gone away for me.

I made sure to fully uninstall the previous version before the latest upgrade, to make sure any remnants of old modules had been fully wiped. It is a fresh install. I get the same behaviour as other people in this thread. A quick way to make it happen is trying to download two different items at the same time (even without watching, just using the Seed Box).

Thank you for all you're doing for the community. Let me know if you need further testing.

dutchy1001 commented 2 years ago

@GoldenOG I've tried with 3 movie at once to download to see if my ram is building up but there is no movement, it is at a constant rate of 42% (having 16gb ram). If PCT is closed, ram goes down to 39% with only my browser and task manager on.

I'm using a PCT dev build f268afc1 which I think is about 6 days old (at the time of writing) and on windows 10 (21H1 19043.1889) almost same as you. Not sure you can see an error when when using the debug key (F12) and post that out put here so our devs can see if there is anything wrong. So far I don't see the point to re-open this unless your F12 output suggest otherwise.

ghost commented 2 years ago

Cool, I'm linking to a .zip file with a memory heap snapshot of PT in a usable state (for reference), an "allocation timeline" dump of PT's growing memory usage to the point where it's basically unusable, and a memory heap snapshot of PT when it's over 3GB of RAM usage.

I got no interesting errors on the console, aside from a few subtitle errors and a few other here and there, 9 total.

Let me know if this is helpful and / or if further testing / data is needed. Thanks for your help.

https://drive.google.com/file/d/10k5DF7gy-zGzd9SvchxxrZaaK3QAYTgF/

dutchy1001 commented 2 years ago

I've passed on the message so it's up to the devs to see if they can do something with your given info.

dutchy1001 commented 2 years ago

At the moment they cant find any leaks. A known bottle neck is node/chromium that can't run it on more than 1 core. If your CPU has only a few cores then this can cause your laptop to give issue's. I've tried multiple downloads at the same time (4) with an i7 (10700K) and 16gb ram but my system is as stable as it should.

Unless something else causes a(re-creatable) leak they will not spend extra time on this as almost all users are not having this issue. Sorry I can't help you any further on this (I don't do coding myself).

ghost commented 2 years ago

Hey ductchy1001, thanks for your replies. However, a few things need to be addressed here:

A known bottle neck is node/chromium that can't run it on more than 1 core. If your CPU has only a few cores then this can cause your laptop to give issue's.

Thanks, it's an eight-core i7, 8 GB RAM. I checked the basics before coming here and I RTFM, man.

they will not spend extra time on this as almost all users are not having this issue. Sorry I can't help you any further on this (I don't do coding myself).

A quick search on Popcorn Time's subreddit shows quite a few people mentioning the ongoing leaks after the date(s) when this bug was closed. Not only that, I've been sent here by an article mentioning how people were simply having to use Popcorn Time as a glorified downloader and quickly close it and watch stuff on VLC later, because of nigh-unusable systems.

We're trying to help. Pretending the issue doesn't exist (because it's tough as nails, I get it) won't make it disappear. It's a really weird attitude, still surprisingly prevalent in the open source software dev community. I didn't get it 20 years ago, and I still don't.

Thank you for trying, dutchy1001 (no sarcasm here).

kiriles90 commented 11 months ago

Can everyone try the latest build (Nov 13, 2023 - https://github.com/popcorn-official/popcorn-desktop/commit/694050d2d1fc4d03a0b1f5250bddf65c77e05c3d) and later and check if this issue still exists?

merseyV commented 11 months ago

macOS Ventura (M1 Silicon) ...

Impressive: Works for me!

Before patch: 8.7GB file PTapp froze (23% downloaded) 118 peers

Normal-Build

After patch: (100% download) 115 peers

Patched
dutchy1001 commented 11 months ago

It seems I do have a bit more going up then down with the memory use ( it uses a bit more with the use of an external player ), still not what I can say will be an issue. I will try later again as time is not on my side ATM

merseyV commented 11 months ago

@dutchy1001 Can you try the same torrent as me ... when your free (no rush!)

New Torrent 9 26GB

@kiriles90 I still get a significant memory leak with a brand new torrent. Obviously, before the patch, I couldn't have got anywhere near completion with a new torrent of that file size (9.26GB). Leak was absolutely steady: 1.8GB @ 50%, 3.6GB @ 99.5%. Peers went 100+ after 25% and stayed between 140-150 for most of the download. Leak continues after download completes ... I think it would freeze PTapp before the movie finished playing?

Your fix has definitely taken the foot off the accelerator ... but is there something special (with new releases) about the way a "swarm" and it's constituent parts (seeds/peers) operates, that exacerbates the leak (that already exists somewhere in their code)?

I'd like to test the old nwjs (patched) version on my "ancient" MacBook Pro ... but your latest build seems be stuck?

dutchy1001 commented 11 months ago

@merseyV I'm not sure it's the same file but close enough. test 1 At start test 2 - 5% 5% test 3 - 10% 10% test 4 - 15% 15% test 5 - 20% 20% test 6 - 25% 25%

The RAM is going up and down by about 75/100MB but doesn't keep going higher then this (give and take 650mb max) Hope this helps

merseyV commented 11 months ago

@dutchy1001

Thanks! mate. Same as last time we tried? - you don't really have the issue!

My best attempt, so far .... unfortunately it's 0.3.8-5 🤣

0 3 8-5
dutchy1001 commented 11 months ago

Pc's behave when I'm near them 😆 😅 😂 🤣

kiriles90 commented 11 months ago

@merseyV why do you have 150 active peers?? I get my full 500Mbps now in Popcorn Time with the default 55 (never could before top was 300 and in very specific circumstances where it was a few but very fast peers). I think that many active connections especially on a device that experiences this issue do a lot more bad than good, speed-wise as well. Also.. do you have "Protocol Encryption" enabled? That one still remains a big cpu hog (so disabled by default) and its side-effect is the memory leak issue once things start timing out.

merseyV commented 11 months ago

@merseyV why do you have 150 active peers??

Don't know mate! We had this conversation many years ago (you might remember) when I got 200+ (runaway) peers with a Wally "Christmas update/s". That would have included a WebTorrent update that started the rot - I think.

No encryption .. you warned me off that before. On the other thread I did a comparison with different connection settings: (https://github.com/popcorn-official/popcorn-desktop/issues/2776#issuecomment-1773823965) . I think that would reduce the active peers and ameliorate things. High number definitely makes the leak worse ... with a new torrent?

kiriles90 commented 11 months ago

Don't know mate!

So in the Settings you've got Connection Limit: 55 and DHT UDP Requests Limit: 16 (default values) and you get those 150 active peers?

merseyV commented 11 months ago

So in the Settings you've got Connection Limit: 55 and DHT UDP Requests Limit: 16 (default values) and you get those 150 active peers?

That's correct. In the good result above with/without patch, I still ran 115 peers with only 645MB usage. It's always been an issue with fresh torrents (going back to PT.io)?

kiriles90 commented 11 months ago

@merseyV Try Active Torrents: 5, Connection Limit: 55, DHT UDP..: 16 and set the upload limit to something reasonable (1-2 MB/s ?) then test the worst torrent you can think of/found so far.

The runaway peers issue seems to be https://github.com/webtorrent/webtorrent/issues/703 so I wonder if limiting the upload has any effect but like everything with WebTorrent it doesn't seem to affect everyone so I cant test anything, e.g for me it respects the 55 limit, always did as far as I remember, its not a hardkill I get 56-58-59 sometimes but then I see it drop them down to 45-50 almost immediately after. Never got 100... with any torrent no matter how popular. Sometimes I get the full 50-60MB/s (25-30MB/s before latest build) download speed with 25-30 peers.

merseyV commented 11 months ago

..... tea break! :D

kiriles90 commented 11 months ago

If I load the last torrent you linked and let it go (my settings are the ones I suggested above)

Screenshot 2023-11-14 204847

Replicated 3-4 times. Peers never exceeded 60. Running on an almost 8 year old, 4 core/8 thread i7. Everything in PCT still smooth even at this download speed. CPU usage when download speed not at absolute max and is the more usual 45-50MB/s (if the torrent allows it ofc) hovers around 15-25% with the latest build. Before this.. 20-30MB/s was the max I could get before CPU usage exceeded 50% (but more importantly basically 100% at that 1 core the app was running on) at which point everything in PCT lagged, extremely, like.. minutes, and the memory leak issue had a good chance of making its appearance. Sometimes it did, others it didn't. I could also feel the UI begin to lag at about 10-15MB/s and over and yes popular torrents with a big swarm seemed to make the issue worse even at the same speeds as less popular ones.

merseyV commented 11 months ago

lol .. 61.5MB/s is just ridiculous!! You must have downloaded that in about 5 minutes .... I hate you! :P ( joking, of course! :)

kiriles90 commented 11 months ago

@merseyV I think I told you before where I work :D Cant "sell the merchandise" all day and run the worst of the worst :D

Also 300 -> 500mbps upgrade is fairly recent and was basically free but also most pointless internet upgrade I've done tbh, ever, all the way up from a 28kbps modem. 40MB/s is a sip of coffee away from 60MB/s for most downloads... Going up to one or two gig is even more pointless for the near future unless you want it for something very specific or a large number of users, ..and the worst thing, I knew about all this before I did it.. but free upgrade etc like I said. Anyway give it 5-10 years and who knows, then it might/should make a bit more sense.

P.s you should see the almost 3000mbps 5G result I screenshotted on my phone.. but that one I'm fairly sure has also sterilized me. Which is a win-win, not complaining... (was at ~15 meters and at basically eye level with the main 5G antenna for the city 😄 also joking, 5G wont fry your kids, its only interested in your brain!! 🧠🧠🧠)

... 😄

merseyV commented 11 months ago

@kiriles90

Give up!!

hang up the hat

Nothing produced a better result than the 3.6GB on default settings. Active peers got no lower than 64: Last settings on 1_20_2 (1GB up)... that one burned through 9.65GB and froze. I'll see what it does in a day or two (when it settles?).

The patch is still a significant improvement for general downloads. Probably wouldn't have been noticeable in the old PT.io days - the (only) API's were yts.ag and eztv.to (with small file sizes 1 to 3GB). But as I said, even then users had crash/freezes with latest "blockbusters" (resolved itself after 2/3 days!). Still none the wiser?

Wish I'd sold that kidney, now ... and got the 32GB build option. (lol)

dutchy1001 commented 11 months ago

@merseyV you might need to infest in a proper WINDOWS pc 🤣🤣. If you do have one try and see if you get same results, will rule out the issue it gives you

merseyV commented 11 months ago

@merseyV you might need to infest in a proper WINDOWS pc 🤣🤣

To be fair 8GB works for everything .. except Popcorntime (lol). Even Handbrake doesn't make it break a sweat! 16GB would have been the "belt and braces" option - but I can't blame it for WebTorrents eye-watering leaks! (qBittorrent runs very nicely @ 110MB).

kiriles90 commented 11 months ago

@merseyV put them back to 5, 55, 16 and leave them there. They clearly don't do anything significant in your case even when on the extreme end so no reason messing with the connection this way. Use the download/upload speed limit to limit the CPU usage if this keeps being an issue.

Btw, anyone else wants to chip in? I'll leave the issue open for a couple more days but at the moment its solely up to @merseyV if we close this or not since me and @dutchy1001 don't have the issue anymore and none else reported the latest build doesn't alleviate the issue (90% anyway, the runaway peers issue which is what mersey is probably having is once again a WebTorrent open issue with not much we can do about here)

merseyV commented 11 months ago

Last will and Testament (before @kiriles90 kills me!!)

@dutchy1001 Looking at your results, again .. your upload/download speed and active peers are noticeable different from my stats. Your max bandwidth speed is not a million miles from mine (from a previous conversation). At 20/25% your peers are 12/11 and down/up speed almost the same (roughly) 1.8MB/s both ways! Are you running custom settings (or default?). Nothing like my results at that % downloaded?

Out of curiosity: Tried the last WebTorrent (desktop) app - been dormant for about 3 years now (for obvious reasons!) ...

WebTorrent  0 24 0

@kiriles90 eat your heart out! ... 126MB/s!!! ... I wish :DD

Back to the real world:

+ 1 9 7 patch

Swarm appears to have settled down a bit: now 2.2GB (previous 3.6GB). Should reach a "normal" state when the torrent matures. Notice the 'active peer' count (209) ... and it didn't fall over? Your fix (obviously) kept things under some control - even my runaway peers!!

Closed, I'd say: As we can't do 2.x.x without tearing down the house - it's as good as it gets, for Mac.

( hopefully kiriles90 doesn't find out I got my popcorntimes' muddled ... too many versions!! ;)

dutchy1001 commented 11 months ago

Only thing I have set differant (as far as I know) is the upload to 2kb/s Screenshot 2023-11-15 155511 We have a 350mbps connection with the junction box less then 20 meters from my house. Average dl speed using other means are around the 38MB to 42MB (depending on other users in the house)

merseyV commented 11 months ago

Only thing I have set differant (as far as I know) is the upload to 2kb/s

lol ... your pic blurred slightly when I expanded it (thought KB/s was MB/s). makes sense now!

Thanks! for clarifying that.

kiriles90 commented 11 months ago

@merseyV well 2GB is almost(!!) the normal/no-leak 500MB? Beats the 12GB usage of WebTorrent desktop? :D

@dutchy1001 try the latest build once it finishes building if you want, it has some Favorites and Watched fixes which should help with most if not all the database corruption issues that we were talking about. Let me know what you think!

dutchy1001 commented 11 months ago

DL/installing as I type this, will let you know how it goes.

kiriles90 commented 11 months ago

Ok, I think we can close this now/for now. If it creeps up with any of the new builds we can always re-open it.