mafintosh / torrent-stream

The low level streaming torrent engine that peerflix uses
MIT License
1.94k stars 228 forks source link

[REGRESSION] Speed falling, small number of peers #106

Closed thermatk closed 9 years ago

thermatk commented 9 years ago

Somewhere between 0.12 and 0.13.1 happened a change that affected torrent-stream forever. Since the 0.13 release speed dramatically fell, peers are not discovered in quantities enough to download as fast as torrent-stream did before. I have a very simple test for it - I build peerflix 0.29.1 as is and compare it with the same peerflix using torrent-stream 0.12. I tried to get the exact commit that caused it, but the fact is that between https://github.com/mafintosh/torrent-stream/commit/7666f34aebb94645bbaf44feba0c078508dbdf7d and https://github.com/mafintosh/torrent-stream/commit/078b812cf300bfc01f454020daa19d9caf5e8ae3 peerflix doesn't work at all(before - great speed, after - works but slowly). Affects on Linux and Windows, shouldn't be platform-specific. What can we do? :)

asapach commented 9 years ago

I've been using 0.13 for several months now and I didn't notice any dramatic difference. Can you back it up by some concrete numbers? Back-to-back comparison?

thermatk commented 9 years ago

peerflix with 0.12.0 - finds first peer immediately and has already 20 MB after 10 seconds same peerflix with 0.13.5 - finds first peer on 8s and on 10s has 3 MB with this magnet: magnet:?xt=urn:btih:46d43b8d4279825232500eb9147eb9c5d0d1aa03&tr=http%3A%2F%2Fbt.unionpeer.org%3A777%2Fannounce&tr=http%3A%2F%2Fretracker.local%2Fannounce&tr=http%3A%2F%2Fbt.rutor.org%3A2710%2Fannounce&tr=http%3A%2F%2Fpubt.net%3A2710%2Fannounce&tr=http%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.prq.to%3A80%2Fannounce&tr=http%3A%2F%2Ftracker.prq.to%2Fannounce

That's a bad example as both are usable but while using newer peerflix in general there are situations where it never finds peers(and old peerflix finds 100 if I try it) or the speed is not comparable(100kb/s vs 3 mb/s). It affects all projects using torrent-stream as well, for example Popcorn Time slowed down a lot since update.

One more thing: experiments showed that new version has some kind of bias connected with country and number of peers. I have opened the same torrent in new peerflix from my internet connection and after some minutes of waiting through a VPN and it got a lot of peers and speed if used through a VPN. Old peerflix(torrent-stream) has high speed in both cases without significant variations

I'll try to test more magnet links to find an edge example.

thermatk commented 9 years ago

It's more visible with torrents that don't have thousands of peers, somehow torrent-stream blocks or ignors a lot of them, so if there aren't many it becomes slow or even unusable at 0 kb/s

thermatk commented 9 years ago

So A random IT Crowd magnet: magnet:?xt=urn:btih:99d25bb98b1931001f7f5bc560be717f653bd551&dn=The.IT.Crowd.Season.2&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969 You can see that new torrent-stream downloaded only a half of what the old did and actually the old found the same three peers immediately and the new one was searching for 17s 2015-03-29 18 06 36 2015-03-29 18 06 46 2015-03-29 18 07 26 2015-03-29 18 07 46

thermatk commented 9 years ago

Update: I am completely misunderstanding how it works, may be there are two problems at once. But After 0.13.0 speed of finding peers initially is lower but once they are found everything is alright, after 0.14.0 it's a disaster 0.12.0 best one 0.13.0-0.14.0 - slow 0.14.1 and afterwards - even worse

thermatk commented 9 years ago

peerflix 0.22 with torrent-stream 0.18.0 with very old bittorrent-dht 1.5.0 is working great! Found the cause!

thermatk commented 9 years ago

bittorrent-dht 3.0.0 is not affected Hooray!

thermatk commented 9 years ago

I've sent a pull-request. But looking at the repo there might be some API breakage, please look into it, I don't understand how the whole thing works that deep :) https://github.com/feross/bittorrent-dht/commit/920dee18759118257700bbc30c3944a9446097fe