Skip to content

Commit e476fff

Browse files
committed
adds speedtest to perf tests
Signed-off-by: Ashraf Fouda <ashraf.m.fouda@gmail.com>
1 parent 3491f06 commit e476fff

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ require (
4545
github.com/pkg/errors v0.9.1
4646
github.com/rs/zerolog v1.34.0
4747
github.com/shirou/gopsutil v3.21.11+incompatible
48+
github.com/showwin/speedtest-go v1.7.10
4849
github.com/stretchr/testify v1.10.0
4950
github.com/threefoldtech/0-fs v1.3.1-0.20240424140157-b488dfedcc56
5051
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20241127100051-77e684bcb1b2
@@ -64,7 +65,6 @@ require (
6465
)
6566

6667
require (
67-
github.com/fatih/color v1.18.0 // indirect
6868
github.com/frankban/quicktest v1.14.3 // indirect
6969
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
7070
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ github.com/safchain/ethtool v0.0.0-20201023143004-874930cb3ce0/go.mod h1:Z0q5wiB
535535
github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
536536
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
537537
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
538+
github.com/showwin/speedtest-go v1.7.10 h1:9o5zb7KsuzZKn+IE2//z5btLKJ870JwO6ETayUkqRFw=
539+
github.com/showwin/speedtest-go v1.7.10/go.mod h1:Ei7OCTmNPdWofMadzcfgq1rUO7mvJy9Jycj//G7vyfA=
538540
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
539541
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
540542
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=

pkg/perf/iperf/iperf_task.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313
"github.com/cenkalti/backoff"
1414
"github.com/pkg/errors"
1515
"github.com/rs/zerolog/log"
16+
"github.com/showwin/speedtest-go/speedtest"
1617
"github.com/threefoldtech/zosbase/pkg/environment"
1718
"github.com/threefoldtech/zosbase/pkg/network/iperf"
1819
"github.com/threefoldtech/zosbase/pkg/perf"
19-
"github.com/threefoldtech/zosbase/pkg/perf/exec_wrapper"
20+
execwrapper "github.com/threefoldtech/zosbase/pkg/perf/exec_wrapper"
2021
"github.com/threefoldtech/zosbase/pkg/perf/graphql"
2122
)
2223

@@ -66,7 +67,7 @@ func (t *IperfTest) ID() string {
6667

6768
// Cron returns the schedule for the tcp task
6869
func (t *IperfTest) Cron() string {
69-
return "0 0 */6 * * *"
70+
return "*/10 * * * * *"
7071
}
7172

7273
// Description returns the task description
@@ -222,6 +223,31 @@ func (t *IperfTest) runIperfTest(ctx context.Context, clientIP string, tcp bool)
222223
if !tcp && len(report.End.Streams) > 0 {
223224
iperfResult.DownloadSpeed = report.End.Streams[0].UDP.BitsPerSecond
224225
}
226+
var speedtestServer *speedtest.Server
227+
serverList, _ := speedtest.FetchServers()
228+
servers, _ := serverList.FindServer([]int{})
229+
if len(servers) > 0 {
230+
speedtestServer = servers[0]
231+
err = speedtestServer.DownloadTest()
232+
if err != nil {
233+
log.Error().Err(err).Msg("speedtest download test failed")
234+
}
235+
err = speedtestServer.UploadTest()
236+
if err != nil {
237+
log.Error().Err(err).Msg("speedtest upload test failed")
238+
}
239+
downloadSpeed := float64(speedtestServer.DLSpeed) * 8
240+
uploadSpeed := float64(speedtestServer.ULSpeed) * 8
241+
log.Debug().Msgf("speedtest: %f/%f vs iperf results: %f/%f", downloadSpeed, uploadSpeed, iperfResult.DownloadSpeed, iperfResult.UploadSpeed)
242+
// take the best result
243+
if downloadSpeed > iperfResult.DownloadSpeed {
244+
iperfResult.DownloadSpeed = downloadSpeed
245+
}
246+
if uploadSpeed > iperfResult.UploadSpeed {
247+
iperfResult.UploadSpeed = uploadSpeed
248+
}
249+
250+
}
225251

226252
return iperfResult
227253
}

0 commit comments

Comments
 (0)