Lots of CPU used to gather webrtc stats
Categories
(Core :: WebRTC, defect, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox155 | --- | fixed |
People
(Reporter: pehrsons, Assigned: ng, NeedInfo)
References
(Depends on 2 open bugs)
Details
Attachments
(1 file, 1 external file)
|
2.49 MB,
text/html
|
Details |
This profile was reported to us on Matrix, captured on a Roland Garros broadcast that uses MSE for the broadcast video.
Somehow we're spending a ton of CPU time copying strings for stats on main thread, while there's not a single webrtc thread running.
There are multiple things we should investigate here:
- should we really gather stats history (for about:webrtc?) when about:webrtc was never opened?
- can we do stats report copying cheaper by not deep copying? (refcounting or moving the objects)
- is there a logic gap in how the peer connections are registered with the stats gathering, keeping them from being released? no webrtc threads in the profile suggests the stats are at best not very interesting.
Comment 1•6 months ago
|
||
Note I removed some processes from the profile (I had many) but I took care to show all threads in all processes that are there. Also the firefox was running from some time already. So it's not impossible webrtc has been started by some other websites earlier? I definitely didn't use about:webrtc though.
I can take more profiles if needed, for example right after restarting Firefox. Though very soon I'll be away for a few days, but I can do it when I come back.
| Assignee | ||
Comment 2•6 months ago
•
|
||
Thanks for the extra context! It would be good to have a full profile if you see it happen again. You could also check about:webrtc to see if there are any PeerConnections listed.
It looks like the WebRTC history gathering thread ran 126 times in the sample period of 12 seconds.
That leads me to believe that there had been at some point up to 3 WebRTC connections. (126 / 12 * 4).
In that same time there were 2734 calls to mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring const&, std::function&&)::$_0::operator()
I am not exactly sure what to make of this stack:
mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0::operator()(nsTArray<mozilla::dom::RTCStatsReportInternal>&&) const [dom/media/webrtc/jsapi/WebrtcGlobalInformation.cpp]
mozilla::MozPromise<nsTArray<mozilla::dom::RTCStatsReportInternal>, mozilla::ipc::ResponseRejectReason, true>::InvokeMethod<mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0, void (mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0::*)(nsTArray<mozilla::dom::RTCStatsReportInternal>&&) const, nsTArray<mozilla::dom::RTCStatsReportInternal> >(mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0*, void (mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0::*)(nsTArray<mozilla::dom::RTCStatsReportInternal>&&) const, nsTArray<mozilla::dom::RTCStatsReportInternal>&&) [xpcom/threads/MozPromise.h]
mozilla::MozPromise<nsTArray<mozilla::dom::RTCStatsReportInternal>, mozilla::ipc::ResponseRejectReason, true>::InvokeCallbackMethod<false, mozilla::MozPromise<nsTArray<mozilla::dom::RTCStatsReportInternal>, mozilla::ipc::ResponseRejectReason, true>, mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0, void (mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0::*)(nsTArray<mozilla::dom::RTCStatsReportInternal>&&) const, nsTArray<mozilla::dom::RTCStatsReportInternal> >(mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0*, void (mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0::*)(nsTArray<mozilla::dom::RTCStatsReportInternal>&&) const, nsTArray<mozilla::dom::RTCStatsReportInternal>&&) [xpcom/threads/MozPromise.h]
mozilla::MozPromise<nsTArray<mozilla::dom::RTCStatsReportInternal>, mozilla::ipc::ResponseRejectReason, true>::ThenValue<mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_0, mozilla::dom::WebrtcGlobalChild::RecvGetStats(nsTSubstring<char16_t> const&, std::function<void (mozilla::Span<mozilla::dom::RTCStatsReportInternal const, (unsigned long)18446744073709551615>)>&&)::$_1>::DoResolveOrRejectInternal(mozilla::MozPromise<nsTArray<mozilla::dom::RTCStatsReportInternal>, mozilla::ipc::ResponseRejectReason, true>::ResolveOrRejectValue&) [xpcom/threads/MozPromise.h]
?--> mozilla::MozPromise<nsTArray<mozilla::net::Http3ConnectionStatsParams>, mozilla::ipc::ResponseRejectReason, true>::ThenValueBase::ResolveOrRejectRunnable::Run() [xpcom/threads/MozPromise.h]
mozilla::RunnableTask::Run() [xpcom/threads/TaskController.cpp]
mozilla::TaskController::RunTask(mozilla::Task*) [xpcom/threads/TaskController.cpp]
mozilla::TaskController::DoExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) [xpcom/threads/TaskController.cpp]
Task MozPromise::ThenValueBase::ResolveOrRejectRunnable <completion promise>
mozilla::TaskController::ExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) [xpcom/threads/TaskController.cpp]
mozilla::TaskController::ProcessPendingMTTask(bool) [xpcom/threads/TaskController.cpp]
mozilla::TaskController::TaskController()::$_0::operator()() const [xpcom/threads/TaskController.cpp]
mozilla::detail::RunnableFunction<mozilla::TaskController::TaskController()::$_0>::Run() [xpcom/threads/nsThreadUtils.h]
nsThread::ProcessNextEvent(bool, bool*) [xpcom/threads/nsThread.cpp]
NS_ProcessNextEvent(nsIThread*, bool) [xpcom/threads/nsThreadUtils.cpp]
mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) [ipc/glue/MessagePump.cpp]
MessageLoop::RunInternal() [ipc/chromium/src/base/message_loop.cc]
MessageLoop::RunHandler() [ipc/chromium/src/base/message_loop.cc]
MessageLoop::Run() [ipc/chromium/src/base/message_loop.cc]
nsBaseAppShell::Run() [widget/nsBaseAppShell.cpp]
nsAppShell::Run() [widget/gtk/nsAppShell.cpp]
XRE_RunAppShell() [toolkit/xre/nsEmbedFunctions.cpp]
mozilla::ipc::MessagePumpForChildProcess::Run(base::MessagePump::Delegate*) [ipc/glue/MessagePump.cpp]
MessageLoop::RunInternal() [ipc/chromium/src/base/message_loop.cc]
MessageLoop::RunHandler() [ipc/chromium/src/base/message_loop.cc]
MessageLoop::Run() [ipc/chromium/src/base/message_loop.cc]
XRE_InitChildProcess(int, char**, XREChildData const*) [toolkit/xre/nsEmbedFunctions.cpp]
mozilla::BootstrapImpl::XRE_InitChildProcess(int, char**, XREChildData const*) [toolkit/xre/Bootstrap.cpp]
XRE_InitChildProcess
main [browser/app/nsBrowserApp.cpp]
__libc_start_call_main [sysdeps/nptl/libc_start_call_main.h]
__libc_start_main_alias_2 [csu/libc-start.c]
_start [firefox-bin]
0x7ffd3193bfb8
(root)
| Assignee | ||
Updated•6 months ago
|
| Assignee | ||
Comment 3•6 months ago
|
||
I believe that padenot mentioned that there was a lot of ICE messages in the logs. That would indicate that there are active WebRTC sessions. It could be that they are outliving their intended life time. The stats history polling should stop once the peerconnection is closed and final stats have been reported. It is possible that a loaded page is calling GetStats() on a 5ms timer.
Comment 5•4 months ago
|
||
Another profile from today in https://share.firefox.dev/4vrHXEF (bug 2053810).
Comment 6•4 months ago
|
||
It's happening only in nightly, right?
I think I don't see the issue when media.aboutwebrtc.hist.enabled is false indeed. But I'll have to double check tomorrow and I'll also think to look at about:webrtc.
| Assignee | ||
Comment 7•3 months ago
|
||
(In reply to Julien Wajsberg [:julienw] from comment #6)
It's happening only in nightly, right?
I think I don't see the issue when media.aboutwebrtc.hist.enabled is false indeed. But I'll have to double check tomorrow and I'll also think to look at about:webrtc.
Thanks, for the updated profile. That is very helpful. If you get a chance it would be good to get an about:webrtc when it is happening. There is a save button at the bottom of the page. I would really like to know how many PeerConnections are reported. Something is definitely happening here, and while we could toggle the stats history pref, I am not sure if this is the symptom or the cause.
| Assignee | ||
Comment 8•3 months ago
•
|
||
(In reply to Andreas Pehrson [:pehrsons] (PTO; back in Aug) from comment #0)
This profile was reported to us on Matrix, captured on a Roland Garros broadcast that uses MSE for the broadcast video.
Somehow we're spending a ton of CPU time copying strings for stats on main thread, while there's not a single webrtc thread running.
There are multiple things we should investigate here:
- should we really gather stats history (for about:webrtc?) when about:webrtc was never opened?
The intent is to have the stats over a window that covers before and after an event that causes one to open about:webrtc. I am open to reconsidering that. It would also be possible to reduce the frequency of the polling. There may be other reasonable limitations that could be enforced if we better understood the nature of the problem.
- can we do stats report copying cheaper by not deep copying? (refcounting or moving the objects)
It is possible that there are spots where we aren't doing refcounting where we could. The primary history entry structures are refcounted. It doesn't look like we should be doing any work though. I would like to know how many unique PeerConnections are generating stats.
- is there a logic gap in how the peer connections are registered with the stats gathering, keeping them from being released? no webrtc threads in
the profile suggests the stats are at best not very interesting.
It is very possible that we are keeping a reference to a peer connection alive when we shouldn't be. The stats history stores PeerConnection IDs (pcids), and does not directly hold on to references to PeerConnections. WebrtcGlobalInformation holds the references. When a PeerConnection is closed, it is supposed to to report its final stats to WebrtcGlobalInformation, and its pcid is unregistered. If the PeerConnection is destroyed, it likewise notifies WebrtcGlobalInformation which, amongst its other duties, unregisters its pcid.
Updated•3 months ago
|
Comment 9•3 months ago
|
||
If you get a chance it would be good to get an about:webrtc when it is happening.
Yeah, I'll look at it next time there's a live chat on this website (it's not always there, it's just for specific sport events).
| Assignee | ||
Comment 10•3 months ago
|
||
There were several spots were we were making unintentional copies of the stats reports as they were added to the stats history.
Updated•3 months ago
|
Updated•3 months ago
|
Comment 11•3 months ago
|
||
Comment 12•3 months ago
|
||
| bugherder | ||
Updated•3 months ago
|
Comment 13•17 days ago
|
||
Hey Nico,
as requested here is a dump of about:webrtc when watching a live video with live chat on france.tv
| Reporter | ||
Comment 14•16 days ago
|
||
(In reply to Julien Wajsberg [:julienw] from comment #13)
Created attachment 9677482 [details]
aboutWebrtc.htmlHey Nico,
as requested here is a dump of about:webrtc when watching a live video with live chat on france.tv
91 peer connections, of which 54 are closed, and about:webrtc polls them all every 250ms. In the profile most work is in IPC paths for strings, of which the stats will have plenty. Especially when we copy the entire sdp history, and mainly static ice candidate stats on every request. I'll try to do something about this in bug 1863805.
| Reporter | ||
Updated•16 days ago
|
Description
•