المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!??



C++ Programming
07-08-2009, 02:30 AM
Hi!

I've been experimenting with custom flow control techniques for bulk transfers over UDP when I discovered something very weird. Please take a look at the following code: it just sends UDP datagrams of size 1400 bytes in an endless loop to some IP address.


SOCKET sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );

sockaddr_in targetAddr;
targetAddr.sin_addr.s_addr = inet_addr( "...some IP..." );
targetAddr.sin_family = AF_INET;
targetAddr.sin_port = htons( 1337 );

char arr[1400];
long long sent = 0;
while( !kbhit() )
{
for( int i=0; i> 20) );
}



When I run the program, every sendto() call succeeds and reports having sent 1400 bytes of data. The interesting thing is that I get a transfer rate of just about 50 MB/s but 100% CPU usage on one core (mostly kernel-mode). Now:

-- my computer is connected to an Ethernet 100BaseTX network, which obviously does not support the transfer rate above, so datagrams get already lost before even reaching the network. Why does sendto() then reports having sent the data, what is more, why does it not block when I/O buffers fills up? (The documentation says that it should.)

-- how on Earth can someone utilize the full potential of a - say - Gigabit Ethernet network if just sending data even at half of its capacity already causes maximum CPU load?

So, what am I doing wrong, why on Earth does sendto() takes so long?

Any suggestion is very welcome, thanks,
clayman

P.S.: I've run a test with 140 bytes of data each time, and the transfer rate basically dropped to 5 MB/s -- so the _number_ of sendto() calls seems to be the bottle-neck.