Unable to explain mediasoup-worker behavior - unexpectedly low CPU utilization

I’ve been trying to test how my SFU cluster behaves under a specific scenario:

  • 100+ clients connect to the same router
  • 1 Client turns on 1080p video+audio

In my experience, 1 router (1 worker) cannot handle that many clients at once. To deal with this scenario, I added code to poll worker load and move clients onto other workers/nodes if the worker load is above a threshold (90%). However, I find that the worker’s CPU load is seldom above this threshold.

I would assume that the mediasoup-worker would be tirelessly working to try and route packets to as many consumers as it possibly can, but somehow that doesn’t seem to be the case. Instead, all clients are receiving streams at around 2fps with the CPU only occasionally crossing 90% CPU load.

What is the expected behavior when a mediasoup-worker is overburdened with too many clients?

  • Does the sender use simulcast for screen sharing or a single stream?
  • Have you checked sent fps in sender side (via Producer stats)?
  • Does it behave different in receivers if there are just a few of them instead of 100?
  • Does the sender use simulcast for screen sharing or a single stream?

I have two producers (audio+video), but the video is just a single stream with video/vp8 codec.

  • Have you checked sent fps in sender side (via Producer stats)?

I’m not sure how to check this. I got the following from chrome://webrtc-internals. It looks like the sender is only able to send ~5-12fps. I’m not entirely sure why…


Is this what you meant? Let me know if you want me to check and report something on the server-side.

Does it behave different in receivers if there are just a few of them instead of 100?

Yes, when I start 13 clients instead of 100, every client receives 25fps video (same as sender side)

Additionally, each of the servers is a 3CPU machine configured to use 3 workers. The relevant server config is:

  server:
    num_workers: {{ mediasoup_num_workers | default('0') }}
    max_worker_load: {{ mediasoup_max_worker_load | default('0.9') }}
    worker_settings:
      logLevel: warn
      rtcIPv4: true
      rtcIPv6: true
      rtcAnnouncedIPv4:
      rtcAnnouncedIPv6:
      rtcMinPort: 30000
      rtcMaxPort: 49999
    router:
      mediaCodecs:
        - kind: audio
          mimeType: audio/opus
          clockRate: 48000
          channels: 2
        - kind: video
          mimeType: video/VP8
          clockRate: 90000
          parameters:
            x-google-start-bitrate: 1000
    webrtc_transport:
      initialAvailableOutgoingBitrate: 10000000
      maxSctpMessageSize: 262144
      maxIncomingBitrate: 15000000

Indeed you may be reaching the CPU limit for a single worker.

Could you please elaborate?

The issue I’m running into is that, counter-intuitively, the CPU is not being fully utilized. I expected it to be, but that just doesn’t seem to be the case. I can confirm that iotop shows barely any disk/swap usage, so that’s not it. The server is in the cloud, and upload bw is only at 50~80MBps, which is well below the 450MBps I have witnessed when all workers are in use, so it isn’t a network bottleneck either.

Is there any way to determine what the worker is doing? Any way to debug this?

I don’t know, sorry.

From what I understand, you run multiple Chrome clients on one instance. It might be that your client CPU is overloaded. Have you checked it?

I’m confident that’s not the case. As mentioned, when running only ~13 clients (8+5 tabs), all tabs received video at ~25fps

How do you check your CPU usage on the server side?

There’s another comment where I posted code to compute CPU usage on the SFU backend. This load value as well as top report that CPU usage is well below 90% when a worker has 100+ clients to handle, as described in the original post.

I was able to get some data from perf. Keep in mind that this only profiles the CPU as it runs… I’m not sure we’d see non-CPU bottlenecks in report.

  13.14%  mediasoup-worke  mediasoup-worker     [.] AES_encrypt                                                                                                                                                                                                                           
   6.64%  mediasoup-worke  mediasoup-worker     [.] sha1_block_data_order                                                                                                                                                                                                                 
   6.52%  mediasoup-worke  [kernel.kallsyms]    [k] irq_entries_start                                                                                                                                                                                                                     
   4.29%  mediasoup-worke  mediasoup-worker     [.] CRYPTO_ctr128_encrypt                                                                                                                                                                                                                 
   1.77%  mediasoup-worke  mediasoup-worker     [.] std::less<long>::operator()                                                                                                                                                                                                           
   1.66%  mediasoup-worke  mediasoup-worker     [.] RTC::RateCalculator::RemoveOldData                                                                                                                                                                                                    
   0.76%  mediasoup-worke  mediasoup-worker     [.] std::_Rb_tree<unsigned char, std::pair<unsigned char const, RTC::RtpPacket::OneByteExtension*>, std::_Select1st<std::pair<unsigned char const, RTC::RtpPacket::OneByteExtension*> >, std::less<unsigned char>, std::allocator<std::pai
   0.75%  mediasoup-worke  mediasoup-worker     [.] srtp_get_stream                                                                                                                                                                                                                       
   0.65%  mediasoup-worke  [kernel.kallsyms]    [k] do_syscall_64                                                                                                                                                                                                                         
   0.60%  mediasoup-worke  mediasoup-worker     [.] bitvector_left_shift                                                                                                                                                                                                                  
   0.57%  mediasoup-worke  mediasoup-worker     [.] srtp_protect_mki                                                                                                                                                                                                                      
   0.57%  mediasoup-worke  [kernel.kallsyms]    [k] __fget                                                                                                                                                                                                                                
   0.51%  mediasoup-worke  libc-2.31.so         [.] cfree                                                                                                                                                                                                                                 
   0.50%  mediasoup-worke  mediasoup-worker     [.] RTC::RtpStreamSend::StorePacket                                                                                                                                                                                                       
   0.48%  mediasoup-worke  mediasoup-worker     [.] RTC::SimpleConsumer::SendRtpPacket                                                                                                                                                                                                    
   0.47%  mediasoup-worke  libc-2.31.so         [.] malloc                                                                                                                                                                                                                                
   0.47%  mediasoup-worke  libstdc++.so.6.0.28  [.] std::_Rb_tree_insert_and_rebalance                                                                                                                                                                                                    
   0.47%  mediasoup-worke  mediasoup-worker     [.] RTC::SrtpSession::EncryptRtp                                                                                                                                                                                                          
   0.44%  mediasoup-worke  mediasoup-worker     [.] gcm_ghash_4bit                                                                                                                                                                                                                        
   0.44%  mediasoup-worke  [kernel.kallsyms]    [k] entry_SYSCALL_64                                                                                                                                                                                                                      
   0.43%  mediasoup-worke  mediasoup-worker     [.] RTC::resetStorageItem                                                                                                                                                                                                                 
   0.42%  mediasoup-worke  mediasoup-worker     [.] EVP_MD_CTX_copy_ex                                                                                                                                                                                                                    
   0.39%  mediasoup-worke  mediasoup-worker     [.] webrtc::PacketFeedback::PacketFeedback                                                                                                                                                                                                
   0.36%  mediasoup-worke  mediasoup-worker     [.] std::_Rb_tree_header::_M_reset                                                                                                                                                                                                        
   0.36%  mediasoup-worke  [kernel.kallsyms]    [k] memset_erms                                                                                                                                                                                                                           
   0.34%  mediasoup-worke  mediasoup-worker     [.] RTC::Router::OnTransportProducerRtpPacketReceived                                                                                                                                                                                     
   0.34%  mediasoup-worke  mediasoup-worker     [.] std::operator< <unsigned short, unsigned short>                                                                                                                                                                                       
   0.34%  mediasoup-worke  [kernel.kallsyms]    [k] syscall_return_via_sysret                                                                                                                                                                                                             
   0.33%  mediasoup-worke  mediasoup-worker     [.] std::_Rb_tree<long, std::pair<long const, webrtc::PacketFeedback>, std::_Select1st<std::pair<long const, webrtc::PacketFeedback> >, std::less<long>, std::allocator<std::pair<long const, webrtc::PacketFeedback> > >::_S_key         
   0.33%  mediasoup-worke  [kernel.kallsyms]    [k] virtqueue_get_buf_ctx                                                                                                                                                                                                                 
   0.32%  mediasoup-worke  mediasoup-worker     [.] webrtc::PacketResult::PacketResult                                                                                                                                                                                                    
   0.32%  mediasoup-worke  [vdso]               [.] 0x0000000000000794                                                                                                                                                                                                                    
   0.31%  mediasoup-worke  mediasoup-worker     [.] RTC::RateCalculator::Update                                                                                                                                                                                                           
   0.31%  mediasoup-worke  mediasoup-worker     [.] webrtc::rtc_units_impl::UnitBase<webrtc::Timestamp>::DivRoundPositiveToNearest                                                                                                                                                        
   0.30%  mediasoup-worke  [kernel.kallsyms]    [k] udp_sendmsg                                                                                                                                                                                                                           
   0.28%  mediasoup-worke  mediasoup-worker     [.] std::_Rb_tree<unsigned char, std::pair<unsigned char const, RTC::RtpPacket::OneByteExtension*>, std::_Select1st<std::pair<unsigned char const, RTC::RtpPacket::OneByteExtension*> >, std::less<unsigned char>, std::allocator<std::pai
   0.27%  mediasoup-worke  [kernel.kallsyms]    [k] _raw_spin_lock                                                                                                                                                                                                                        
   0.27%  mediasoup-worke  [kernel.kallsyms]    [k] ep_poll_callback                                                                                                                                                                                                                      
   0.27%  mediasoup-worke  libstdc++.so.6.0.28  [.] std::_Rb_tree_rebalance_for_erase                                                                                                                                                                                                     
   0.27%  mediasoup-worke  mediasoup-worker     [.] std::unique_ptr<RTC::Codecs::PayloadDescriptorHandler, std::default_delete<RTC::Codecs::PayloadDescriptorHandler> >::~unique_ptr                                                                                                      
   0.26%  mediasoup-worke  [kernel.kallsyms]    [k] copy_user_generic_unrolled                                                                                                                                                                                                            
   0.26%  mediasoup-worke  mediasoup-worker     [.] webrtc::(anonymous namespace)::LinearFitSlope                                                                                                                                                                                         
   0.25%  mediasoup-worke  [kernel.kallsyms]    [k] apparmor_socket_sendmsg                                                                                                                                                                                                               
   0.25%  mediasoup-worke  mediasoup-worker     [.] std::less<unsigned char>::operator()                                                                                                                                                                                                  
   0.24%  mediasoup-worke  mediasoup-worker     [.] std::equal_to<unsigned char>::operator()                                                                                                                                                                                              
   0.24%  mediasoup-worke  mediasoup-worker     [.] aes_ctr_cipher                                                                                                                                                                                                                        
   0.23%  mediasoup-worke  [kernel.kallsyms]    [k] fib_table_lookup                                                                                                                                                                                                                      
   0.22%  mediasoup-worke  libstdc++.so.6.0.28  [.] std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::empty                                                                                                                                                
   0.22%  mediasoup-worke  mediasoup-worker     [.] std::unique_ptr<RTC::RateCalculator::BufferItem [], std::default_delete<RTC::RateCalculator::BufferItem []> >::operator[]                                                                                                             
   0.21%  mediasoup-worke  libc-2.31.so         [.] 0x000000000009ad05                                                                                                                                                                                                                    
   0.21%  mediasoup-worke  mediasoup-worker     [.] webrtc::SendTimeHistory::RemoveOld                                                                                                                                                                                                    
   0.21%  mediasoup-worke  mediasoup-worker     [.] RTC::TransportTuple::Send                                                                                                                                                                                                             
   0.21%  mediasoup-worke  [kernel.kallsyms]    [k] sock_wfree                                                                                                                                                                                                                            
   0.21%  mediasoup-worke  [kernel.kallsyms]    [k] __ksize                                                                                                                                                                                                                               
   0.21%  mediasoup-worke  mediasoup-worker     [.] uv__udp_check_before_send                                                                                                                                                                                                             
   0.21%  mediasoup-worke  mediasoup-worker     [.] srtp_aes_icm_openssl_set_iv                                                                                                                                                                                                           
   0.21%  mediasoup-worke  mediasoup-worker     [.] RTC::RtpPacket::RtpPacket                                                                                                                                                                                                             
   0.20%  mediasoup-worke  [kernel.kallsyms]    [k] start_xmit                                                                                                                                                                                                                            
   0.20%  mediasoup-worke  libc-2.31.so         [.] 0x000000000018e7a7                                                                                                                                                                                                                    
   0.20%  mediasoup-worke  [kernel.kallsyms]    [k] __wake_up_common                                                                                                                                                                                                                      
   0.19%  mediasoup-worke  [kernel.kallsyms]    [k] __ip_append_data.isra.0                                                                                                                                                                                                               
   0.19%  mediasoup-worke  mediasoup-worker     [.] RTC::Transport::OnConsumerSendRtpPacket                                                                                                                                                                                               
   0.19%  mediasoup-worke  mediasoup-worker     [.] std::_Rb_tree<long, std::pair<long const, webrtc::PacketFeedback>, std::_Select1st<std::pair<long const, webrtc::PacketFeedback> >, std::less<long>, std::allocator<std::pair<long const, webrtc::PacketFeedback> > >::_M_lower_bound 
   0.19%  mediasoup-worke  mediasoup-worker     [.] EVP_CipherInit_ex                                                                                                                                                                                                                     
   0.19%  mediasoup-worke  mediasoup-worker     [.] UdpSocket::Send                                                                                                                                                                                                                       
   0.19%  mediasoup-worke  mediasoup-worker     [.] RTC::IceServer::GetState                                                                                                                                                                                                              
   0.19%  mediasoup-worke  [kernel.kallsyms]    [k] virtqueue_add_outbuf                                                                                                                                                                                                                  
   0.19%  mediasoup-worke  [kernel.kallsyms]    [k] ip_finish_output2                                                                                                                                                                                                                     
   0.19%  mediasoup-worke  [kernel.kallsyms]    [k] __slab_free                                                                                                                                                                                                                           
   0.19%  mediasoup-worke  libc-2.31.so         [.] 0x0000000000099bd9                                                                                                                                                                                                                    
   0.18%  mediasoup-worke  mediasoup-worker     [.] std::unique_ptr<RTC::RateCalculator::BufferItem [], std::default_delete<RTC::RateCalculator::BufferItem []> >::get                                                                                                                    
   0.18%  mediasoup-worke  [kernel.kallsyms]    [k] skb_set_owner_w                                                                                                                                                                                                                       
   0.18%  mediasoup-worke  mediasoup-worker     [.] std::__uniq_ptr_impl<RTC::RateCalculator::BufferItem, std::default_delete<RTC::RateCalculator::BufferItem []> >::_M_ptr    
...                                                                                                           

Does this report look like what one would expect to see? Any idea if I can do anything to increase CPU utilization?

I believe what @footniko has said about your CPU on the client side might be true. I have witnessed this myself when I keep adding tabs each tab creates a decoder for the incoming stream and if the CPU gets overloaded the frame rate drops. So if 13 is a good number I would suggest opening another 13 tabs on a different computer.

Also do have a look at the awesome numbers posted here: Experience with Mediasoup

Could you please elaborate?

server:                  1SFU                       1SFU
client:               8 Tabs (1 VM)         96 Tabs (12 VMs; 8 Tabs/VM)
Producers:         2 (1xVideo 1xAudio)        2 (1xVideo 1xAudio)
FPS (client-side):         25                      5-12 FPS

In both scenarios, every VM has the same 8 tabs. I’m finding it hard to believe that this is a client-side issue…

1 Like

Just to be totally clear. You are running VMs - clients - in a cloud right? You’re not running them on a local machine/ server?

Yes, I am. And in both scenarios, every VM runs 8 Chromium tabs via Puppeteer and xvfb.

edit: Perhaps I’m overloading the term ‘VM’. What I mean to say is, I’m running 12 cloud instances.

1 Like

This is very interesting… No CPU overload, no io there either… If you drop down the number of tabs per host from 8 to 1 does the frame-rate increase??

I have read in the documentation somewhere that 100 is the theoretical limit. if it works fine around 100 then maybe we can cross compare some stats.

If I drop the total number of clients, the framerate increases. I can still maintain 8 tabs/host, but if I set up only 2 hosts (8x2 = 16 tabs), everything works great. All tabs receive 25 fps, which is what the producer is producing at.

I’m sorry. You did say there are 96 tabs. Try switching off the audio and see if things get better. Because if you read this here: https://mediasoup.org/documentation/v3/scalability/#one-to-many-broadcasting

it says that around 200-300 is the limit sort of. Which is not the case from the stats that you’re putting forward.

Although to be clear we have 96 tabs receiving one audio and one video stream so that makes 2 consumers per tab so you actually have 192 consumers.

By switching off audio, we take it down to 96, which is somewhere around 100, does that improve things in the same way scaling down clients does? that’s the question I’m asking.

I understand that those those numbers quoted there obviously depends on the underlying CPU and may vary as a result. I will try what you are suggesting and report back.

That being said, I still don’t understand what the system is doing in this scenario. Clearly the CPU is not overloaded. Neither is memory, nor IO. Putting this together with what’s present in that document makes me think that there is some kind of throttling going on somewhere, possibly on the producer end.

Perhaps it is sending/receiving far too many PLIs/FIRs and that is manifesting itself in terms of reduced CPU load on the SFU server? Is there a way I can detect whether this is what is happening?

1 Like