rtt: Fix extra 1 second delay in RTT calculation #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Occasionally hping mis reports large RTT latency (>1000ms) . For more details: #48
Thanks.
Fix the issue in the rtt() function where it incorrectly adds an extra 1 second delay to the RTT calculation. To ensure the acquisition of atomic seconds and microseconds values, use gettimeofday() instead of time() and get_usec().
Trigger command:
hping3 -S -p 6379 -c 1000 192.168.0.7 -i u10000
Error output:
On average, out of every 1000 ping packets, 1 to 2 times the RTT delay exceeds 1 second. This delay of more than 1 second is exactly 1 second longer compared to the delays of the packets before and after it.
tcpdump analysis:
The tcpdump capture shows that the TCP connection with cport 2570 and sport 6379 completed the three-way handshake in a total of 102 microseconds, which did not exceed 1 second.
More detailed log analysis
This issue typically arises when there is a system time change between the two steps of fetching a timestamp. If a carry-over occurs between fetching seconds and microseconds, it indeed results in the seconds being 1 second less than the actual time. Modify the source code to print out some intermediate results within the rtt() function.
case1: The start time is incorrect, the end time is correct, and the time difference is incorrect. (note fixed)
Incorrect start time: 1719999425.000532s Correct start time: 1719999426.000532s
Correct end time: 1719999426.002238s
Incorrect time difference: 1.001706s = 1001.7ms Correct time difference: 0.001706s = 1.7ms
case2: The start time is correct, the end time is incorrect, and the time difference is incorrect (partially fixed).
Correct start time: 1720000176.998808s
Incorrect end time: 1720000176.000237s Correct end time: 1720000177.000237s
Incorrect time difference: -0.998571s Correct time difference: 0.001429s = 1.4ms
This situation has been partially fixed but not completely.