Skip to content

Commit

Permalink
Merge 3521123 into df68f4c
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodauria committed May 17, 2022
2 parents df68f4c + 3521123 commit 9c49e5d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
31 changes: 22 additions & 9 deletions cmd/ndt7-client/internal/emitter/humanreadable.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,29 @@ func (h HumanReadable) onSpeedEvent(m *spec.Measurement) error {
// The specification recommends that we show application level
// measurements. Let's just do that in interactive mode. To this
// end, we ignore any measurement coming from the server.
if m.Origin != spec.OriginClient {
return nil
switch m.Test {
case spec.TestDownload:
if m.Origin == spec.OriginClient {
if m.AppInfo == nil || m.AppInfo.ElapsedTime <= 0 {
return errors.New("missing AppInfo or invalid ElapsedTime")
}
elapsed := float64(m.AppInfo.ElapsedTime)
v := 8.0 * float64(m.AppInfo.NumBytes) / elapsed
_, err := fmt.Fprintf(h.out, "\rAvg. speed : %7.1f Mbit/s", v)
return err
}
case spec.TestUpload:
if m.Origin == spec.OriginServer {
if m.TCPInfo == nil || m.TCPInfo.ElapsedTime <= 0 {
return errors.New("missing TCPInfo or invalid ElapsedTime")
}
elapsed := float64(m.TCPInfo.ElapsedTime)
v := 8.0 * float64(m.TCPInfo.BytesReceived) / elapsed
_, err := fmt.Fprintf(h.out, "\rAvg. speed : %7.1f Mbit/s", v)
return err
}
}
if m.AppInfo == nil || m.AppInfo.ElapsedTime <= 0 {
return errors.New("Missing m.AppInfo or invalid m.AppInfo.ElapsedTime")
}
elapsed := float64(m.AppInfo.ElapsedTime) / 1e06
v := (8.0 * float64(m.AppInfo.NumBytes)) / elapsed / (1000.0 * 1000.0)
_, err := fmt.Fprintf(h.out, "\rAvg. speed : %7.1f Mbit/s", v)
return err
return nil
}

// OnComplete handles the complete event
Expand Down
16 changes: 9 additions & 7 deletions cmd/ndt7-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ const (
)

var (
ClientName = "ndt7-client-go-cmd"
ClientVersion = "0.6.1"
flagProfile = flag.String("profile", "",
ClientName = "ndt7-client-go-cmd"
ClientVersion = "0.6.1"
flagProfile = flag.String("profile", "",
"file where to store pprof profile (see https://blog.golang.org/pprof)")

flagScheme = flagx.Enum{
Expand Down Expand Up @@ -273,12 +273,14 @@ func makeSummary(FQDN string, results map[spec.TestKind]*ndt7.LatestMeasurements
}
}
}
// Upload comes from the client-side Measurement during the upload test.
// The upload rate comes from the receiver (the server). Currently
// ndt-server only provides network-level throughput via TCPInfo.
// TODO: Use AppInfo for application-level measurements when available.
if ul, ok := results[spec.TestUpload]; ok {
if ul.Client.AppInfo != nil && ul.Client.AppInfo.ElapsedTime > 0 {
elapsed := float64(ul.Client.AppInfo.ElapsedTime) / 1e06
if ul.Server.TCPInfo != nil && ul.Server.TCPInfo.BytesReceived > 0 {
elapsed := float64(ul.Server.TCPInfo.ElapsedTime) / 1e06
s.Upload = emitter.ValueUnitPair{
Value: (8.0 * float64(ul.Client.AppInfo.NumBytes)) /
Value: (8.0 * float64(ul.Server.TCPInfo.BytesReceived)) /
elapsed / (1000.0 * 1000.0),
Unit: "Mbit/s",
}
Expand Down
13 changes: 7 additions & 6 deletions cmd/ndt7-client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ func TestMakeSummary(t *testing.T) {
tcpInfo.BytesSent = 100
tcpInfo.BytesRetrans = 1
tcpInfo.MinRTT = 10000
// Simulate a 8Mb/s upload rate.
tcpInfo.BytesReceived = 10000000
tcpInfo.ElapsedTime = 10000000

results := map[spec.TestKind]*ndt7.LatestMeasurements{
spec.TestDownload: {
Expand All @@ -406,11 +409,8 @@ func TestMakeSummary(t *testing.T) {
},
},
spec.TestUpload: {
Client: spec.Measurement{
AppInfo: &spec.AppInfo{
NumBytes: 100,
ElapsedTime: 1,
},
Server: spec.Measurement{
TCPInfo: tcpInfo,
},
},
}
Expand All @@ -425,7 +425,7 @@ func TestMakeSummary(t *testing.T) {
Unit: "Mbit/s",
},
Upload: emitter.ValueUnitPair{
Value: 800.0,
Value: 8.0,
Unit: "Mbit/s",
},
DownloadRetrans: emitter.ValueUnitPair{
Expand All @@ -441,6 +441,7 @@ func TestMakeSummary(t *testing.T) {
generated := makeSummary("test", results)

if !reflect.DeepEqual(generated, expected) {
t.Errorf("expected %+v; got %+v", expected, generated)
t.Fatal("makeSummary(): unexpected summary data")
}
}

0 comments on commit 9c49e5d

Please sign in to comment.