简体   繁体   English

为什么我的Java UDP套接字未收到所有数据包?

[英]Why my java UDP socket is not receiving all packets?

MyQueue<DatagramPacket> queue;
while(true){
    udpSocket.receive(receivePacket);
    putReceviedPacketToQueue(receivePacket);
}

I have a UDP server which is accepting UDP packets and putting it into my custom implemented Queue like data structure which mainly stored these DatagramPackets. 我有一台UDP服务器,它接受UDP数据包并将其放入我的自定义实现的Queue之类的数据结构中,该数据结构主要存储这些DatagramPackets。 This data structure's insert and remove methods are synchronized. 此数据结构的插入和删除方法是同步的。

There are 100 different threads which process these DatagramPackets. 有100个不同的线程来处理这些DatagramPackets。 They synchronously remove a DatagramPacket from MyQueue and then processes that Datagram packet independently. 他们从MyQueue同步删除DatagramPacket,然后独立处理该Datagram数据包。

So in total, I have 101 threads 1 for receiving UDP Packets and other 100 for processing them. 因此,总共我有101个线程1用于接收UDP数据包,另外100个线程用于处理它们。

My problem is: 我的问题是:

  1. From tcpdump, I can see there are like 2000 UDP packets(50 bytes per packet) has reached the server in a single second. 从tcpdump,我可以看到一秒钟内有2000个UDP数据包(每个数据包50个字节)到达了服务器。
  2. But my udpSocket .receive(receivePacket) is not being able to receive this 2000 packets. 但是我的udpSocket .receive(receivePacket)无法接收这2000个数据包。 Sometimes it receives only like 1500-1600 packets. 有时它只接收1500-1600封包。 But 2000 UDP packets have reached my server's network layer(tcpdump shows that) but my application ie java UDP socket has failed to read them. 但是2000个UDP数据包到达了我服务器的网络层(tcpdump显示),但是我的应用程序(即Java UDP套接字)无法读取它们。

I am testing this AWS server and my server is upgraded enough to handle 2000 UDP packets/second. 我正在测试此AWS服务器,并且我的服务器已升级到足以处理每秒2000个UDP数据包。

I want to know what the problem might be. 我想知道可能是什么问题。 Is my MyQueue insert and delete implement is taking too much time or my 100 processing thread is causing problems or one thread cant receive 2000 packets/second? 我的MyQueue插入和删除工具是否花费了太多时间,或者我的100个处理线程导致了问题,或者一个线程无法接收2000个数据包/秒?

Because UDP is an unreliable transport, but also because if you are going to enqueue DatagramPackets you will need a new one per receive() , otherwise the receive will overwrite the previous one. 由于UDP是不可靠的传输方式,而且还因为如果要入队DatagramPackets ,则每个receive()将需要一个新的,否则,接收将覆盖前一个。 And a new underlying byte[] array. 还有一个新的基础byte[]数组。

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

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