Inter-Arrival time

This is a discussion on Inter-Arrival time within the Networking/Device Communication forums, part of the General Programming Boards category; Hi, I am trying to measure the inter arrival time of the packets that I receive in one of my ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    23

    Inter-Arrival time

    Hi,

    I am trying to measure the inter arrival time of the packets that I receive in one of my sockets. Basically, I ve got a socket listening for packets and each time a packet arrives I start a timer. Whenever the next packet arrives I stop the timer and store the value. Then I start a new timer until next packet arrives. The code is below.
    Code:
    ...
    #define IARRIVAL_DELAY 1
    int Crx=0;
    struct timeval tv_b_iarrival[100][7000],tv_e_iarrival[100][7000];
    float AvgIarrival[100][7000];
    char log_iarrival_buf[500];
    FILE * fd_iarrival;
    float MaxIarrival=0.0;
    double SumIarrival=0.0;
    char filename_iarrival[150]="log_file.dat";
    ...
    
    ...
    nrcv=recvfrom(sockfd,buffer,buffersize, 0, (struct sockaddr *)&address,&addrlen );
    
    if (nrcv>0){
    	if (IARRIVAL_DELAY){
    		if (Crx==0)start_time(&tv_b_iarrival[pair][Crx]);
    		else {
    			fd_iarrival=fopen(filename_iarrival,"a");
    			if(fd_iarrival != NULL) {
    				AvgIarrival[pair][Crx-1]=stop_time(&tv_e_iarrival[pair][Crx-1],&tv_b_iarrival[pair][Crx-1]);
    				sprintf(log_iarrival_buf, "%d,%f\n", Crx,AvgIarrival[pair][Crx-1]);
    				fwrite(log_iarrival_buf,strlen(log_iarrival_buf),1,fd_iarrival);
    				fclose(fd_iarrival);
    			}	
    		}
    		if (Crx!=0)start_time(&tv_b_iarrival[pair][Crx]);
    		Crx++;
    	}
    }
    Now, I compare my values with those I record with Wireshark and they are clearly apart. While Wireshark values show sharp differences now and them my values are mainly steady and do not vary much. So I wonder if the socket buffer is playing me a hard time. In other words, Is it possible that the socket
    buffer deliver the packet at a certain speed that i can not see the real difference in the arrival time? If that is the case, how could i get the values Wireshark is getting?

    Thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    For one thing, you're at the other end of the protocol stack compared to where wireshark is looking (the clue is in the name).

    Secondly, you're really skewing your information with opening/closing the file for EVERY message.

    Your large arrays seem to be serving no useful purpose.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    23
    you're at the other end of the protocol stack
    Yes that is right but i have no experience in comparing both sides and it strikes me such big differences.
    you're really skewing your information with opening/closing the file for EVERY message
    This however should not modified the real values response time, it will actually make the longer delays longer and the shorter ones a bit larger isn't it?
    Your large arrays seem to be serving no useful purpose
    This is because this is code is part of a thread that is called multiple times, 100 times exactly and 7000 is because I would like to capture 7000 times the inter-arrival time, so that i can get a good estimate. Also important to mention that at the moment I am only using single thread so yes I could actually remove the 100 from most of the arrays.

    any other ideas of why the sharp changes in wireshark can not be seen at the other end of the protocol?

    Thanks

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > This however should not modified the real values response time, it will actually make the longer delays longer and the shorter ones a bit larger isn't it?
    Consider this possibility:
    Opening and closing a file takes 1 second (doesn't matter, it's just "large")
    The variation between message arrival times is anything from 1mS to 10mS.
    The large and near constant time to open/close the file is going to mask any fine-resolution variation in your message arrival times.

    How can you have multiple threads, when you have a single scalar variable for your subscripts?

    I would remove all the file I/O from your current code, and only write it out when the array is full. On a per message basis, there should be very little overhead in timing the message.

    Also, how expensive is your timing code?
    Is it really a timer, that will fire some event at a future time? These can be expensive.
    How about just reading some convenient clock function?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    23
    Opening and closing a file takes 1 second (doesn't matter, it's just "large")
    The variation between message arrival times is anything from 1mS to 10mS.
    This is actually a good point. In my case I am receiving RTP packet on my socket and they are normally around 20ms apart and although i have changed the code as you mentioned
    only write it out when the array is full
    the outcome is still the same.

    How can you have multiple threads, when you have a single scalar variable for your subscripts?
    I havent been completely transparent in the code, but actually these variables are global variables

    struct timeval tv_b_iarrival[100][7000],tv_e_iarrival[100][7000];
    float AvgIarrival[100][7000];

    So I can have up to 100 threads but all write in the same array, so that then the main threat can handle all the data.


    Is it really a timer, that will fire some event at a future time?
    I simply want to measure the inter arrival time of the packets nothing but that, i am not seting an event out of it.

    So, my main questions whether the socket's buffer can smooth the real arrival time with sockets is still unfolded.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-02-2006, 11:46 PM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 05:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21