Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go:Fix benchmarking code and improve response side performance #2288

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions go/benchmarks/benchmarking.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func executeBenchmarks(runConfig *runConfiguration, connectionSettings *connecti
return nil
}

var key_count int64 = 1

func runSingleBenchmark(config *benchmarkConfig) error {
fmt.Printf("Running benchmarking for %s client:\n", config.clientName)
fmt.Printf(
Expand Down Expand Up @@ -228,13 +230,13 @@ const (
func getActions(dataSize int) map[string]operations {
actions := map[string]operations{
getExisting: func(client benchmarkClient) (string, error) {
return client.get(keyFromExistingKeyspace())
return client.get(keyFromExistingKeyspace(getExisting))
},
getNonExisting: func(client benchmarkClient) (string, error) {
return client.get(keyFromNewKeyspace())
},
set: func(client benchmarkClient) (string, error) {
return client.set(keyFromExistingKeyspace(), strings.Repeat("0", dataSize))
return client.set(keyFromExistingKeyspace(set), strings.Repeat("0", dataSize))
},
}

Expand All @@ -246,8 +248,15 @@ const (
sizeExistingKeyspace = 3000000
)

func keyFromExistingKeyspace() string {
randNum, err := rand.Int(rand.Reader, big.NewInt(sizeExistingKeyspace))
func keyFromExistingKeyspace(action string) string {
if action == set {

if key_count < sizeNewKeyspace-1 {
key_count = key_count + 1
}
return fmt.Sprint(key_count)
}
randNum, err := rand.Int(rand.Reader, big.NewInt(key_count))
if err != nil {
log.Fatal("Error while generating random number for existing keyspace: ", err)
}
Expand Down
17 changes: 8 additions & 9 deletions go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,30 +362,29 @@ pub unsafe extern "C" fn command(
let result: RedisResult<Option<CommandResponse>> = match value {
Value::Nil => Ok(None),
Value::SimpleString(text) => {
let vec = text.chars().map(|b| b as c_char).collect::<Vec<_>>();
let vec = text.into_bytes();
let (vec_ptr, len) = convert_vec_to_pointer(vec);
command_response.string_value = vec_ptr;
command_response.string_value = vec_ptr as *mut c_char;
command_response.string_value_len = len;
Ok(Some(command_response))
}
Value::BulkString(text) => {
let vec = text.iter().map(|b| *b as c_char).collect::<Vec<_>>();
let (vec_ptr, len) = convert_vec_to_pointer(vec);
command_response.string_value = vec_ptr;
let (vec_ptr, len) = convert_vec_to_pointer(text);
command_response.string_value = vec_ptr as *mut c_char;
command_response.string_value_len = len;
Ok(Some(command_response))
}
Value::VerbatimString { format: _, text } => {
let vec = text.chars().map(|b| b as c_char).collect::<Vec<_>>();
let vec = text.into_bytes();
let (vec_ptr, len) = convert_vec_to_pointer(vec);
command_response.string_value = vec_ptr;
command_response.string_value = vec_ptr as *mut c_char;
command_response.string_value_len = len;
Ok(Some(command_response))
}
Value::Okay => {
let vec = "OK".chars().map(|b| b as c_char).collect::<Vec<_>>();
let vec = String::from("OK").into_bytes();
let (vec_ptr, len) = convert_vec_to_pointer(vec);
command_response.string_value = vec_ptr;
command_response.string_value = vec_ptr as *mut c_char;
command_response.string_value_len = len;
Ok(Some(command_response))
}
Expand Down
Loading