sharkone / BitTorrent.bundle

BitTorrent channel for Plex Media Server
144 stars 52 forks source link

scrapmagnet it`s always keeping my cpu at 7% or higher when idle #81

Open ghost opened 7 years ago

ghost commented 7 years ago

31698 plex 20 0 910M 85268 12840 S 7.9 2.8 0:20.67 /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/BitTorrent.bundle/Contents/Bin/linux_amd64/scrapmagnet --ppid 2510 --port 8042 --inactivity-pause-timeout 10 --inactivity-remove-timeout 20 --mixpanel-token 63b4a20135a998db7eef5bbca5743df6 --mixpanel-data eyJDaGFubmVsIFZlcnNpb38i

cpatulea commented 6 years ago

Some more information:

$ ls -l "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/BitTorrent.bundle/Contents/Bin/linux_amd64/scrapmagnet" -rwxr-xr-x 1 plex plex 24,432,949 Dec 30 23:51 /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/BitTorrent.bundle/Contents/Bin/linux_amd64/scrapmagnet $ "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/BitTorrent.bundle/Contents/Bin/linux_amd64/scrapmagnet" --version

command line: /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/BitTorrent.bundle/Contents/Bin/linux_amd64/scrapmagnet --ppid 27279 --port 8042 --inactivity-pause-timeout 10 --inactivity-remove-timeout 20 --mixpanel-token 63b4a20135a998db7eef5bbca5743df6 --mixpanel-data eyJDaGFubmVsIFZlcnNpb24iOiAiMS4xLjEifQ==

parent pid is running: plex 27279 2.1 0.8 950072 33308 ? Sl 00:02 0:01 _ Plex Plug-in [com.plexapp.plugins.bittorrent] /usr/lib/plexmediaserver/Resources/Plug-ins-f54242b6b/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py --server-version 1.10.1.4602-f54242b6b /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/BitTorrent.bundle

during this time, strace shows scrapmagnet calls epoll_wait very fast:

$ sudo strace -tt -f -p 27318 2>&1 | head -n 40 Process 27318 attached with 9 threads ... [pid 27318] 00:02:58.374187 epoll_wait(6, <unfinished ...> [pid 27326] 00:02:58.374224 futex(0x11e5fa4, FUTEX_WAIT_PRIVATE, 8, NULL <unfinished ...> [pid 27318] 00:02:58.375461 <... epoll_wait resumed> {}, 1024, 1) = 0 [pid 27318] 00:02:58.375676 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.375954 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.377343 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.377629 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.379123 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.379261 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.380641 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.380914 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.382267 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.382394 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.383732 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.383957 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.385326 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.385466 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.386870 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.387172 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.388587 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.388871 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.390327 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.390626 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.391989 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.392219 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.393535 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.393742 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.395105 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.395271 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.396613 kill(27279, SIG_0) = 0 [pid 27318] 00:02:58.396856 epoll_wait(6, {}, 1024, 1) = 0 [pid 27318] 00:02:58.398175 kill(27279, SIG_0) = 0

with a timeout of 1 millisecond (last argument): int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);

this causes scrapmagnet to consume ~3.6% CPU on my machine when idle (no downloads), which seems too much: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 27318 plex 20 0 934304 79180 8808 S 3.6 2.0 0:09.12 scrapmagnet

cpatulea commented 6 years ago

Probably due to this code: https://github.com/sharkone/scrapmagnet.js/blob/master/scrapmagnet.js#L348

where setInterval defaults to 1 millisecond: https://nodejs.org/api/timers.html#timers_setinterval_callback_delay_args