From 5f72a1f6fa00dc744b4654579bd6b2c3cf95ca51 Mon Sep 17 00:00:00 2001 From: SanHalacogluImproving Date: Fri, 13 Oct 2023 14:02:41 -0700 Subject: [PATCH] -Implemented writing results in json format to be transformed into csv -Refactored TestClientSetGet --- benchmarks/utilities/csv_exporter.py | 2 +- go/benchmarks/benchmark.go | 41 ++++++++++++++++-- go/benchmarks/benchmarkconfig.go | 10 ++++- go/benchmarks/main/benchmarkApp/main.go | 56 +++++++++++++++++++------ 4 files changed, 89 insertions(+), 20 deletions(-) diff --git a/benchmarks/utilities/csv_exporter.py b/benchmarks/utilities/csv_exporter.py index a9f1131729..e2a83e6811 100644 --- a/benchmarks/utilities/csv_exporter.py +++ b/benchmarks/utilities/csv_exporter.py @@ -39,7 +39,7 @@ json_file_name = os.path.basename(json_file_full_path) - languages = ["csharp", "node", "python", "rust"] + languages = ["csharp", "node", "python", "rust", "go"] language = next( (language for language in languages if language in json_file_name), None ) diff --git a/go/benchmarks/benchmark.go b/go/benchmarks/benchmark.go index 1023879d0a..a5aa86e1e2 100644 --- a/go/benchmarks/benchmark.go +++ b/go/benchmarks/benchmark.go @@ -1,6 +1,7 @@ package benchmarks import ( + "encoding/json" "fmt" "math" "math/rand" @@ -23,11 +24,13 @@ type actionLatency struct { type operations func(client Client) (string, error) var chosenActionOptions = chosenActions{ - getExisting: "Get_Existing", - getNonExisting: "Get_Non_Existing", - set: "Set", + getExisting: "get_existing", + getNonExisting: "get_non_existing", + set: "set", } +var jsonResults = make([]map[string]interface{}, 0) + const probGet = 0.8 const probGetExistingKey = 0.8 const sizeNewKeyspace = 3750000 @@ -215,7 +218,7 @@ func getKeysInSortedOrderForPrint(m map[string]latencyResults) []string { return keys } -func PrintResults(tps float64, resultMap map[string]latencyResults, benchmarkConfig *BenchmarkConfig, resultsFile *os.File) { +func PrintResultsStdOut(benchmarkConfig *BenchmarkConfig, resultMap map[string]latencyResults, tps float64, resultsFile *os.File) { writeFileOrPanic(resultsFile, fmt.Sprintf("Client Name: %s, Tasks Count: %d, Data Size: %d, Client Count: %d, TPS: %f\n", benchmarkConfig.ClientName, benchmarkConfig.TasksCount, benchmarkConfig.DataSize, benchmarkConfig.ClientCount, tps)) keys := getKeysInSortedOrderForPrint(resultMap) @@ -230,6 +233,36 @@ func PrintResults(tps float64, resultMap map[string]latencyResults, benchmarkCon } } +func AddResultsJsonFormat(benchmarkConfig *BenchmarkConfig, results map[string]latencyResults, tps float64) { + jsonResult := make(map[string]interface{}) + + jsonResult["client"] = benchmarkConfig.ClientName + jsonResult["is_cluster"] = benchmarkConfig.IsCluster + jsonResult["num_of_tasks"] = benchmarkConfig.TasksCount + jsonResult["data_size"] = benchmarkConfig.DataSize + jsonResult["clientCount"] = benchmarkConfig.ClientCount + jsonResult["tps"] = tps + + for key, value := range results { + jsonResult[key+"_p50_latency"] = float64(value.p50Latency) / 1e6 + jsonResult[key+"_p90_latency"] = float64(value.p90Latency) / 1e6 + jsonResult[key+"_p99_latency"] = float64(value.p99Latency) / 1e6 + jsonResult[key+"_average_latency"] = float64(value.avgLatency) / 1e6 + jsonResult[key+"_std_dev"] = float64(value.stdDeviation) / 1e6 + } + + jsonResults = append(jsonResults, jsonResult) +} + +func ProcessResults(file *os.File) error { + encoder := json.NewEncoder(file) + err := encoder.Encode(jsonResults) + if err != nil { + return fmt.Errorf("error encoding JSON: %v", err) + } + return nil +} + func MeasurePerformance(clients []Client, concurrentTasks int, dataSize int) (float64, map[string]latencyResults) { iterations := numberOfIterations(concurrentTasks) actions := getActions(dataSize) diff --git a/go/benchmarks/benchmarkconfig.go b/go/benchmarks/benchmarkconfig.go index 104fded5fe..f891fae253 100644 --- a/go/benchmarks/benchmarkconfig.go +++ b/go/benchmarks/benchmarkconfig.go @@ -5,8 +5,14 @@ type BenchmarkConfig struct { TasksCount int DataSize int ClientCount int + IsCluster bool } -func NewBenchmarkConfig(clientName string, tasksCount int, dataSize int, clientCount int) *BenchmarkConfig { - return &BenchmarkConfig{ClientName: clientName, TasksCount: tasksCount, DataSize: dataSize, ClientCount: clientCount} +func NewBenchmarkConfig(clientName string, tasksCount int, dataSize int, clientCount int, isCluster bool) *BenchmarkConfig { + return &BenchmarkConfig{ + ClientName: clientName, + TasksCount: tasksCount, + DataSize: dataSize, + ClientCount: clientCount, + IsCluster: isCluster} } diff --git a/go/benchmarks/main/benchmarkApp/main.go b/go/benchmarks/main/benchmarkApp/main.go index 37bd5f43b5..30ef8daa71 100644 --- a/go/benchmarks/main/benchmarkApp/main.go +++ b/go/benchmarks/main/benchmarkApp/main.go @@ -171,26 +171,30 @@ func verifyOptions(opts *options) (*runConfiguration, error) { func testClientSetGet(runConfig *runConfiguration) error { fmt.Printf("\n =====> %s <===== \n\n", runConfig.clientName) + connectionSettings := benchmarks.NewConnectionSettings( runConfig.host, runConfig.port, - runConfig.tls) + runConfig.tls, + ) + + err := executeBenchmarks(runConfig, connectionSettings) + if err != nil { + return err + } + + if runConfig.resultsFile != os.Stdout { + return benchmarks.ProcessResults(runConfig.resultsFile) + } + return nil +} + +func executeBenchmarks(runConfig *runConfiguration, connectionSettings *benchmarks.ConnectionSettings) error { for _, dataSize := range runConfig.dataSize { for _, concurrentTasks := range runConfig.concurrentTasks { for _, clientCount := range runConfig.clientCount { - clients, err := createClients(clientCount, runConfig.clientName, connectionSettings) - if err != nil { - return err - } - tps, latencyResults := benchmarks.MeasurePerformance(clients, concurrentTasks, dataSize) - benchmarkConfig := benchmarks.NewBenchmarkConfig( - runConfig.clientName, - concurrentTasks, - dataSize, - clientCount) - benchmarks.PrintResults(tps, latencyResults, benchmarkConfig, runConfig.resultsFile) - err = closeClients(clients) + err := runSingleBenchmark(runConfig, connectionSettings, dataSize, concurrentTasks, clientCount) if err != nil { return err } @@ -200,6 +204,32 @@ func testClientSetGet(runConfig *runConfiguration) error { return nil } +func runSingleBenchmark(runConfig *runConfiguration, connectionSettings *benchmarks.ConnectionSettings, dataSize, concurrentTasks, clientCount int) error { + fmt.Printf("Starting %s data size: %d concurrency: %d client count: %d\n", runConfig.clientName, dataSize, concurrentTasks, clientCount) + + clients, err := createClients(clientCount, runConfig.clientName, connectionSettings) + if err != nil { + return err + } + + tps, latencyResults := benchmarks.MeasurePerformance(clients, concurrentTasks, dataSize) + benchmarkConfig := benchmarks.NewBenchmarkConfig( + runConfig.clientName, + concurrentTasks, + dataSize, + clientCount, + false, + ) + + if runConfig.resultsFile == os.Stdout { + benchmarks.PrintResultsStdOut(benchmarkConfig, latencyResults, tps, runConfig.resultsFile) + } else { + benchmarks.AddResultsJsonFormat(benchmarkConfig, latencyResults, tps) + } + + return closeClients(clients) +} + func createClients(clientCount int, clientType string, connectionSettings *benchmarks.ConnectionSettings) ([]benchmarks.Client, error) { var clients []benchmarks.Client