diff options
| -rw-r--r-- | ms/ms.go | 33 | ||||
| -rw-r--r-- | ms/ms_test.go | 61 | ||||
| -rw-r--r-- | rpm/rpm.go | 24 | ||||
| -rw-r--r-- | stabilizer/rev3.go | 26 |
4 files changed, 117 insertions, 27 deletions
@@ -46,7 +46,10 @@ func calculateAverage[T constraints.Integer | constraints.Float](elements []T) f return float64(total) / float64(len(elements)) } -func calculatePercentile[T constraints.Integer | constraints.Float](elements []T, p int) (result T) { +func calculatePercentile[T constraints.Integer | constraints.Float]( + elements []T, + p int, +) (result T) { result = T(0) if p < 0 || p > 100 { return @@ -76,7 +79,9 @@ func (ims *InfiniteMathematicalSeries[T]) Less(i, j int) bool { func (ims *InfiniteMathematicalSeries[T]) DoubleSidedTrim(percent uint32) MathematicalSeries[T] { if percent >= 100 { - panic(fmt.Sprintf("Cannot perform double-sided trim for an invalid percentage: %d", percent)) + panic( + fmt.Sprintf("Cannot perform double-sided trim for an invalid percentage: %d", percent), + ) } trimmed := &InfiniteMathematicalSeries[T]{} @@ -106,7 +111,9 @@ func (ims *InfiniteMathematicalSeries[T]) CalculateAverage() float64 { return calculateAverage(ims.elements) } -func (ims *InfiniteMathematicalSeries[T]) AllSequentialIncreasesLessThan(limit float64) (bool, float64) { +func (ims *InfiniteMathematicalSeries[T]) AllSequentialIncreasesLessThan( + limit float64, +) (bool, float64) { if len(ims.elements) < 2 { return false, 0.0 } @@ -186,7 +193,9 @@ type CappedMathematicalSeries[T constraints.Float | constraints.Integer] struct divisor *saturating.Saturating[uint64] } -func NewCappedMathematicalSeries[T constraints.Float | constraints.Integer](instants_count uint64) MathematicalSeries[T] { +func NewCappedMathematicalSeries[T constraints.Float | constraints.Integer]( + instants_count uint64, +) MathematicalSeries[T] { return &CappedMathematicalSeries[T]{ elements: make([]T, instants_count), elements_count: instants_count, @@ -209,7 +218,9 @@ func (ma *CappedMathematicalSeries[T]) CalculateAverage() float64 { return calculateAverage(ma.elements[0:ma.divisor.Value()]) } -func (ma *CappedMathematicalSeries[T]) AllSequentialIncreasesLessThan(limit float64) (_ bool, maximumSequentialIncrease float64) { +func (ma *CappedMathematicalSeries[T]) AllSequentialIncreasesLessThan( + limit float64, +) (_ bool, maximumSequentialIncrease float64) { // If we have not yet accumulated a complete set of intervals, // this is false. @@ -302,7 +313,13 @@ func (ma *CappedMathematicalSeries[T]) Values() []T { func (ma *CappedMathematicalSeries[T]) Len() int { if uint64(len(ma.elements)) != ma.elements_count { - panic(fmt.Sprintf("Error: A capped mathematical series' metadata is invalid: the length of its element array/slice does not match element_count! (%v vs %v)", ma.elements_count, len(ma.elements))) + panic( + fmt.Sprintf( + "Error: A capped mathematical series' metadata is invalid: the length of its element array/slice does not match element_count! (%v vs %v)", + ma.elements_count, + len(ma.elements), + ), + ) } return len(ma.elements) } @@ -331,7 +348,9 @@ func (ims *CappedMathematicalSeries[T]) Less(i, j int) bool { func (ims *CappedMathematicalSeries[T]) DoubleSidedTrim(percent uint32) MathematicalSeries[T] { if percent >= 100 { - panic(fmt.Sprintf("Cannot perform double-sided trim for an invalid percentage: %d", percent)) + panic( + fmt.Sprintf("Cannot perform double-sided trim for an invalid percentage: %d", percent), + ) } trimmed := &CappedMathematicalSeries[T]{elements_count: uint64(ims.Len())} diff --git a/ms/ms_test.go b/ms/ms_test.go index 87f3c8a..533cc7e 100644 --- a/ms/ms_test.go +++ b/ms/ms_test.go @@ -29,14 +29,19 @@ func Test_InfiniteSequentialIncreasesAlwaysLessThan(test *testing.T) { series.AddElement(float64(previous)) } if islt, maxSeqIncrease := series.AllSequentialIncreasesLessThan(6.0); !islt { - test.Fatalf("(infinite) Sequential increases are not always less than 6.0 (%f).", maxSeqIncrease) + test.Fatalf( + "(infinite) Sequential increases are not always less than 6.0 (%f).", + maxSeqIncrease, + ) } } func Test_CappedTooFewInstantsSequentialIncreasesLessThanAlwaysFalse(test *testing.T) { series := NewCappedMathematicalSeries[float64](500) series.AddElement(0.0) if islt, _ := series.AllSequentialIncreasesLessThan(6.0); islt { - test.Fatalf("(infinite) 0 elements in a series should always yield false when asking if sequential increases are less than a value.") + test.Fatalf( + "(infinite) 0 elements in a series should always yield false when asking if sequential increases are less than a value.", + ) } } @@ -66,7 +71,10 @@ func Test_Infinite90_percentile(test *testing.T) { series.AddElement(1) if series.Percentile(90) != 10 { - test.Fatalf("(infinite) Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", series.Percentile(90)) + test.Fatalf( + "(infinite) Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", + series.Percentile(90), + ) } } @@ -84,7 +92,10 @@ func Test_Infinite90_percentile_reversed(test *testing.T) { series.AddElement(10) if series.Percentile(90) != 10 { - test.Fatalf("(infinite) Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", series.Percentile(90)) + test.Fatalf( + "(infinite) Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", + series.Percentile(90), + ) } } @@ -102,7 +113,10 @@ func Test_Infinite50_percentile_jumbled(test *testing.T) { series.AddElement(12) if series.Percentile(50) != 15 { - test.Fatalf("(infinite) Series 50 percentile of a jumble of numbers failed: Expected 15 got %v.", series.Percentile(50)) + test.Fatalf( + "(infinite) Series 50 percentile of a jumble of numbers failed: Expected 15 got %v.", + series.Percentile(50), + ) } } @@ -132,7 +146,11 @@ func Test_InfiniteDoubleSidedTrimmedMean_jumbled(test *testing.T) { trimmed := series.DoubleSidedTrim(10) if trimmed.Len() != 16 { - test.Fatalf("Capped series is not of the proper size. Expected %v and got %v", 16, trimmed.Len()) + test.Fatalf( + "Capped series is not of the proper size. Expected %v and got %v", + 16, + trimmed.Len(), + ) } prev := int64(0) @@ -172,7 +190,10 @@ func Test_CappedSequentialIncreasesAlwaysLessThanWithWraparound(test *testing.T) } if islt, maxSeqIncrease := series.AllSequentialIncreasesLessThan(11.0); !islt { - test.Fatalf("Sequential increases are not always less than 11.0 in wraparound situation (%f v 11.0).", maxSeqIncrease) + test.Fatalf( + "Sequential increases are not always less than 11.0 in wraparound situation (%f v 11.0).", + maxSeqIncrease, + ) } } @@ -192,7 +213,10 @@ func Test_CappedSequentialIncreasesAlwaysLessThanWithWraparoundInverse(test *tes } if islt, maxSeqIncrease := series.AllSequentialIncreasesLessThan(11.0); islt { - test.Fatalf("Sequential increases are (unexpectedly) always less than 11.0 in wraparound situation: %f v 11.0.", maxSeqIncrease) + test.Fatalf( + "Sequential increases are (unexpectedly) always less than 11.0 in wraparound situation: %f v 11.0.", + maxSeqIncrease, + ) } } @@ -271,7 +295,10 @@ func Test_Capped90_percentile(test *testing.T) { series.AddElement(1) if series.Percentile(90) != 10 { - test.Fatalf("Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", series.Percentile(90)) + test.Fatalf( + "Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", + series.Percentile(90), + ) } } @@ -289,7 +316,10 @@ func Test_Capped90_percentile_reversed(test *testing.T) { series.AddElement(10) if series.Percentile(90) != 10 { - test.Fatalf("Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", series.Percentile(90)) + test.Fatalf( + "Series 90th percentile of 0 ... 10 failed: Expected 10 got %v.", + series.Percentile(90), + ) } } @@ -307,7 +337,10 @@ func Test_Capped50_percentile_jumbled(test *testing.T) { series.AddElement(12) if series.Percentile(50) != 15 { - test.Fatalf("Series 50 percentile of a jumble of numbers failed: Expected 15 got %v.", series.Percentile(50)) + test.Fatalf( + "Series 50 percentile of a jumble of numbers failed: Expected 15 got %v.", + series.Percentile(50), + ) } } @@ -328,7 +361,11 @@ func Test_CappedDoubleSidedTrimmedMean_jumbled(test *testing.T) { trimmed := series.DoubleSidedTrim(10) if trimmed.Len() != 8 { - test.Fatalf("Capped series is not of the proper size. Expected %v and got %v", 8, trimmed.Len()) + test.Fatalf( + "Capped series is not of the proper size. Expected %v and got %v", + 8, + trimmed.Len(), + ) } prev := int64(0) @@ -447,7 +447,10 @@ func LoadGenerator( ) } // TODO: Do we add null connection to throughput? and how do we define it? Throughput -1 or 0? - granularThroughputDatapoints = append(granularThroughputDatapoints, GranularThroughputDataPoint{now, 0, uint32(i), 0, 0, ""}) + granularThroughputDatapoints = append( + granularThroughputDatapoints, + GranularThroughputDataPoint{now, 0, uint32(i), 0, 0, ""}, + ) continue } allInvalid = false @@ -473,7 +476,17 @@ func LoadGenerator( } } } - granularThroughputDatapoints = append(granularThroughputDatapoints, GranularThroughputDataPoint{now, instantaneousConnectionThroughput, uint32(i), tcpRtt, tcpCwnd, ""}) + granularThroughputDatapoints = append( + granularThroughputDatapoints, + GranularThroughputDataPoint{ + now, + instantaneousConnectionThroughput, + uint32(i), + tcpRtt, + tcpCwnd, + "", + }, + ) } // For some reason, all the lgcs are invalid. This likely means that @@ -489,7 +502,12 @@ func LoadGenerator( } // We have generated a throughput calculation -- let's send it back to the coordinator - throughputDataPoint := ThroughputDataPoint{time.Now(), instantaneousTotalThroughput, len(*loadGeneratingConnections.LGCs), granularThroughputDatapoints} + throughputDataPoint := ThroughputDataPoint{ + time.Now(), + instantaneousTotalThroughput, + len(*loadGeneratingConnections.LGCs), + granularThroughputDatapoints, + } throughputCalculations <- throughputDataPoint // Just add another constants.AdditiveNumberOfLoadGeneratingConnections flows -- that's our only job now! diff --git a/stabilizer/rev3.go b/stabilizer/rev3.go index fa9b378..4ab0bd9 100644 --- a/stabilizer/rev3.go +++ b/stabilizer/rev3.go @@ -41,7 +41,13 @@ type ThroughputStabilizer DataPointStabilizer // calculate the standard deviation of those values. If the calculated standard deviation is less than S, we declare // stability. -func NewProbeStabilizer(i uint64, k uint64, s float64, debugLevel debug.DebugLevel, debug *debug.DebugWithPrefix) ProbeStabilizer { +func NewProbeStabilizer( + i uint64, + k uint64, + s float64, + debugLevel debug.DebugLevel, + debug *debug.DebugWithPrefix, +) ProbeStabilizer { return ProbeStabilizer{instantaneousMeasurements: ms.NewCappedMathematicalSeries[float64](i), movingAverages: ms.NewCappedMathematicalSeries[float64](k), stabilityStandardDeviation: s, @@ -58,7 +64,9 @@ func (r3 *ProbeStabilizer) AddMeasurement(measurement rpm.ProbeDataPoint) { // be 1 / measurement.RoundTripCount of the total length. for range utilities.Iota(0, int(measurement.RoundTripCount)) { // Add this instantaneous measurement to the mix of the I previous instantaneous measurements. - r3.instantaneousMeasurements.AddElement(measurement.Duration.Seconds() / float64(measurement.RoundTripCount)) + r3.instantaneousMeasurements.AddElement( + measurement.Duration.Seconds() / float64(measurement.RoundTripCount), + ) } // Calculate the moving average of the I previous instantaneous measurements and add it to // the mix of K previous moving averages. @@ -108,12 +116,20 @@ func (r3 *ProbeStabilizer) IsStable() bool { return isStable } -func NewThroughputStabilizer(i uint64, k uint64, s float64, debugLevel debug.DebugLevel, debug *debug.DebugWithPrefix) ThroughputStabilizer { - return ThroughputStabilizer{instantaneousMeasurements: ms.NewCappedMathematicalSeries[float64](i), +func NewThroughputStabilizer( + i uint64, + k uint64, + s float64, + debugLevel debug.DebugLevel, + debug *debug.DebugWithPrefix, +) ThroughputStabilizer { + return ThroughputStabilizer{ + instantaneousMeasurements: ms.NewCappedMathematicalSeries[float64](i), movingAverages: ms.NewCappedMathematicalSeries[float64](k), stabilityStandardDeviation: s, dbgConfig: debug, - dbgLevel: debugLevel} + dbgLevel: debugLevel, + } } func (r3 *ThroughputStabilizer) AddMeasurement(measurement rpm.ThroughputDataPoint) { |
