如何监视Linux UDP缓冲区的可用空间? [英] How to monitor Linux UDP buffer available space?

查看:641
本文介绍了如何监视Linux UDP缓冲区的可用空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux上有一个Java应用程序,它可以打开UDP套接字并等待消息.

I have a java app on linux which opens UDP socket and waits for messages.

几个小时在高负载下出现数据包丢失,即数据包被内核接收,但不是由我的应用程序接收(我们在嗅探器中看到丢失的数据包,在netstat中看到UDP数据包丢失,我们没有在我们的应用日志中查看这些数据包.

After couple of hours under heavy load, there is a packet loss, i.e. the packets are received by kernel but not by my app (we see the lost packets in sniffer, we see UDP packets lost in netstat, we don't see those packets in our app logs).

我们尝试扩大套接字缓冲区,但这无济于事-我们早些时候就开始丢失数据包,仅此而已.

We tried enlarging socket buffers but this didnt help - we started losing packets later then before, but that's it.

对于调试,我想知道在任何给定时刻OS udp缓冲区有多满.谷歌搜索,但没有找到任何东西.你能帮我吗?

For debugging, I want to know how full the OS udp buffer is, at any given moment. Googled, but didn't find anything. Can you help me?

P.S.伙计们,我知道UDP是不可靠的.但是-我的计算机收到所有UDP消息,而我的应用程序无法使用其中的一些消息.我想最大程度地优化我的应用,这就是问题的原因.谢谢.

P.S. Guys, I'm aware that UDP is unreliable. However - my computer receives all UDP messages, while my app is unable to consume some of them. I want to optimize my app to the max, that's the reason for the question. Thanks.

推荐答案

Linux提供了文件/proc/net/udp/proc/net/udp6,其中列出了所有打开的UDP套接字(分别用于IPv4和IPv6).在这两个字段中,列tx_queuerx_queue均以字节为单位显示了传出队列和传入队列.

Linux provides the files /proc/net/udp and /proc/net/udp6, which lists all open UDP sockets (for IPv4 and IPv6, respectively). In both of them, the columns tx_queue and rx_queue show the outgoing and incoming queues in bytes.

如果一切都按预期工作,则通常在这两列中不会看到任何与零不同的值:一旦您的应用程序生成了通过网络发送的数据包,以及这些数据包从网络到达您的应用程序将唤醒并接收它们(recv调用立即返回).如果您的应用程序打开了套接字但没有调用recv来接收数据,或者它没有足够快地处理此类数据,您可能会看到rx_queue上升.

If everything is working as expected, you usually will not see any value different than zero in those two columns: as soon as your application generates packets they are sent through the network, and as soon those packets arrive from the network your application will wake up and receive them (the recv call immediately returns). You may see the rx_queue go up if your application has the socket open but is not invoking recv to receive the data, or if it is not processing such data fast enough.

这篇关于如何监视Linux UDP缓冲区的可用空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆