diff --git a/Makefile b/Makefile index b12ada5..f20217c 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ coverage: get test $(GOTEST) -race -coverprofile=coverage.txt -covermode=atomic . flow-test: build-race - ./$(BIN_NAME) -n 100000 -query "CREATE(n)" -query-ratio 1 -query "MATCH (n) RETURN n LIMIT 1" -query-ratio 2 + ./$(BIN_NAME) -n 100000 -query "CREATE(n)" -query-ratio 0.33 -query "MATCH (n) RETURN n LIMIT 1" -query-ratio 0.67 release: $(GOGET) github.com/mitchellh/gox diff --git a/cli.go b/cli.go index dac6941..2f9270e 100644 --- a/cli.go +++ b/cli.go @@ -20,7 +20,7 @@ func (i *arrayStringParameters) Set(value string) error { return nil } -func printFinalSummary(queries []string, queryRates []int, totalMessages uint64, duration time.Duration) { +func printFinalSummary(queries []string, queryRates []float64, totalMessages uint64, duration time.Duration) { writer := os.Stdout messageRate := float64(totalMessages) / float64(duration.Seconds()) diff --git a/multi-query.go b/multi-query.go index 594b358..c4a6939 100644 --- a/multi-query.go +++ b/multi-query.go @@ -15,9 +15,9 @@ func sample(cdf []float32) int { return bucket } -func prepareCommandsDistribution(cmds []string, cmdRates []int) (int, []float32) { - var totalRates int = 0 +func prepareCommandsDistribution(cmds []string, cmdRates []float64) (int, []float32) { var totalDifferentCommands = len(cmds) + var totalRateSum = 0.0 var err error for i, rawCmdString := range benchmarkQueries { cmds[i] = rawCmdString @@ -25,12 +25,16 @@ func prepareCommandsDistribution(cmds []string, cmdRates []int) (int, []float32) cmdRates[i] = 1 } else { - cmdRates[i], err = strconv.Atoi(benchmarkQueryRates[i]) + cmdRates[i], err = strconv.ParseFloat(benchmarkQueryRates[i], 64) if err != nil { log.Fatalf("Error while converting query-rate param %s: %v", benchmarkQueryRates[i], err) } } - totalRates += cmdRates[i] + totalRateSum += cmdRates[i] + } + // probability density function + if totalRateSum != 1.0 { + log.Fatalf("Total ratio should be 1.0 ( currently is %f )", totalRateSum) } // probability density function if len(benchmarkQueryRates) > 0 && (len(benchmarkQueryRates) != len(benchmarkQueries)) { @@ -39,7 +43,7 @@ func prepareCommandsDistribution(cmds []string, cmdRates []int) (int, []float32) pdf := make([]float32, len(benchmarkQueries)) cdf := make([]float32, len(benchmarkQueries)) for i := 0; i < len(cmdRates); i++ { - pdf[i] = float32(cmdRates[i]) / float32(totalRates) + pdf[i] = float32(cmdRates[i]) cdf[i] = 0 } // get cdf diff --git a/redisgraph-bechmark-go.go b/redisgraph-bechmark-go.go index d388f62..55a4a84 100644 --- a/redisgraph-bechmark-go.go +++ b/redisgraph-bechmark-go.go @@ -65,7 +65,7 @@ func main() { fmt.Printf("Running in loop until you hit Ctrl+C\n") } queries := make([]string, len(benchmarkQueries)) - cmdRates := make([]int, len(benchmarkQueries)) + cmdRates := make([]float64, len(benchmarkQueries)) totalDifferentCommands, cdf := prepareCommandsDistribution(queries, cmdRates) createRequiredGlobalStructs(totalDifferentCommands) @@ -113,8 +113,8 @@ func main() { testResult.FillDurationInfo(startTime, endTime, duration) testResult.BenchmarkFullyRun = totalCommands == *numberRequests testResult.IssuedCommands = totalCommands - testResult.OverallGraphInternalQuantiles = GetOverallQuantiles(queries, serverSide_PerQuery_GraphInternalTime_OverallLatencies, serverSide_AllQueries_GraphInternalTime_OverallLatencies) - testResult.OverallClientQuantiles = GetOverallQuantiles(queries, clientSide_PerQuery_OverallLatencies, clientSide_AllQueries_OverallLatencies) + testResult.OverallGraphInternalLatencies = GetOverallLatencies(queries, serverSide_PerQuery_GraphInternalTime_OverallLatencies, serverSide_AllQueries_GraphInternalTime_OverallLatencies) + testResult.OverallClientLatencies = GetOverallLatencies(queries, clientSide_PerQuery_OverallLatencies, clientSide_AllQueries_OverallLatencies) testResult.OverallQueryRates = GetOverallRatesMap(duration, queries, clientSide_PerQuery_OverallLatencies, clientSide_AllQueries_OverallLatencies) testResult.Totals = GetTotalsMap(queries, clientSide_PerQuery_OverallLatencies, clientSide_AllQueries_OverallLatencies, errorsPerQuery, totalNodesCreatedPerQuery, totalNodesDeletedPerQuery, totalLabelsAddedPerQuery, totalPropertiesSetPerQuery, totalRelationshipsCreatedPerQuery, totalRelationshipsDeletedPerQuery) diff --git a/test_result.go b/test_result.go index 3cd000a..3cd5d78 100644 --- a/test_result.go +++ b/test_result.go @@ -58,10 +58,10 @@ type TestResult struct { OverallQueryRates map[string]interface{} `json:"OverallQueryRates"` // Overall Client Quantiles - OverallClientQuantiles map[string]interface{} `json:"OverallClientQuantiles"` + OverallClientLatencies map[string]interface{} `json:"OverallClientLatencies"` // Overall Graph Internal Quantiles - OverallGraphInternalQuantiles map[string]interface{} `json:"OverallGraphInternalQuantiles"` + OverallGraphInternalLatencies map[string]interface{} `json:"OverallGraphInternalLatencies"` // Per second ( tick ) client stats ClientRunTimeStats map[int64]interface{} `json:"ClientRunTimeStats"` @@ -165,7 +165,7 @@ func calculateRateMetrics(current, prev int64, took time.Duration) (rate float64 return } -func generateQuantileMap(hist *hdrhistogram.Histogram) (int64, map[string]float64) { +func generateLatenciesMap(hist *hdrhistogram.Histogram) (int64, map[string]float64) { ops := hist.TotalCount() q0 := 0.0 q50 := 0.0 @@ -173,6 +173,7 @@ func generateQuantileMap(hist *hdrhistogram.Histogram) (int64, map[string]float6 q99 := 0.0 q999 := 0.0 q100 := 0.0 + average := 0.0 if ops > 0 { q0 = float64(hist.ValueAtQuantile(0.0)) / 10e2 q50 = float64(hist.ValueAtQuantile(50.0)) / 10e2 @@ -180,19 +181,20 @@ func generateQuantileMap(hist *hdrhistogram.Histogram) (int64, map[string]float6 q99 = float64(hist.ValueAtQuantile(99.0)) / 10e2 q999 = float64(hist.ValueAtQuantile(99.90)) / 10e2 q100 = float64(hist.ValueAtQuantile(100.0)) / 10e2 + average = (hist.Mean() / float64(1000.0)) } - mp := map[string]float64{"q0": q0, "q50": q50, "q95": q95, "q99": q99, "q999": q999, "q100": q100} + mp := map[string]float64{"q0": q0, "q50": q50, "q95": q95, "q99": q99, "q999": q999, "q100": q100, "avg": average} return ops, mp } -func GetOverallQuantiles(cmds []string, perQueryHistograms []*hdrhistogram.Histogram, totalsHistogram *hdrhistogram.Histogram) map[string]interface{} { +func GetOverallLatencies(cmds []string, perQueryHistograms []*hdrhistogram.Histogram, totalsHistogram *hdrhistogram.Histogram) map[string]interface{} { perQueryQuantileMap := map[string]interface{}{} for i, query := range cmds { - _, quantileMap := generateQuantileMap(perQueryHistograms[i]) + _, quantileMap := generateLatenciesMap(perQueryHistograms[i]) perQueryQuantileMap[query] = quantileMap } - _, totalMap := generateQuantileMap(totalsHistogram) + _, totalMap := generateLatenciesMap(totalsHistogram) perQueryQuantileMap["Total"] = totalMap return perQueryQuantileMap }