Source File
rtt_stats.go
Belonging Package
github.com/quic-go/quic-go/internal/utils
package utilsimport ()const (rttAlpha = 0.125oneMinusAlpha = 1 - rttAlpharttBeta = 0.25oneMinusBeta = 1 - rttBeta)// The default RTT used before an RTT sample is takenconst DefaultInitialRTT = 100 * time.Millisecond// RTTStats provides round-trip statisticstype RTTStats struct {hasMeasurement boolminRTT atomic.Int64 // nanosecondslatestRTT atomic.Int64 // nanosecondssmoothedRTT atomic.Int64 // nanosecondsmeanDeviation atomic.Int64 // nanosecondsmaxAckDelay atomic.Int64 // nanoseconds}func () *RTTStats {var RTTStats.minRTT.Store(DefaultInitialRTT.Nanoseconds()).latestRTT.Store(DefaultInitialRTT.Nanoseconds()).smoothedRTT.Store(DefaultInitialRTT.Nanoseconds())return &}// MinRTT Returns the minRTT for the entire connection.// May return Zero if no valid updates have occurred.func ( *RTTStats) () time.Duration {return time.Duration(.minRTT.Load())}// LatestRTT returns the most recent rtt measurement.// May return Zero if no valid updates have occurred.func ( *RTTStats) () time.Duration {return time.Duration(.latestRTT.Load())}// SmoothedRTT returns the smoothed RTT for the connection.// May return Zero if no valid updates have occurred.func ( *RTTStats) () time.Duration {return time.Duration(.smoothedRTT.Load())}// MeanDeviation gets the mean deviationfunc ( *RTTStats) () time.Duration {return time.Duration(.meanDeviation.Load())}// MaxAckDelay gets the max_ack_delay advertised by the peerfunc ( *RTTStats) () time.Duration {return time.Duration(.maxAckDelay.Load())}// PTO gets the probe timeout duration.func ( *RTTStats) ( bool) time.Duration {if !.hasMeasurement {return 2 * DefaultInitialRTT}:= .SmoothedRTT() + max(4*.MeanDeviation(), protocol.TimerGranularity)if {+= .MaxAckDelay()}return}// UpdateRTT updates the RTT based on a new sample.func ( *RTTStats) (, time.Duration) {if <= 0 {return}// Update r.minRTT first. r.minRTT does not use an rttSample corrected for// ackDelay but the raw observed sendDelta, since poor clock granularity at// the client may cause a high ackDelay to result in underestimation of the// r.minRTT.:= time.Duration(.minRTT.Load())if !.hasMeasurement || > {=.minRTT.Store(.Nanoseconds())}// Correct for ackDelay if information received from the peer results in a// an RTT sample at least as large as minRTT. Otherwise, only use the// sendDelta.:=if - >= {-=}.latestRTT.Store(.Nanoseconds())// First time call.if !.hasMeasurement {.hasMeasurement = true.smoothedRTT.Store(.Nanoseconds()).meanDeviation.Store(.Nanoseconds() / 2)} else {:= .SmoothedRTT():= time.Duration(oneMinusBeta*float32(.MeanDeviation()/time.Microsecond)+rttBeta*float32((-).Abs()/time.Microsecond)) * time.Microsecond:= time.Duration((float32(/time.Microsecond)*oneMinusAlpha)+(float32(/time.Microsecond)*rttAlpha)) * time.Microsecond.meanDeviation.Store(.Nanoseconds()).smoothedRTT.Store(.Nanoseconds())}}func ( *RTTStats) () bool {return .hasMeasurement}// SetMaxAckDelay sets the max_ack_delayfunc ( *RTTStats) ( time.Duration) {.maxAckDelay.Store(int64())}// SetInitialRTT sets the initial RTT.// It is used during handshake when restoring the RTT stats from the token.func ( *RTTStats) ( time.Duration) {// On the server side, by the time we get to process the session ticket,// we might already have obtained an RTT measurement.// This can happen if we received the ClientHello in multiple pieces, and one of those pieces was lost.// Discard the restored value. A fresh measurement is always better.if .hasMeasurement {return}.smoothedRTT.Store(int64()).latestRTT.Store(int64())}func ( *RTTStats) () {.hasMeasurement = false.minRTT.Store(DefaultInitialRTT.Nanoseconds()).latestRTT.Store(DefaultInitialRTT.Nanoseconds()).smoothedRTT.Store(DefaultInitialRTT.Nanoseconds()).meanDeviation.Store(0)// max_ack_delay remains valid}func ( *RTTStats) () *RTTStats {:= &RTTStats{}.hasMeasurement = .hasMeasurement.minRTT.Store(.minRTT.Load()).latestRTT.Store(.latestRTT.Load()).smoothedRTT.Store(.smoothedRTT.Load()).meanDeviation.Store(.meanDeviation.Load()).maxAckDelay.Store(.maxAckDelay.Load())return}
![]() |
The pages are generated with Golds v0.8.4. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |