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. This data structure's insert and remove methods are synchronized.
我有一个UDP服务器,它接受UDP数据包并将其放入我的自定义实现的队列,如主要存储这些DatagramPackets的数据结构。此数据结构的插入和删除方法是同步的。
There are 100 different threads which process these DatagramPackets. They synchronously remove a DatagramPacket from MyQueue and then processes that Datagram packet independently.
有100个不同的线程处理这些DatagramPackets。它们从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:
我的问题是:
- From tcpdump, I can see there are like 2000 UDP packets(50 bytes per packet) has reached the server in a single second.
- But my udpSocket .receive(receivePacket) is not being able to receive this 2000 packets. Sometimes it receives only like 1500-1600 packets. 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.
从tcpdump,我可以看到有2000个UDP数据包(每个数据包50个字节)在一秒钟内到达服务器。
但是我的udpSocket .receive(receivePacket)无法接收这2000个数据包。有时它只收到1500-1600个数据包。但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个数据包/秒?
1 个解决方案
#1
3
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. And a new underlying byte[]
array.
因为UDP是一种不可靠的传输,但也因为如果要将DatagramPackets入队,则每个receive()需要一个新的,否则接收将覆盖前一个。还有一个新的底层byte []数组。
#1
3
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. And a new underlying byte[]
array.
因为UDP是一种不可靠的传输,但也因为如果要将DatagramPackets入队,则每个receive()需要一个新的,否则接收将覆盖前一个。还有一个新的底层byte []数组。