kasperhj
kasperhj

Reputation: 10482

Handling UDP packets in a queue or on every received packet

I have a UDP "server" that receives UDP packets and handles them.

The way I have implemented it now, I raise an event whenever I receive a packet, and handling each packet on some threadpool thread. The handling is fairly simple, and I suspect it is much faster than the rate of packets coming in.

I now have another application in which the rate of packets can be higher, and I was wondering whether it would be better in general to have a queue of packets, and handle the packets in a more bulk sort of way, instead of raising the event on every receive.

Do you have any thoughts on this matter?

Upvotes: 2

Views: 1682

Answers (1)

Tayyab
Tayyab

Reputation: 10651

Well if you are expecting lot of packets then it might not be a very good option to handle each packet in a new thread. You can make a Producer/Consumer system. Your UDP packet receive module will be producer which will produce the packets (push in some sort of queue) and then you can have a consumer which reads the packet and process it. This will be faster and more scalable option and you can run more than one consumer threads for processing the packets.

It is always better to handle packets in bulk sort of way if you can.

Upvotes: 1

Related Questions