Skip to content

Commit

Permalink
Implement Confidence Intervals
Browse files Browse the repository at this point in the history
Resolves: #42

Signed-off-by: Sai Sindhur Malleni <[email protected]>
  • Loading branch information
smalleni committed Apr 3, 2023
1 parent 4721d80 commit 57b69c7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ module github.com/jtaleric/k8s-netperf
go 1.18

require (
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794
github.com/google/uuid v1.1.2
github.com/montanaflynn/stats v0.6.6
github.com/olekukonko/tablewriter v0.0.5
github.com/opensearch-project/opensearch-go v1.1.0
github.com/openshift/client-go v0.0.0-20221213131518-7aec8d54188a
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.41.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.26.0
k8s.io/apimachinery v0.26.0
Expand Down Expand Up @@ -39,9 +42,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/openshift/api v0.0.0-20230111143458-54592eea5539 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 h1:xlwdaKcTNVW4PtpQb8aKA4Pjy0CdJHEqvFbAnvR5m2g=
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794/go.mod h1:7e+I0LQFUI9AXWxOfsQROs9xPhoJtbsyWcjJqDd4KPY=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
14 changes: 12 additions & 2 deletions pkg/results/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/jtaleric/k8s-netperf/pkg/sample"
stats "github.com/montanaflynn/stats"
"github.com/olekukonko/tablewriter"
math "github.com/aclements/go-moremath/stats"
)

// Data describes the result data
Expand Down Expand Up @@ -62,6 +63,11 @@ func Percentile(vals []float64, ptile float64) (float64, error) {
return stats.Percentile(vals, ptile)
}

// Confidence accepts array of floats to calculate average
func confidenceInterval(vals []float64, ci float64) (float64, float64, float64) {
return math.MeanCI(vals, ci)
}

// CheckResults will check to see if there are results with a specific Profile like TCP_STREAM
// returns true if there are results with provided string
func checkResults(s ScenarioResults, check string) bool {
Expand Down Expand Up @@ -163,12 +169,16 @@ func ShowNodeCPU(s ScenarioResults) {

// Abstracts out the common code for results
func renderResults(s ScenarioResults, testType string) {
table := initTable([]string{"Result Type", "Driver", "Scenario", "Parallelism", "Host Network", "Service", "Message Size", "Same node", "Duration", "Samples", "Avg value"})
table := initTable([]string{"Result Type", "Driver", "Scenario", "Parallelism", "Host Network", "Service", "Message Size", "Same node", "Duration", "Samples", "Avg value", "95% Confidence Interval"})
for _, r := range s.Results {
if strings.Contains(r.Profile, testType) {
if len(r.Driver) > 0 {
avg, _ := Average(r.ThroughputSummary)
table.Append([]string{fmt.Sprintf("📊 %s Results", strings.Title(strings.ToLower(testType))), r.Driver, r.Profile, strconv.Itoa(r.Parallelism), strconv.FormatBool(r.HostNetwork), strconv.FormatBool(r.Service), strconv.Itoa(r.MessageSize), strconv.FormatBool(r.SameNode), strconv.Itoa(r.Duration), strconv.Itoa(r.Samples), fmt.Sprintf("%f (%s)", avg, r.Metric)})
var lo, hi float64
if r.Samples > 1 {
_, lo, hi = confidenceInterval(r.ThroughputSummary, 0.95)
}
table.Append([]string{fmt.Sprintf("📊 %s Results", strings.Title(strings.ToLower(testType))), r.Driver, r.Profile, strconv.Itoa(r.Parallelism), strconv.FormatBool(r.HostNetwork), strconv.FormatBool(r.Service), strconv.Itoa(r.MessageSize), strconv.FormatBool(r.SameNode), strconv.Itoa(r.Duration), strconv.Itoa(r.Samples), fmt.Sprintf("%f (%s)", avg, r.Metric), fmt.Sprintf("%f-%f (%s)", lo, hi, r.Metric)})
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794
## explicit; go 1.12
github.com/aclements/go-moremath/mathx
github.com/aclements/go-moremath/stats
github.com/aclements/go-moremath/vec
# github.com/davecgh/go-spew v1.1.1
## explicit
github.com/davecgh/go-spew/spew
Expand Down

0 comments on commit 57b69c7

Please sign in to comment.