From 140c64907408d1cf998f1616d6aec4bc2904ce95 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Fri, 13 May 2022 23:49:56 -0400 Subject: [Improvement] Increase granularity of transfer rate calculation Previously the code relied on the fact that the go runtime would wake up the saturation go function at exactly 1 second intervals, as we asked. With this change, the code takes into account any minor fluctuations in that time when calculating the throughput in an interval. I hope that this change is an improvement. --- rpm/rpm.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'rpm') diff --git a/rpm/rpm.go b/rpm/rpm.go index 8956509..3425566 100644 --- a/rpm/rpm.go +++ b/rpm/rpm.go @@ -23,13 +23,11 @@ func addFlows( ctx context.Context, toAdd uint64, lgcs *[]lgc.LoadGeneratingConnection, - lgcsPreviousTransferred *[]uint64, lgcGenerator func() lgc.LoadGeneratingConnection, debug debug.DebugLevel, ) { for i := uint64(0); i < toAdd; i++ { *lgcs = append(*lgcs, lgcGenerator()) - *lgcsPreviousTransferred = append(*lgcsPreviousTransferred, 0) if !(*lgcs)[len(*lgcs)-1].Start(ctx, debug) { fmt.Printf( "Error starting lgc with id %d!\n", @@ -55,13 +53,11 @@ func Saturate( go func() { lgcs := make([]lgc.LoadGeneratingConnection, 0) - lgcsPreviousTransferred := make([]uint64, 0) addFlows( saturationCtx, constants.StartingNumberOfLoadGeneratingConnections, &lgcs, - &lgcsPreviousTransferred, lgcGenerator, debugging.Level, ) @@ -116,7 +112,7 @@ func Saturate( // Compute "instantaneous aggregate" goodput which is the number of // bytes transferred within the last second. - totalTransfer := uint64(0) + var totalTransfer float64 = 0 allInvalid := true for i := range lgcs { if !lgcs[i].IsValid() { @@ -130,11 +126,10 @@ func Saturate( continue } allInvalid = false - previousTransferred := lgcsPreviousTransferred[i] - currentTransferred := lgcs[i].Transferred() - instantaneousTransferred := currentTransferred - previousTransferred + currentTransferred, currentInterval := lgcs[i].TransferredInInterval() + // normalize to a second-long interval! + instantaneousTransferred := float64(currentTransferred) / float64(currentInterval.Seconds()) totalTransfer += instantaneousTransferred - lgcsPreviousTransferred[i] = currentTransferred } // For some reason, all the lgcs are invalid. This likely means that @@ -208,7 +203,6 @@ func Saturate( saturationCtx, constants.AdditiveNumberOfLoadGeneratingConnections, &lgcs, - &lgcsPreviousTransferred, lgcGenerator, debugging.Level, ) @@ -234,7 +228,7 @@ func Saturate( if debug.IsDebug(debugging.Level) { fmt.Printf("%v: New flows to add to try to increase our saturation!\n", debugging) } - addFlows(saturationCtx, constants.AdditiveNumberOfLoadGeneratingConnections, &lgcs, &lgcsPreviousTransferred, lgcGenerator, debugging.Level) + addFlows(saturationCtx, constants.AdditiveNumberOfLoadGeneratingConnections, &lgcs, lgcGenerator, debugging.Level) previousFlowIncreaseInterval = currentInterval } } -- cgit v1.2.3