Networking Forums

Networking Forums > Computer Networking > Linux Networking > Problem with gettimeofday() function

Reply
Thread Tools Display Modes

Problem with gettimeofday() function

 
 
Rajat
Guest
Posts: n/a

 
      10-12-2004, 10:13 AM
Hi All,

I am facing a strang behaviour of gettimeofday() function in the TTCP
application, this application I am using for testing the available
bandwidth of my LAN. The URL to download the source is
http://www.pcausa.com/Utilities/pcattcp.htm.

Its just a simple send and receive application, in which sender will
send some amount of data and receiver will receive, after receiving it
will calculate the time spent while receiving, based on that it will
calculate the data transfer speed in Mbps.

Now if we run the receiver, the in its first 1-2 execution it will
show a time difference in 0.00 Sec(I mean for 2048 calls of recvfrom()
and each packet is of size 8192 bytes in approx 2 microsec). Later it
gives the exact results(approx 1.42 Sec.). It seems like a problem
with gettimeofday() API.

Can any one comment on this????

Though I am attaching a simplify receiver code below,

int main (int argc, char *argv[])
{
int buflen = 65535; //length of buffer
char *buf; //ptr to dynamic buffer
int recvd_buflen = 0; //Length of received buffer.

int eof_flag = 0; //Holds end of transfer flag.

unsigned long io_calls = 0; //Holds number of I/O system calls.

struct timeval start_time; //Time at which timing started
struct timeval end_time; //Time at which timing ended
struct timeval total_time; //Total time elapsed.

double nbytes = 0.0; //Total bytes transfered.
double real_time = 0.0; //Real time in seconds.

if (argc != 2) {
printf("\nUSAGE : speed_measure_recv source_port\n\n");
return 1;
}

//Holds UDP class instance.
ofi_net_udp *udp_recv = new ofi_net_udp();

//Allocate memory for recv packet buffers.
buf = (char*)malloc(buflen*sizeof(char));

printf("Receiver is listening...........\n");

//Initialize receiver for receiving purpose.
udp_recv->initialize_udp_recv("127.0.0.1", atoi(argv[1]));

//Start receiving data.
do {

udp_recv->receive_packet(buf, buflen, &recvd_buflen);
io_calls++;

if(recvd_buflen <= 4) {
if(eof_flag) {
break; //End of transfer.
}

//Set end of transfer flag.
eof_flag = 1;

//Get start time
gettimeofday(&start_time, (struct timezone *)NULL);

} else {
nbytes += recvd_buflen;
}
} while (recvd_buflen > 0);

//Get end time.
gettimeofday(&end_time, (struct timezone *)NULL);

//Get real time in seconds.
tvsub( &total_time, &end_time, &start_time);
real_time = total_time.tv_sec + ((double)total_time.tv_usec) /
1000000;

//Set minimum time.
if(real_time <= 0.0)
real_time = 0.001;

printf("Recvd %0.f bytes in %.2f real seconds\n",nbytes,
real_time);
printf("Total number of I/O calls is %d\n", io_calls);
printf("Hence Speed = %.2f Mbps\n",
(nbytes*8)/(real_time*1000*1000));

//Free packet buffer.
delete(buf);

//Delete udp class instance.
delete(udp_recv);
}



//Function for getting the difference of two timeval structure.
void tvsub(struct timeval *tdiff, struct timeval *t1, struct timeval
*t0)
{

tdiff->tv_sec = t1->tv_sec - t0->tv_sec;
tdiff->tv_usec = t1->tv_usec - t0->tv_usec;
if (tdiff->tv_usec < 0)
tdiff->tv_sec--, tdiff->tv_usec += 1000000;
}
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=
Guest
Posts: n/a

 
      10-12-2004, 10:44 AM
Rajat wrote:
> Hi All,
>
> I am facing a strang behaviour of gettimeofday() function in the TTCP
> application, this application I am using for testing the available
> bandwidth of my LAN. The URL to download the source is
> http://www.pcausa.com/Utilities/pcattcp.htm.
>
> Its just a simple send and receive application, in which sender will
> send some amount of data and receiver will receive, after receiving it
> will calculate the time spent while receiving, based on that it will
> calculate the data transfer speed in Mbps.
>
> Now if we run the receiver, the in its first 1-2 execution it will
> show a time difference in 0.00 Sec(I mean for 2048 calls of recvfrom()
> and each packet is of size 8192 bytes in approx 2 microsec). Later it
> gives the exact results(approx 1.42 Sec.). It seems like a problem
> with gettimeofday() API.
>
> Can any one comment on this????
>
> Though I am attaching a simplify receiver code below,
>
> int main (int argc, char *argv[])
> {
> int buflen = 65535; //length of buffer
> char *buf; //ptr to dynamic buffer
> int recvd_buflen = 0; //Length of received buffer.
>
> int eof_flag = 0; //Holds end of transfer flag.
>
> unsigned long io_calls = 0; //Holds number of I/O system calls.
>
> struct timeval start_time; //Time at which timing started
> struct timeval end_time; //Time at which timing ended
> struct timeval total_time; //Total time elapsed.
>
> double nbytes = 0.0; //Total bytes transfered.
> double real_time = 0.0; //Real time in seconds.
>
> if (argc != 2) {
> printf("\nUSAGE : speed_measure_recv source_port\n\n");
> return 1;
> }
>
> //Holds UDP class instance.
> ofi_net_udp *udp_recv = new ofi_net_udp();
>
> //Allocate memory for recv packet buffers.
> buf = (char*)malloc(buflen*sizeof(char));
>
> printf("Receiver is listening...........\n");
>
> //Initialize receiver for receiving purpose.
> udp_recv->initialize_udp_recv("127.0.0.1", atoi(argv[1]));
>
> //Start receiving data.
> do {
>
> udp_recv->receive_packet(buf, buflen, &recvd_buflen);
> io_calls++;
>
> if(recvd_buflen <= 4) {
> if(eof_flag) {
> break; //End of transfer.
> }
>
> //Set end of transfer flag.
> eof_flag = 1;
>
> //Get start time
> gettimeofday(&start_time, (struct timezone *)NULL);

Why is gettimeofday done here, and not before or somewhere in
(but before a read/recv system call) udp_recv->receive_packet ?
 
Reply With Quote
 
Rajat
Guest
Posts: n/a

 
      10-13-2004, 05:05 AM
"Nils O. Selåsdal" <(E-Mail Removed)> wrote in message news:<%zOad.1563$(E-Mail Removed)>...
> Rajat wrote:
> > Hi All,
> >
> > I am facing a strang behaviour of gettimeofday() function in the TTCP
> > application, this application I am using for testing the available
> > bandwidth of my LAN. The URL to download the source is
> > http://www.pcausa.com/Utilities/pcattcp.htm.
> >
> > Its just a simple send and receive application, in which sender will
> > send some amount of data and receiver will receive, after receiving it
> > will calculate the time spent while receiving, based on that it will
> > calculate the data transfer speed in Mbps.
> >
> > Now if we run the receiver, the in its first 1-2 execution it will
> > show a time difference in 0.00 Sec(I mean for 2048 calls of recvfrom()
> > and each packet is of size 8192 bytes in approx 2 microsec). Later it
> > gives the exact results(approx 1.42 Sec.). It seems like a problem
> > with gettimeofday() API.
> >
> > Can any one comment on this????
> >
> > Though I am attaching a simplify receiver code below,
> >
> > int main (int argc, char *argv[])
> > {
> > int buflen = 65535; //length of buffer
> > char *buf; //ptr to dynamic buffer
> > int recvd_buflen = 0; //Length of received buffer.
> >
> > int eof_flag = 0; //Holds end of transfer flag.
> >
> > unsigned long io_calls = 0; //Holds number of I/O system calls.
> >
> > struct timeval start_time; //Time at which timing started
> > struct timeval end_time; //Time at which timing ended
> > struct timeval total_time; //Total time elapsed.
> >
> > double nbytes = 0.0; //Total bytes transfered.
> > double real_time = 0.0; //Real time in seconds.
> >
> > if (argc != 2) {
> > printf("\nUSAGE : speed_measure_recv source_port\n\n");
> > return 1;
> > }
> >
> > //Holds UDP class instance.
> > ofi_net_udp *udp_recv = new ofi_net_udp();
> >
> > //Allocate memory for recv packet buffers.
> > buf = (char*)malloc(buflen*sizeof(char));
> >
> > printf("Receiver is listening...........\n");
> >
> > //Initialize receiver for receiving purpose.
> > udp_recv->initialize_udp_recv("127.0.0.1", atoi(argv[1]));
> >
> > //Start receiving data.
> > do {
> >
> > udp_recv->receive_packet(buf, buflen, &recvd_buflen);
> > io_calls++;
> >
> > if(recvd_buflen <= 4) {
> > if(eof_flag) {
> > break; //End of transfer.
> > }
> >
> > //Set end of transfer flag.
> > eof_flag = 1;
> >
> > //Get start time
> > gettimeofday(&start_time, (struct timezone *)NULL);

> Why is gettimeofday done here, and not before or somewhere in
> (but before a read/recv system call) udp_recv->receive_packet ?


Actually first recv call is waiting for indication of data transfer,
as if it receives 4 bytes it assumes now the data transfer will begin,
so get the start_time. lly whenever receive next 4 bytes it assumes
data transfer ends.
But I don't think this will make any problem to gettimeofday().
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
router with Fax function Robert Network Routers 1 04-02-2008 09:34 PM
querry regarding the DC function ankit Windows Networking 1 03-11-2006 03:55 AM
Normal function? inkleputDEL@ETEisp.com Windows Networking 0 01-12-2006 05:05 AM
WAN Miniport Function Q lbrty4us@aol.com Wireless Internet 1 02-06-2005 12:01 AM
Ping function adam Windows Networking 3 03-02-2004 04:30 AM



1 2 3 4 5 6 7 8 9 10 11