Skip to content

Commit 169b003

Browse files
committed
modified response structs, removed percentileLatencies test cases
1 parent a8d9c40 commit 169b003

File tree

5 files changed

+44
-142
lines changed

5 files changed

+44
-142
lines changed

api/types/metric.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@ import "time"
44

55
// ResponseStats is the report about benchmark result.
66
type ResponseStats struct {
7+
// List of failures
8+
FailureList []error
9+
// All the observed latencies
10+
Latencies []float64
11+
// total bytes read from apiserver
12+
TotalReceivedBytes int64
13+
}
14+
15+
type RunnerMetricReport struct {
716
// Total represents total number of requests.
817
Total int
918
// List of failures
1019
FailureList []error
1120
// Duration means the time of benchmark.
1221
Duration time.Duration
13-
// PercentileLatencies represents the latency distribution in seconds.
14-
//
15-
// NOTE: The key represents quantile.
16-
PercentileLatencies map[float64]float64
22+
// All the observed latencies
23+
Latencies []float64
1724
// total bytes read from apiserver
1825
TotalReceivedBytes int64
19-
// TODO:
20-
// 1. Support failures partitioned by http code and verb
21-
// 2. Support to dump all latency data
26+
// PercentileLatencies represents the latency distribution in seconds.
27+
PercentileLatencies [][2]float64 // [2]float64{percentile, value}
2228
}

cmd/kperf/commands/runner/runner.go

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ package runner
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"os"
87
"path/filepath"
9-
"sort"
10-
"strconv"
118

129
"github.com/Azure/kperf/api/types"
1310
"github.com/Azure/kperf/request"
@@ -86,7 +83,7 @@ var runCommand = cli.Command{
8683
kubeCfgPath := cliCtx.String("kubeconfig")
8784
userAgent := cliCtx.String("user-agent")
8885
outputFilePath := cliCtx.String("result")
89-
rawData := cliCtx.Bool("raw-data")
86+
//rawData := cliCtx.Bool("raw-data")
9087

9188
conns := profileCfg.Spec.Conns
9289
rate := profileCfg.Spec.Rate
@@ -118,7 +115,9 @@ var runCommand = cli.Command{
118115
}
119116
defer f.Close()
120117
}
121-
printResponseStats(f, stats, rawData)
118+
119+
//TODO: add printResponseStats for .json format
120+
printResponseStats(f, stats)
122121
return nil
123122
},
124123
}
@@ -158,76 +157,7 @@ func loadConfig(cliCtx *cli.Context) (*types.LoadProfile, error) {
158157
return &profileCfg, nil
159158
}
160159

161-
func printResponseStats(f *os.File, stats *types.ResponseStats, rawData bool) {
162-
percentileLatencies := make(map[string]string)
163-
for i, v := range stats.PercentileLatencies {
164-
iCopy := strconv.FormatFloat(i, 'f', 2, 64)
165-
percentileLatencies[iCopy] = strconv.FormatFloat(v, 'f', 3, 64)
166-
}
167-
168-
if rawData {
169-
total, err := json.MarshalIndent(stats.Total, "", " ")
170-
if err != nil {
171-
fmt.Println(err)
172-
return
173-
}
174-
fList, err := json.MarshalIndent(stats.FailureList, "", " ")
175-
if err != nil {
176-
fmt.Println(err)
177-
return
178-
}
179-
bytes, err := json.MarshalIndent(stats.TotalReceivedBytes, "", " ")
180-
if err != nil {
181-
fmt.Println(err)
182-
return
183-
}
184-
duration, err := json.MarshalIndent(stats.Duration, "", " ")
185-
if err != nil {
186-
fmt.Println(err)
187-
return
188-
}
189-
pLatencies, err := json.MarshalIndent(percentileLatencies, "", " ")
190-
if err != nil {
191-
fmt.Println(err)
192-
return
193-
}
194-
fmt.Fprint(f, "{\n")
195-
fmt.Fprintf(f, " \"Total\": %s,\n", string(total))
196-
fmt.Fprintf(f, " \"Failure List\": %s,\n", string(fList))
197-
fmt.Fprintf(f, " \"Total Received Bytes\":%s,\n", string(bytes))
198-
fmt.Fprintf(f, " \"Duration\":%s,\n", string(duration))
199-
fmt.Fprintf(f, " \"Percentile Latencies\":%s,\n", pLatencies)
200-
fmt.Fprint(f, "}")
201-
202-
} else {
203-
fmt.Fprint(f, "Response Stat: \n")
204-
fmt.Fprintf(f, " Total: %v\n", stats.Total)
205-
206-
fmt.Fprintf(f, " Total Failures: %d\n", len(stats.FailureList))
207-
208-
for _, v := range stats.FailureList {
209-
fmt.Fprintf(f, " %v\n", v)
210-
}
211-
212-
fmt.Fprintf(f, " Observed Bytes: %v\n", stats.TotalReceivedBytes)
213-
214-
fmt.Fprintf(f, " Duration: %v\n", stats.Duration.String())
215-
216-
requestsPerSec := float64(stats.Total) / stats.Duration.Seconds()
217-
218-
fmt.Fprintf(f, " Requests/sec: %.2f\n", requestsPerSec)
219-
220-
fmt.Fprint(f, " Latency Distribution:\n")
221-
keys := make([]float64, 0, len(stats.PercentileLatencies))
222-
for q := range stats.PercentileLatencies {
223-
keys = append(keys, q)
224-
}
225-
226-
sort.Float64s(keys)
227-
228-
for _, q := range keys {
229-
fmt.Fprintf(f, " [%.2f] %.3fs\n", q/100.0, stats.PercentileLatencies[q])
230-
}
231-
}
160+
// TODO: Complete this function
161+
func printResponseStats(f *os.File, stats *request.Result) {
232162

233163
}

metrics/request.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"sort"
77
"sync"
88
"sync/atomic"
9+
10+
"github.com/Azure/kperf/api/types"
911
)
1012

1113
// ResponseMetric is a measurement related to http response.
@@ -17,7 +19,7 @@ type ResponseMetric interface {
1719
// ObserveReceivedBytes observes the bytes read from apiserver.
1820
ObserveReceivedBytes(bytes int64)
1921
// Gather returns the summary.
20-
Gather() (latencies []float64, percentileLatencies map[float64]float64, failureList []error, bytes int64)
22+
Gather() types.ResponseStats
2123
}
2224

2325
type responseMetricImpl struct {
@@ -55,9 +57,14 @@ func (m *responseMetricImpl) ObserveReceivedBytes(bytes int64) {
5557
}
5658

5759
// Gather implements ResponseMetric.
58-
func (m *responseMetricImpl) Gather() ([]float64, map[float64]float64, []error, int64) {
60+
func (m *responseMetricImpl) Gather() types.ResponseStats {
5961
latencies := m.dumpLatencies()
60-
return latencies, buildPercentileLatencies(latencies), m.failureList, atomic.LoadInt64(&m.receivedBytes)
62+
return types.ResponseStats{
63+
FailureList: m.failureList,
64+
Latencies: latencies,
65+
TotalReceivedBytes: atomic.LoadInt64(&m.receivedBytes),
66+
}
67+
//return latencies, buildPercentileLatencies(latencies), m.failureList, atomic.LoadInt64(&m.receivedBytes)
6168
}
6269

6370
func (m *responseMetricImpl) dumpLatencies() []float64 {

metrics/request_test.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

request/schedule.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@ import (
1616

1717
const defaultTimeout = 60 * time.Second
1818

19+
// Result contains responseStats vlaues from Gather() and adds Duration and Total values separately
20+
type Result struct {
21+
types.ResponseStats
22+
// Duration means the time of benchmark.
23+
Duration time.Duration
24+
// Total means the total number of requests.
25+
Total int
26+
}
27+
1928
// Schedule files requests to apiserver based on LoadProfileSpec.
20-
func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.Interface) (*types.ResponseStats, error) {
29+
func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.Interface) (*Result, error) {
2130
ctx, cancel := context.WithCancel(ctx)
2231
defer cancel()
2332

@@ -81,12 +90,10 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
8190
wg.Wait()
8291

8392
totalDuration := time.Since(start)
84-
_, percentileLatencies, failureList, bytes := respMetric.Gather()
85-
return &types.ResponseStats{
86-
Total: spec.Total,
87-
FailureList: failureList,
88-
Duration: totalDuration,
89-
TotalReceivedBytes: bytes,
90-
PercentileLatencies: percentileLatencies,
93+
responseStats := respMetric.Gather()
94+
return &Result{
95+
ResponseStats: responseStats,
96+
Duration: totalDuration,
97+
Total: spec.Total,
9198
}, nil
9299
}

0 commit comments

Comments
 (0)