Closed lucybythec closed 2 years ago
An update: as per #118 we tried to replace wrtc
with node-datachannel
. The above program changes as follows:
const nodeDataChannel = require('node-datachannel')
const client = new WebTorrent({
tracker : {
wrtc : nodeDataChannel
}
})
As a result, the CPU usage is solved, so we can conclude that the problem does not lie with webtorrent-hybrid. However, we have been unable to confirm if the WebRTC functionality is actually working. In fact, we have been unable to confirm that it is working even without this change (using wrtc
). I will file that as a separate issue.
Another update related to the above: the above change doesn't actually work as the two libraries (as expected) have very different APIs. It so happened that all errors caused by an incompatible API, including calls to undefined methods, were silently ignored. To see them, you need to raise the log level. For now we have given up trying to use webtorrent with Node and are evaluating libtorrent (with webtorrent support) instead.
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
Hi there,
We are evaluating using WebTorrent for asset distribution, and ran into the following obstacle. Consider the following example application:
files
is a directory containing about 50 files each under 50 MB.The issue we are seeing is that even when running the above code and doing nothing else, including any attempt to access these files from another client, the node process is using very high CPU usage and does not timely respond to other events (e.g. requests to a HTTP server running in the same process will time out).
I have seen similar reported problems regarding resource usage (https://github.com/webtorrent/webtorrent/issues/1026 and linked issues), however, this problem looks different in that there is no activity other than preparing the files for seeding, with no attempt to actually access them.
Using node
--inspect
and collecting a CPU profile showed that the high CPU usage seems to be the fault of the wrtc module. Here you can see the RTCPeerConnection constructor taking over 3 minutes to run:Examining the node process with gdb revealed the following:
The program creates a very large number of threads (over 1500).
Most of these threads seem to have one of the following two stack traces:
The main node thread seems to spend most of its time in
rtc::Thread::ClearInternal
:Looking at the implementation of
rtc::Thread::ClearInternal
, it does look like it contains some loops which might explain the high CPU usage. However, I can't say if the overall problem is due to a problem in the Google WebRTC library or the wrtc Node module or WebTorrent or somewhere else entirely.What version of this package are you using?
4.0.3
What operating system, Node.js, and npm version?
Ubuntu 18.04.5 LTS, Node v14.13.1, yarn 1.22.10
What happened?
Unexpected high CPU usage and unresponsive application when seeding files with no other activity.
What did you expect to happen?
CPU usage should be reasonable and the application should remain responsive.
Are you willing to submit a pull request to fix this bug?
Possibly (with assistance), but the problem is not yet fully understood.