UDP packet drops by linux kernel

人走茶凉 提交于 2019-11-30 15:32:33

Tracking down network drops on Linux can be a bit difficult as there are many components where packet drops can happen. They can occur at the hardware level, in the network device subsystem, or in the protocol layers.

I wrote a very detailed blog post explaining how to monitor and tune each component. It's a bit hard to summarize as a succinct answer here since there are so many different components that need to be monitored and tuned.

Aside from obvious removal of everything non-essential from the socket read loop:

  • Increase socket receive buffer with setsockopt(2),
  • Use recvmmsg(2), if your kernel supports it, to reduce number of system calls and kernel-userland copies,
  • Consider non-blocking approach with edge-triggered epoll(7),
  • See if you really need threads here, locking/synchronization is very expensive.

"On the client side, one thread reads the socket and put the data into a queue. " I guess the problem is in this thread. It is not receiving messages fast enough. Too much time is spent on something else, for example acquiring mutex when putting data into the queue. Try to optimize operations on the queue, such as use a lock-free queue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!