Title: Estimating the Round-Trip Time in TCP
Tags: tcp
Question: I was reading a textbook which says:
Let’s begin our study of TCP timer management by considering how TCP estimates
the round-trip time between sender and receiver. This is accomplished as follows.
The sample RTT, denoted SampleRTT, for a segment is the amount of time between
when the segment is sent (that is, passed to IP) and when an acknowledgment for
the segment is received. Instead of measuring a SampleRTT for every transmitted segment, most TCP implementations take only one SampleRTT measurement at a time. That is, at any point in time, the SampleRTT is being estimated for only one of the transmitted but currently unacknowledged segments, leading to a new value of SampleRTT approximately once every RTT.
I'm a little bit confused here, the text in black says it won't measure SampleRTT for every segement, then it says a new value of SampleRTT  will be  approximately once every RTT, which still sounds like TCP measure SampleRTT for every segement to the an average RTT?

Here is the accepted answer: From the sender's perspective, segments within the send window are all &quot;in flight&quot; simultaneously. So, instead of trying to track each segment's RTT, just one segment is tracked at a time. Since it takes RTT to send a segment and receive ACK, one sample per RTT is taken that way.
If you'd track each segment's RTT you'd have number of segments in send window = window size / segment size samples per RTT - that's actually more than you need, so it wastes memory and processing power.
As Jeff has pointed out in his answer, today's implementations commonly use the TCP timestamp option to simplify RTT measurement. Timestamping provides finer-grained information with less processing overhead. Do check out Jeff's links as they're well worth reading.
Comment for this answer: so TCP just radomly choose one segment within the many segments(pipeline) the send window? what happen if the chosen one is timeout later then TCP cannot go back to measure another segment  in previous window?
Comment for this answer: Implementation specifics are really off-topic here, but the easiest way is to track the first segment, when that's ACKed, track the very next segment to send and so on.
Comment for this answer: It's unfortunate that this answer became the accepted one since it's not correct for modern TCP implementations.  For example, Linux really does keep track of the time segments were transmitted and acknowledged.  You don't have to take my word for it.  https://elixir.bootlin.com/linux/latest/source/net/ipv4/tcp_rate.c
Comment for this answer: Thanks @JeffWheeler - I've added timestamping to the answer, but I can't vote more than once for yours. Once again it shows that textbooks are most often not up to date or even obsolete.

Here is another answer: I suggest you start by reading RFC 7323 §4 RTTM: Round-Trip Time Measurement which is a fantastic introduction to this problem, a great perspective on how long very smart people have worked on it, and how little has changed since 1992.
The Linux tcp_input.c source also contains a lot of useful commentary and links to a few newer academic papers on this topic.
If you check on your own workstation, using tcpdump or wireshark, you'll find that most TCP segments exchanged by your computer have a timestamp option present.  This allows more frequent RTT measurement providing better inputs to the Smoothed RTT used to calculate RTO, and with less complexity.
Without TCP timestamps, systems have to do what Zac67 described, with associated problems / limitations discussed in both the above links and really all the literature about this subject.
Comment for this answer: Please don't start by reading RFC 1323. Or, if you do, always check its header block first. Six years before this answer was posted, RFC 1323 was stamped with "Obsoleted by: [7323](https://www.rfc-editor.org/rfc/rfc7323)" This Q&A thread is all about how the text books go out of date. However a lot of people in the IETF are putting in a lot of work to keep the RFC series up to date. That all goes to nought if those reading and citing them don't check the header first (sigh).
Comment for this answer: I've updated the answer based on your comment @BobBriscoe; thanks!

{'source': 'StackExchangeDataset', 'subset': 'networkengineering.stackexchange.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:08/16/20', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<tcp>', 'Title': 'Estimating the Round-Trip Time in TCP', 'ViewCount': 366, 'id': 69562, 'user_AboutMe': None, 'user_AccountId': 13332616.0, 'user_DisplayName': 'amjad', 'user_Reputation': 411.0, 'user_Views': 22.0, 'user_id': 46704.0}}