Hello.
I use Reliable Qos. I want to check probable latency in receiving data by dataReader. For this purpose when one data received by dataReader in "sampleInfo" I calculate difference between "source_timestamp" and "reception_timestamp". For accuracy I want to know:
Is "source_timestamp" time that I call write(the_sample) in DataWriter? Or it is time that sample published from dataWriter's queu to the network?
It's important for me to know that, because I use Reliable Qos, and there might be difference between (time that I call write), and (time that sample published to network).
The source_timestamp is the time (as measured by the system clock on the host running the sending application) when the data is accepted into the DataWriter's cache...which, for SYNCHRONOUS publish_mode should be very close to the time that the data is put on the network...independent of the value of the Reliability QOS.
If the writer's write() call is blocked due to a full cache (send queue) because of RELIABLE Reliablility QoS (DataReader's are slow to send ACKs), the data is not timestamped until the DataWriter is unblocked (i.e., there is room to accept the data into the queue).
If the DataWriter's publish_mode is ASYNCHRONOUS, then there can be a substantial time difference between the source_timestamp and the actual time that the data is on the network.
But, ultimately, the latency of receiving data by a DataReader is fundamentally, the time that the DataWriter::write()'s call succeeded and the time that the user code was able to get the data in their code...which reception_timestamp - source_timestamp only represents a portion of the latency...since the reception_timestamp is recorded when DDS is able to receive the data and store it into the DataReader's cache (receive queue)...which may not be the same time as when the user code actually gets a hold of the data...which greatly depends on the method that the application is coded to receive data (listener/waitset/polling).
AND FINALLY, unless the sending machine and the receiving machine are actually the same, and the same clock is used to generate the source_timestamp and reception_timestamp, there can be (and usually will be) significant offset (which drifts with time) between clocks on different machines. In addition, depending on the host OS that you are using, you may or may not get microsecond resolution on the timestamp (beware of Windows).
You can use some sort of time synchronization mechanism, like NTP, to try to get all of the clocks in sync...but the normal ntp resolution is only 1 millisecond or so...which is not useful when latencies are measure in the microseconds. You would have to find a more accurate synchronization method like using GPS clocks on all hosts to be able to really compare timestamps taken by different clocks and have microsecond accuracy.
Thank you for the rich comment.
I know that latency of sending/receiving is just one part of latency calculating, and as you mentioned I should care about other parameters.
I want to know when reliable data_writer sends a packet in response of nack (data writer retries sending packet to data_reader) does source_timestamp refresh by retry time or it doesn't change?
No, the source timestamp does not change after the data has been accepted (write() returns). Even if the data is sent for a repair...or for non-volatile Durability DataReaders, the source timestamp is the same as when it was first passed to DDS by the DataWriter::write() call.
Thank you so much Mr. Howard