Skip to content

Commit

Permalink
-Implemented writing results in json format to be transformed into csv
Browse files Browse the repository at this point in the history
-Refactored TestClientSetGet
  • Loading branch information
SanHalacogluImproving committed Oct 13, 2023
1 parent 41a3d14 commit 5f72a1f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 20 deletions.
2 changes: 1 addition & 1 deletion benchmarks/utilities/csv_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
41 changes: 37 additions & 4 deletions go/benchmarks/benchmark.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package benchmarks

import (
"encoding/json"
"fmt"
"math"
"math/rand"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions go/benchmarks/benchmarkconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
56 changes: 43 additions & 13 deletions go/benchmarks/main/benchmarkApp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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

Expand Down

0 comments on commit 5f72a1f

Please sign in to comment.