Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtt: Fix extra 1 second delay in RTT calculation #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ELWIN-MAO
Copy link

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
image

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.

image

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.
image

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
image

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
image

This situation has been partially fixed but not completely.
image

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().

Reviewed-by: lishuo02 <[email protected]>
Signed-off-by: maoyingming <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant