pldubouilh / live-torrent

Simple proof-of-concept for a live streaming solution based on webtorrent
MIT License
168 stars 39 forks source link

[Question] How does live-torrent create/destroy many torrents at a time and remain responsive? #18

Closed Tryptophan closed 5 years ago

Tryptophan commented 5 years ago

I've been playing around with chunking a stream of video/audio data into many torrents in the browser with WebTorrent, but have run into issues where calling client.seed() and client.remove() many times in the span of a few seconds has caused performance issues. Would sending the binary data to a web worker thread and doing the torrent work there fix this? I've been looking around the code, but I'm still unsure how your solution works.

Tryptophan commented 5 years ago

The fix was actually in specifying an announceList in the client.seed() function, looking something like this:

let announceList = [['wss://tracker.openwebtorrent.com']];
this.client.seed(buffer, { announceList }, (torrent) => {
...
});
pldubouilh commented 5 years ago

alright, so setting just 1 tracker reduces the performance issue ?

Tryptophan commented 5 years ago

That's what I've noticed at least, yes.

pldubouilh commented 5 years ago

It would make sense as it's few connection less, and a few messages less on the WS pipe. How is it performance wise aside from that ? Did you try the "p2p" locally between 2 browsers ? (browser + browser incognito does the job)

Tryptophan commented 5 years ago

The performance on your demo works perfectly, I was just wondering how you got it like that as I was implementing something similar with webtorrent and found using a single tracker like your demo helped.

pldubouilh commented 5 years ago

thanks a lot for the feedback, I'll amend the readme to reflect that behaviour :)