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

查看:19
本文介绍了如何监控 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.

为了调试,我想知道操作系统 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?

附:伙计们,我知道 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天全站免登陆