Skip to content

Commit

Permalink
Fix RTT estimation when timestamp option is enabled.
Browse files Browse the repository at this point in the history
From RFC7323#Section-4

The [RFC6298] RTT estimator has weighting factors, alpha and beta, based on an
implicit assumption that at most one RTTM will be sampled per RTT.  When
multiple RTTMs per RTT are available to update the RTT estimator, an
implementation SHOULD try to adhere to the spirit of the history specified in
[RFC6298].  An implementation suggestion is detailed in Appendix G.

From RFC7323#appendix-G
Appendix G.  RTO Calculation Modification

   Taking multiple RTT samples per window would shorten the history calculated
   by the RTO mechanism in [RFC6298], and the below algorithm aims to maintain a
   similar history as originally intended by [RFC6298].

   It is roughly known how many samples a congestion window worth of data will
   yield, not accounting for ACK compression, and ACK losses.  Such events will
   result in more history of the path being reflected in the final value for
   RTO, and are uncritical.  This modification will ensure that a similar amount
   of time is taken into account for the RTO estimation, regardless of how many
   samples are taken per window:

      ExpectedSamples = ceiling(FlightSize / (SMSS * 2))

      alpha' = alpha / ExpectedSamples

      beta' = beta / ExpectedSamples

   Note that the factor 2 in ExpectedSamples is due to "Delayed ACKs".

   Instead of using alpha and beta in the algorithm of [RFC6298], use alpha' and
   beta' instead:

      RTTVAR <- (1 - beta') * RTTVAR + beta' * |SRTT - R'|

      SRTT <- (1 - alpha') * SRTT + alpha' * R'

      (for each sample R')

PiperOrigin-RevId: 213644795
  • Loading branch information
hbhasker authored and shentubot committed Sep 19, 2018
1 parent 53c177b commit 82e967d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions tcpip/transport/tcp/snd.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,37 @@ func (s *sender) updateRTO(rtt time.Duration) {
if diff < 0 {
diff = -diff
}
s.rtt.rttvar = (3*s.rtt.rttvar + diff) / 4
s.rtt.srtt = (7*s.rtt.srtt + rtt) / 8
// Use RFC6298 standard algorithm to update rttvar and srtt when
// no timestamps are available.
if !s.ep.sendTSOk {
s.rtt.rttvar = (3*s.rtt.rttvar + diff) / 4
s.rtt.srtt = (7*s.rtt.srtt + rtt) / 8
} else {
// When we are taking RTT measurements of every ACK then
// we need to use a modified method as specified in
// https://tools.ietf.org/html/rfc7323#appendix-G
if s.outstanding == 0 {
s.rtt.Unlock()
return
}
// Netstack measures congestion window/inflight all in
// terms of packets and not bytes. This is similar to
// how linux also does cwnd and inflight. In practice
// this approximation works as expected.
expectedSamples := math.Ceil(float64(s.outstanding) / 2)

// alpha & beta values are the original values as recommended in
// https://tools.ietf.org/html/rfc6298#section-2.3.
const alpha = 0.125
const beta = 0.25

alphaPrime := alpha / expectedSamples
betaPrime := beta / expectedSamples
rttVar := (1-betaPrime)*s.rtt.rttvar.Seconds() + betaPrime*diff.Seconds()
srtt := (1-alphaPrime)*s.rtt.srtt.Seconds() + alphaPrime*rtt.Seconds()
s.rtt.rttvar = time.Duration(rttVar * float64(time.Second))
s.rtt.srtt = time.Duration(srtt * float64(time.Second))
}
}

s.rto = s.rtt.srtt + 4*s.rtt.rttvar
Expand Down

0 comments on commit 82e967d

Please sign in to comment.