Click here to Skip to main content
15,924,193 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: String Parsing in C++ (Simple Question) Pin
Chandrasekharan P7-Jul-09 19:27
Chandrasekharan P7-Jul-09 19:27 
GeneralRe: String Parsing in C++ (Simple Question) Pin
N a v a n e e t h7-Jul-09 20:19
N a v a n e e t h7-Jul-09 20:19 
AnswerRe: String Parsing in C++ (Simple Question) Pin
PrafullaVedante7-Jul-09 20:25
PrafullaVedante7-Jul-09 20:25 
AnswerRe: String Parsing in C++ (Simple Question) Pin
chandu0047-Jul-09 20:26
chandu0047-Jul-09 20:26 
AnswerRe: String Parsing in C++ (Simple Question) Pin
CPallini7-Jul-09 21:17
mveCPallini7-Jul-09 21:17 
AnswerRe: String Parsing in C++ (Simple Question) Pin
Stuart Dootson7-Jul-09 21:31
professionalStuart Dootson7-Jul-09 21:31 
QuestionRe: String Parsing in C++ (Simple Question) Pin
David Crow8-Jul-09 2:51
David Crow8-Jul-09 2:51 
QuestionMaximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
clayman877-Jul-09 12:20
clayman877-Jul-09 12:20 
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<1000; ++i )
	{
		long res;
		if( (res=sendto( sock, arr, 1400, 0, (sockaddr*)&targetAddr, sizeof( targetAddr ) )) == SOCKET_ERROR )
		{
			printf("Error: %d\n", WSAGetLastError() );
			return -1;
		}
		sent += res;
	}
	
	printf("\r%d MBs sent", (long)(sent >> 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.
QuestionRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
harold aptroot7-Jul-09 15:28
harold aptroot7-Jul-09 15:28 
AnswerRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? [modified] Pin
clayman877-Jul-09 15:53
clayman877-Jul-09 15:53 
AnswerRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
Adam Roderick J7-Jul-09 18:29
Adam Roderick J7-Jul-09 18:29 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
clayman877-Jul-09 18:48
clayman877-Jul-09 18:48 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
Adam Roderick J7-Jul-09 20:42
Adam Roderick J7-Jul-09 20:42 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
clayman877-Jul-09 21:27
clayman877-Jul-09 21:27 
AnswerRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
killabyte7-Jul-09 19:07
killabyte7-Jul-09 19:07 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
clayman877-Jul-09 19:50
clayman877-Jul-09 19:50 
AnswerRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
David Crow8-Jul-09 2:55
David Crow8-Jul-09 2:55 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
clayman878-Jul-09 4:24
clayman878-Jul-09 4:24 
AnswerRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
Moak4-Aug-09 1:15
Moak4-Aug-09 1:15 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
clayman874-Aug-09 2:27
clayman874-Aug-09 2:27 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
Moak4-Aug-09 5:29
Moak4-Aug-09 5:29 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
clayman874-Aug-09 5:37
clayman874-Aug-09 5:37 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
Moak4-Aug-09 5:46
Moak4-Aug-09 5:46 
GeneralRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
clayman874-Aug-09 6:09
clayman874-Aug-09 6:09 
AnswerRe: Maximum UDP transmit rate is just 50 MB/s and with 100% CPU usage!?? Pin
Jim_Pen24-Feb-10 1:10
Jim_Pen24-Feb-10 1:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.