Page 1 of 1

Time measure UDP socket Raspi<--->PC

Posted: Wed Apr 06, 2016 10:34 am
by ampu
I´m trying to obtain the performance in a Client (PC i7 3.4 GHz Kubuntu 15.04) - Server (RaspberryPi 700 Mhz Raspbian Jessie) architecture with sockets, measuring the spent time sending and receiving with at least microseconds precision.

Concretely, I have a client (PC) that makes 100 times:

Send UDP frame to server (Ta)
Receive UDP frame from server (Tb)
Spent time is: T=Tb-Ta
and a server (RaspberryPi) that makes 100 times:

Receive UDP frame from client(Tc)
Send UDP frame from client(Td)
Spent time is: T'=Td-Tc

This image shows communication architecture and times to measure:

Image

I´m measuring time before send and after receive in client and subtracting it the time taken in server to receive and send, so the total time would be: Tt=T-T' but sometimes I get negative measures... :S

I´m measuring with this macro, where in 'X' I placed my code (C:sendto()-recvfrom() or S:recvfrom()-sendto()):

Code: Select all

float timef=0.0;
#define TIME_MEASURE(X)                                        \
{                                                              \
  struct timespec ts1, ts2;                                    \
  clock_gettime( CLOCK_REALTIME, &ts1 );                       \
  X;                                                           \
  clock_gettime( CLOCK_REALTIME, &ts2 );                       \
  timef=(float) ( 1.0*(1.0*ts2.tv_nsec - ts1.tv_nsec*1.0)*1e-9 \
    + 1.0*ts2.tv_sec - 1.0*ts1.tv_sec ) );                     \
}

//Client pseudo-code example

main(){
   TIME_MEASURE(
       while(i<100)
       {
           sendto(...);
           recvfrom(..);
       }
   );
}
My full code write measures into a files (dataserver.txt and data.txt) and then I process them with Matlab, but is easy to see in files without processing that there are measures in server file which are bigger than measures in client file, making negative the subtraction Tt= Tclient-Tserver.

I have to measure time in any case, so another solution to obtain performance is not valid for me.

Can anyone suggest what can I do to solve this problem?

Than you so much.

Full code can be downloaded from https://www.dropbox.com/sh/dnbxdfpn8xg2 ... DK-5a?dl=0

Re: Time measure UDP socket Raspi<--->PC

Posted: Thu Apr 07, 2016 9:59 am
by byterg

Re: Time measure UDP socket Raspi<--->PC

Posted: Thu Apr 07, 2016 8:22 pm
by bitbank
It looks like you're using the wrong clock function to measure time differences. CLOCK_REALTIME can jump around while CLOCK_MONOTONIC is the absolute machine time. You can read about it here:

http://stackoverflow.com/questions/3523 ... -monotonic

Re: Time measure UDP socket Raspi<--->PC

Posted: Fri Apr 08, 2016 7:43 am
by ampu
bitbank wrote:It looks like you're using the wrong clock function to measure time differences. CLOCK_REALTIME can jump around while CLOCK_MONOTONIC is the absolute machine time. You can read about it here:

http://stackoverflow.com/questions/3523 ... -monotonic
I already tried replacing CLOCK_REALTIME with CLOCK_MONOTONIC and I got the same results...

Re: Time measure UDP socket Raspi<--->PC

Posted: Fri Apr 08, 2016 10:32 am
by bitbank
ampu wrote:
bitbank wrote:It looks like you're using the wrong clock function to measure time differences. CLOCK_REALTIME can jump around while CLOCK_MONOTONIC is the absolute machine time. You can read about it here:

http://stackoverflow.com/questions/3523 ... -monotonic
I already tried replacing CLOCK_REALTIME with CLOCK_MONOTONIC and I got the same results...
That doesn't sound right. I use CLOCK_MONOTONIC to measure tiny bits of time on various Linux machines and it always returns values which move forward in time. I recently wrote a perf-test app for Raspberry Pi's which uses it:

https://github.com/bitbank2/gcc_perf

L.B.

Re: Time measure UDP socket Raspi<--->PC

Posted: Sat Apr 09, 2016 12:47 am
by swampdog
I'm afraid you have made a fundamental mistake. UDP packets are "shouty" thus no way to know their time back. TCP is worse. You can get an average, that is all.


[quote="ampu"]I´m trying to obtain the performance in a Client (PC i7 3.4 GHz Kubuntu 15.04) - Server (RaspberryPi 700 Mhz Raspbian Jessie) architecture with sockets, measuring the spent time sending and receiving with at least microseconds precision.

Concretely, I have a client (PC) that makes 100 times:

[snip]

Re: Time measure UDP socket Raspi<--->PC

Posted: Sun Apr 10, 2016 3:21 pm
by ampu
swampdog wrote:I'm afraid you have made a fundamental mistake. UDP packets are "shouty" thus no way to know their time back. TCP is worse. You can get an average, that is all.

ampu wrote:I´m trying to obtain the performance in a Client (PC i7 3.4 GHz Kubuntu 15.04) - Server (RaspberryPi 700 Mhz Raspbian Jessie) architecture with sockets, measuring the spent time sending and receiving with at least microseconds precision.

Concretely, I have a client (PC) that makes 100 times:

[snip]
I don't know the meaning of "shouty", but in any case, I'm measuring spent time in a while loop (sent-receive) subtracting another time spent in server, so I think that is possible in spite of I use UDP.