Reputation: 2780
I am creating 3 sockets(sender sockets) to send my data to a remote single socket using UDP.
I have bound all these 3 sender sockets on the same single port.
Will this design of binding all the 3 sender sockets on the same port decrease the throughput efficiency of sending packets? Or should I create a new port and a new socket for each of my threads? My goal is send the packets as quickly as possible and keep the network constantly busy.
Important: I am using UDP sockets. Unlike TCP sockets which have a different process created for each of its child threads.
Upvotes: 0
Views: 199
Reputation: 310884
The number of sockets per port is irrelevant. Ports aren't a physical entity and they don't have bandwidths to be divided among their users.
Upvotes: 0
Reputation: 73061
I can't think of any reason why binding multiple sockets to the same port would affect sending efficiency one way or the other. Since your CPU is (presumably) much faster than your network card, your limiting factor is going to be the speed at which your Ethernet hardware can push data onto the network, nothing else.
Of course the only real way to know for sure is to try it both ways and see if you see any differences in throughput; but I would be surprised if you did.
(Note that when sending UDP packets it is important not to try to send them faster than than the network card can transmit them, or the kernel will simply drop the UDP packets it doesn't have room in its send-buffer for. Specifically, you need to either send using blocking I/O (in which case the send() call won't return until the kernel has enough send-buffer space to send the packet you asked it to send), or use non-blocking I/O but only send a packet when the UDP select()'s (or poll()s or whatever) as ready-for-write. Otherwise you will get an amazing fast "send rate" where 99% of your packets were sent only to the bit-bucket ;^))
Upvotes: 1