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

100% CPU use for 20+ seconds on startup #903

Open
dcposch opened this issue Sep 6, 2016 · 10 comments
Open

100% CPU use for 20+ seconds on startup #903

dcposch opened this issue Sep 6, 2016 · 10 comments
Milestone

Comments

@dcposch
Copy link
Contributor

@dcposch dcposch commented Sep 6, 2016

  • WebTorrent version: 0.96.4
  • Node / browser version: Electron 1.3.3

Steps to reproduce

  • Use WebTorrent Desktop to create a few torrents from large folders with ~100MB each of test data. Remove all trackers except the webtorrent (wss://) trackers
  • Restart the app

The app becomes unresponsive for ~20+ seconds on startup, while most of the torrent progress bars are stuck at 0%. The whole OS becomes slow to respond. Opening Dev Tools takes ~5+ seconds.

Dev Tools shows that all the resource use is all in the webtorrent process (ie, not in the window or main processes).

Here's the Timeline view:

screen shot 2016-09-05 at 5 34 02 pm

screen shot 2016-09-05 at 5 34 24 pm

### Potential problems - Tons of time spent in `close()` - The top of the flame graph is always 'Timer fired'. Something inside `webtorrent.js` is probably creating zillions of setIntervals or setTimeouts - Two solid seconds spent in a single (?) call to RTCPeerConnection (probably the constructor?)
@feross feross added the bug label Sep 17, 2016
@dcposch dcposch added this to the v1 milestone Sep 20, 2016
@mmckegg

This comment has been minimized.

Copy link

@mmckegg mmckegg commented Oct 9, 2016

Yep, this is exactly what I'm seeing.

@feross I recorded the seed-start progress using devtools and attached the dump here for inspection:

CPU-20161009T155508.cpuprofile.zip

That was seeding 18 torrents all at once. Each file ranges from 5 - 100 MB.

By the way, when torrentClient.tracker.wrtc = false there is barely even a noticeable blip of cpu.

@mmckegg

This comment has been minimized.

Copy link

@mmckegg mmckegg commented Oct 9, 2016

More info:

I'm noticing that even after the initial crazy cpu spike, it stays idling near 40%. When I record timeline/profile, it doesn't actually show anything unusual (very little is happening, virtually idle). But the cpu is still being used by something in that process. Must be another bug in wrtc I suspect 😢

Edit: I have discovered that rolling out the seeds 15 seconds apart one at a time drastically reduces the cpu usage. It never spikes now, and stays "okayish". Any shorter interval than that and the cpu usage would compound.

When I removed all of the trackers (and just left my one in there) the cpu usage reduced even further. This makes me think it's more likely to be something to do with trackers - that is websockets not web rtc. Anyway, the good news is with this workaround ferment is usable again 😄

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Oct 25, 2016

I think the WebRTC crypto required to set up an RTCPeerConnection object is pretty heavy weight. Will think on ways to improve this.

@gpetrov

This comment has been minimized.

Copy link
Contributor

@gpetrov gpetrov commented Nov 16, 2016

@feross Any news on this? We tracked it down to https://github.com/feross/simple-peer/blob/master/index.js#L263 causing high cpu and taking 2-3secs to close the connections... per peer

platform windows 10 as well Mac OSX

@gpetrov

This comment has been minimized.

Copy link
Contributor

@gpetrov gpetrov commented Nov 16, 2016

Just to clarify this issue happens if you have more than 10 torrents running with WebTorrent and connecting to multiple peers with webRTC. CPu usage is high initially when adding the torrents and also on every 10 minites refresh from the trackers. So everything locks up every minutes - very annouying.

We had to switch off wrts just like @mmckegg to have our app running. Without WebRTC everything is a breeze... So not sure if this is a bug in the Chrome code or in Webtorrent as it happens to us at RTCPeerConnection.close

@feross could you please investigate as this renders the "web" part of the webtorrent project completely unusable ... have you ran test cases with more than 10 torrent files?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 18, 2017

@gpetrov Thanks for the sleuthing. I think we need to vastly lower the number of webrtc connections we attempt. We should also file a bug with the various browser vendors. Which browser did you experience the 2-3 second close times in? Also, how did you measure that?

@gpetrov

This comment has been minimized.

Copy link
Contributor

@gpetrov gpetrov commented Jan 18, 2017

@feross we were using the latest chrome from the nwjs project (version 18.6 that is Chrome 54) but due to the high CPU and instability we had to throw away the whole webRTC and are now doing torrents in the isolated node context only. That is running really fine.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 19, 2017

Yeah, this is such a bummer. I wish that webrtc connections weren't so heavyweight in the current webrtc implementations. I'll raise this issue with the chrome team.

@Marak

This comment has been minimized.

Copy link

@Marak Marak commented Jul 31, 2017

@feross

Has there been any activity on this? Any word from the Chrome team, or perhaps local optimizations here in webtorrent project?

We are planning to roll out an application using webtorrent with many users and are concerned about performance.

Appreciate any help you can provide in this matter, thank you. 😃

@MeowTheCat

This comment has been minimized.

Copy link

@MeowTheCat MeowTheCat commented Dec 26, 2018

torrentClient.tracker.wrtc = false
@mmckegg Could you share where you set this? I couldn't find this in webtorrent-desktop. Thank you!

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

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.