Muduo Network Programming Example (v) measuring network latency for two machines

Source: Internet
Author: User
Tags current time local time

This article introduces a simple network program roundtrip, which is used to measure the network latency between two machines, that is, "roundtrip time/round trip Time/rtt". This article mainly examines the tcp_nodelay of the fixed-length TCP message and the function of the packet.

The code for this article is shown in http://code.google.com/p/muduo/source/browse/trunk/examples/roundtrip/roundtrip.cc

The method of measuring RTT is simple:

Host A sends a message to host B that contains the local time that host a sends a message

Once host B receives the message echo back to host A

When host A receives a message, the RTT is obtained by subtracting the time in the message with the current time.

The NTP protocol works like this, but in addition to measuring the RTT,NTP need to know the time difference between the two machines (clock offset), so that the timing can be calibrated.

Above is the NTP protocol to send and receive messages, RTT = (t4-t1) – (T3-T2), Time difference = ((T4+T1)-(T2+T3))/2. NTP requires a one-way delay on the round-trip path to be as equal as possible to reduce system error. The accidental error is determined by the uncertainty of one-way delay.

In the roundtrip sample program I designed, the protocol simplifies:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.