summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networkQuality.go20
-rw-r--r--utilities/utilities.go18
2 files changed, 26 insertions, 12 deletions
diff --git a/networkQuality.go b/networkQuality.go
index f9e3d71..f390990 100644
--- a/networkQuality.go
+++ b/networkQuality.go
@@ -50,6 +50,7 @@ var (
// Global configuration
cooldownPeriod time.Duration = 4 * time.Second
robustnessProbeIterationCount int = 5
+ RPMCalculationTime time.Duration = 10 * time.Second
)
type ConfigUrls struct {
@@ -399,7 +400,7 @@ func main() {
return
}
saturationTimeout = true
- timeoutAbsoluteTime = time.Now().Add(5 * time.Second)
+ timeoutAbsoluteTime = time.Now().Add(RPMCalculationTime * time.Second)
timeoutChannel = timeoutat.TimeoutAt(operatingCtx, timeoutAbsoluteTime, *debug)
cancelSaturationCtx()
if *debug {
@@ -413,11 +414,11 @@ func main() {
// to the available time for testing. However, if saturation was achieved before the timeout
// then we want to give ourselves another 5 seconds to calculate the RPM.
if !saturationTimeout {
- timeoutAbsoluteTime = time.Now().Add(5 * time.Second)
+ timeoutAbsoluteTime = time.Now().Add(RPMCalculationTime * time.Second)
timeoutChannel = timeoutat.TimeoutAt(operatingCtx, timeoutAbsoluteTime, *debug)
}
- totalRTTsCount := 0
+ totalRTTsCount := uint64(0)
totalRTTTime := float64(0)
rttTimeout := false
@@ -446,12 +447,17 @@ func main() {
{
rttTimeout = true
}
- case fiveRTTsTime := <-utilities.TimedSequentialRTTs(operatingCtx, downloadSaturation.Lbcs[randomLbcsIndex].Client(), &http.Client{}, config.Urls.SmallUrl):
+ case sequentialRTTsTime := <-utilities.CalculateSequentialRTTsTime(operatingCtx, downloadSaturation.Lbcs[randomLbcsIndex].Client(), &http.Client{}, config.Urls.SmallUrl):
{
- totalRTTsCount += 5
- totalRTTTime += fiveRTTsTime.Delay.Seconds()
+ if sequentialRTTsTime.Err != nil {
+ fmt.Printf("Failed to calculate a time for sequential RTTs: %v\n", sequentialRTTsTime.Err)
+ continue
+ }
+ // We know that we have a good Sequential RTT.
+ totalRTTsCount += uint64(sequentialRTTsTime.RTTs)
+ totalRTTTime += sequentialRTTsTime.Delay.Seconds()
if *debug {
- fmt.Printf("fiveRTTsTime: %v\n", fiveRTTsTime.Delay.Seconds())
+ fmt.Printf("sequentialRTTsTime: %v\n", sequentialRTTsTime.Delay.Seconds())
}
}
}
diff --git a/utilities/utilities.go b/utilities/utilities.go
index a441453..f2ab80d 100644
--- a/utilities/utilities.go
+++ b/utilities/utilities.go
@@ -44,32 +44,40 @@ func Conditional(condition bool, t string, f string) string {
type GetLatency struct {
Delay time.Duration
+ RTTs uint16
Err error
}
-func TimedSequentialRTTs(ctx context.Context, client_a *http.Client, client_b *http.Client, url string) chan GetLatency {
+func CalculateSequentialRTTsTime(ctx context.Context, client_a *http.Client, client_b *http.Client, url string) chan GetLatency {
responseChannel := make(chan GetLatency)
go func() {
before := time.Now()
c_a, err := client_a.Get(url)
if err != nil {
- responseChannel <- GetLatency{Delay: 0, Err: err}
+ responseChannel <- GetLatency{Delay: 0, RTTs: 0, Err: err}
+ return
}
// TODO: Make this interruptable somehow by using _ctx_.
_, err = io.ReadAll(c_a.Body)
if err != nil {
- responseChannel <- GetLatency{Delay: 0, Err: err}
+ responseChannel <- GetLatency{Delay: 0, RTTs: 0, Err: err}
+ return
}
+ c_a.Body.Close()
+
c_b, err := client_b.Get(url)
if err != nil {
- responseChannel <- GetLatency{Delay: 0, Err: err}
+ responseChannel <- GetLatency{Delay: 0, RTTs: 0, Err: err}
+ return
}
// TODO: Make this interruptable somehow by using _ctx_.
_, err = io.ReadAll(c_b.Body)
if err != nil {
responseChannel <- GetLatency{Delay: 0, Err: err}
+ return
}
- responseChannel <- GetLatency{Delay: time.Now().Sub(before), Err: nil}
+ c_b.Body.Close()
+ responseChannel <- GetLatency{Delay: time.Since(before), RTTs: 10, Err: nil}
}()
return responseChannel
}