Over 75% CPU usage and most of the run time is spent in epoll_pwait
#1926 opened on Oct 5, 2020
Description
What version of this package are you using? WebTorrent 0.108.6
What operating system, Node.js, and npm version? OS: Node:12 Docker image Node: v14.12.0 npm: 6.14.8
What happened?
Running the example provided in the "Getting Started" section inside a docker container will cause the CPU usage to jump to around 50%. and if a web server is created for the torrent (torrent.createServer(port)), then the usage increases further to around 75%. this behavior was observed when running the container on multiple machines running Windows and Linux. however, if the same code is run on a windows machine (not inside a container) then no abnormal CPU usage is seen.
I've done a profile using the node profiler inside the container, and it seems that most of the time (around 74%) is spent in epoll_pwait which can be seen here.
with the current behavior, Webtorrent is unusable in Docker on relatively under power devices since it will literally lag the system.
PS: here is the code I've used for testing just in case.
let WebTorrent = require('webtorrent')
let client = new WebTorrent()
let port = 40000;
// Sintel, a free, Creative Commons movie
let torrentId = 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent'
client.add(torrentId, (torrent) => {
let server = torrent.createServer();
server.listen(port);
console.log("ready!")
})