move the initial RTT estimate to the congestion package

This commit is contained in:
Marten Seemann
2018-05-01 18:57:05 +09:00
parent 4a7bab9ffe
commit 3cd6cc3e9f
4 changed files with 19 additions and 16 deletions

View File

@@ -11,6 +11,8 @@ const (
oneMinusAlpha float32 = (1 - rttAlpha)
rttBeta float32 = 0.25
oneMinusBeta float32 = (1 - rttBeta)
// The default RTT used before an RTT sample is taken.
defaultInitialRTT = 100 * time.Millisecond
)
// RTTStats provides round-trip statistics
@@ -38,6 +40,15 @@ func (r *RTTStats) LatestRTT() time.Duration { return r.latestRTT }
// May return Zero if no valid updates have occurred.
func (r *RTTStats) SmoothedRTT() time.Duration { return r.smoothedRTT }
// SmoothedOrInitialRTT returns the EWMA smoothed RTT for the connection.
// If no valid updates have occurred, it returns the initial RTT.
func (r *RTTStats) SmoothedOrInitialRTT() time.Duration {
if r.smoothedRTT != 0 {
return r.smoothedRTT
}
return defaultInitialRTT
}
// MeanDeviation gets the mean deviation
func (r *RTTStats) MeanDeviation() time.Duration { return r.meanDeviation }

View File

@@ -37,6 +37,12 @@ var _ = Describe("RTT stats", func() {
Expect(rttStats.SmoothedRTT()).To(Equal((287500 * time.Microsecond)))
})
It("SmoothedOrInitialRTT", func() {
Expect(rttStats.SmoothedOrInitialRTT()).To(Equal(defaultInitialRTT))
rttStats.UpdateRTT((300 * time.Millisecond), (100 * time.Millisecond), time.Time{})
Expect(rttStats.SmoothedOrInitialRTT()).To(Equal((300 * time.Millisecond)))
})
It("MinRTT", func() {
rttStats.UpdateRTT((200 * time.Millisecond), 0, time.Time{})
Expect(rttStats.MinRTT()).To(Equal((200 * time.Millisecond)))