简体   繁体   English

Linux 网络堆栈何时丢弃接收到的 RTP 数据包?

[英]When does the Linux network stack drop received RTP packets?

I am debugging a packet loss issue with my C++ program receiving RTP.我正在调试接收 RTP 的 C++ 程序的丢包问题。 After my program ran for quite a long time receiving lots of RTP data, it starts to loose packets.在我的程序运行很长时间接收大量 RTP 数据后,它开始丢失数据包。

Tracing with Wireshark shows the missing packets, but my application never receives them.使用 Wireshark 进行跟踪显示丢失的数据包,但我的应用程序从未收到它们。 It seems the network stack drops them before delivering them to the application.网络堆栈似乎在将它们交付给应用程序之前丢弃它们。 After restarting my application all goes back to normal.重新启动我的应用程序后,一切都恢复正常。

To produce the error condition, I overload the machine with RTP and at that time packet loss happens and for good reason.为了产生错误条件,我使用 RTP 使机器过载,并且当时发生了数据包丢失并且有充分的理由。 But even after I stop the overload and start sending at a moderate rate, packet loss still occurs and I have to restart my application to receive all data again.但即使在我停止过载并开始以中等速率发送后,数据包丢失仍然发生,我必须重新启动我的应用程序以再次接收所有数据。

Is this an issue with Linux receive buffer handling?这是 Linux 接收缓冲区处理的问题吗? What Linux stats could I check to see where those missing packets go?我可以检查哪些 Linux 统计信息来查看丢失的数据包去哪儿了?

You are not consuming your UDP input fast enough.您使用 UDP 输入的速度不够快。 Here are some usual steps to take to mitigate that:以下是一些通常可以采取的措施来缓解这种情况:

  • Switch to recvmmsg(2) if your kernel supports it to reduce system call overhead,如果您的内核支持它以减少系统调用开销,请切换到recvmmsg(2)
  • Pre-allocate all memory used during input processing,预先分配输入处理期间使用的所有内存,
  • Profile your app, find hot spots and optimize,分析您的应用程序,找到热点并进行优化,
  • Maybe farm processing out to separate threads, but keep lock scope as small as possible,或许可以将处理分摊到单独的线程中,但要保持锁的范围尽可能小,
  • Increase your socket receive buffer ( setsockopt(2) ),增加您的套接字接收缓冲区setsockopt(2) ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM