I have a java app on linux which opens UDP socket and waits for messages.
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.
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. 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 provides the files
/proc/net/udpand/proc/net/udp6, which lists all open UDP sockets (for IPv4 and IPv6, respectively). In both of them, the columnstx_queueandrx_queueshow the outgoing and incoming queues in bytes.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
recvcall immediately returns). You may see therx_queuego up if your application has the socket open but is not invokingrecvto receive the data, or if it is not processing such data fast enough.