Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit c783254

Browse files
committed
Start to consolidate memcached helper functions
1 parent 39e84fb commit c783254

File tree

5 files changed

+192
-238
lines changed

5 files changed

+192
-238
lines changed

kernel/tests/s10_benchmarks.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use serde::Serialize;
2222

2323
use testutils::builder::{BuildArgs, Machine};
2424
use testutils::helpers::{setup_network, spawn_dhcpd, spawn_nrk, DHCP_ACK_MATCH};
25+
use testutils::memcached::{MEMCACHED_MEM_SIZE_MB, MEMCACHED_NUM_QUERIES};
2526
use testutils::redis::{redis_benchmark, REDIS_BENCHMARK, REDIS_START_MATCH};
2627
use testutils::runner_args::{check_for_successful_exit, wait_for_sigterm, RunnerArgs};
2728

@@ -872,9 +873,6 @@ fn s10_leveldb_benchmark() {
872873
}
873874
}
874875

875-
use testutils::configs::MEMCACHED_MEM_SIZE_MB;
876-
use testutils::configs::MEMCACHED_NUM_QUERIES;
877-
878876
#[test]
879877
fn s10_memcached_benchmark_internal() {
880878
setup_network(1);

kernel/tests/s11_rackscale_benchmarks.rs

Lines changed: 15 additions & 229 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ use testutils::helpers::{DCMConfig, DCMSolver};
2525
use testutils::rackscale_runner::{RackscaleBench, RackscaleRun};
2626
use testutils::runner_args::RackscaleTransport;
2727

28-
use testutils::configs::MEMCACHED_MEM_SIZE_MB;
29-
use testutils::configs::MEMCACHED_NUM_QUERIES;
28+
use testutils::memcached::{
29+
parse_memcached_output, rackscale_memcached_checkout, MemcachedShardedConfig,
30+
MEMCACHED_MEM_SIZE_MB, MEMCACHED_NUM_QUERIES,
31+
};
3032

3133
#[test]
3234
#[cfg(not(feature = "baremetal"))]
@@ -513,64 +515,7 @@ fn rackscale_memcached_benchmark(transport: RackscaleTransport) {
513515
*output += prev.as_str();
514516
*output += matched.as_str();
515517

516-
// x_benchmark_mem = 10 MB
517-
let (prev, matched) = proc.exp_regex(r#"x_benchmark_mem = (\d+) MB"#)?;
518-
println!("> {}", matched);
519-
let b_mem = matched.replace("x_benchmark_mem = ", "").replace(" MB", "");
520-
521-
*output += prev.as_str();
522-
*output += matched.as_str();
523-
524-
// number of threads: 3
525-
let (prev, matched) = proc.exp_regex(r#"number of threads: (\d+)"#)?;
526-
println!("> {}", matched);
527-
let b_threads = matched.replace("number of threads: ", "");
528-
529-
*output += prev.as_str();
530-
*output += matched.as_str();
531-
532-
// number of keys: 131072
533-
let (prev, matched) = proc.exp_regex(r#"number of keys: (\d+)"#)?;
534-
println!("> {}", matched);
535-
536-
*output += prev.as_str();
537-
*output += matched.as_str();
538-
539-
let (prev, matched) = proc.exp_regex(r#"Executing (\d+) queries with (\d+) threads"#)?;
540-
println!("> {}", matched);
541-
542-
*output += prev.as_str();
543-
*output += matched.as_str();
544-
545-
// benchmark took 129 seconds
546-
let (prev, matched) = proc.exp_regex(r#"benchmark took (\d+) ms"#)?;
547-
println!("> {}", matched);
548-
let b_time = matched.replace("benchmark took ", "").replace(" ms", "");
549-
550-
*output += prev.as_str();
551-
*output += matched.as_str();
552-
553-
// benchmark took 7937984 queries / second
554-
let (prev, matched) = proc.exp_regex(r#"benchmark took (\d+) queries / second"#)?;
555-
println!("> {}", matched);
556-
let b_thpt = matched
557-
.replace("benchmark took ", "")
558-
.replace(" queries / second", "");
559-
560-
*output += prev.as_str();
561-
*output += matched.as_str();
562-
563-
let (prev, matched) = proc.exp_regex(r#"benchmark executed (\d+)"#)?;
564-
println!("> {}", matched);
565-
let b_queries = matched
566-
.replace("benchmark executed ", "")
567-
.split(" ")
568-
.next()
569-
.unwrap()
570-
.to_string();
571-
572-
*output += prev.as_str();
573-
*output += matched.as_str();
518+
let ret = parse_memcached_output(proc, output)?;
574519

575520
// Append parsed results to a CSV file
576521
let write_headers = !Path::new(file_name).exists();
@@ -590,8 +535,14 @@ fn rackscale_memcached_benchmark(transport: RackscaleTransport) {
590535
let r = csv_file.write(format!("{},", env!("GIT_HASH")).as_bytes());
591536
assert!(r.is_ok());
592537
let out = format!(
593-
"memcached,{},{},{},{},{},{},{}",
594-
b_threads, b_mem, b_queries, b_time, b_thpt, actual_num_clients, num_clients
538+
"memcached_internal,{},{},{},{},{},{},{}",
539+
ret.b_threads,
540+
ret.b_mem,
541+
ret.b_queries,
542+
ret.b_time,
543+
ret.b_thpt,
544+
actual_num_clients,
545+
num_clients
595546
);
596547
let r = csv_file.write(out.as_bytes());
597548
assert!(r.is_ok());
@@ -907,171 +858,6 @@ fn rackscale_memcached_dcm(transport: RackscaleTransport, dcm_config: Option<DCM
907858
}
908859
}
909860

910-
#[derive(Clone)]
911-
struct MemcachedShardedConfig {
912-
pub num_servers: usize,
913-
pub num_queries: usize,
914-
pub is_local_host: bool,
915-
pub mem_size: usize,
916-
pub protocol: &'static str,
917-
pub num_threads: usize,
918-
pub path: PathBuf,
919-
}
920-
921-
#[derive(Clone, Debug)]
922-
struct MemcachedShardedResult {
923-
b_threads: String,
924-
b_mem: String,
925-
b_queries: String,
926-
b_time: String,
927-
b_thpt: String,
928-
}
929-
930-
fn parse_memcached_output(
931-
p: &mut PtySession,
932-
output: &mut String,
933-
) -> Result<MemcachedShardedResult> {
934-
// x_benchmark_mem = 10 MB
935-
let (prev, matched) = p.exp_regex(r#"x_benchmark_mem = (\d+) MB"#)?;
936-
// println!("> {}", matched);
937-
let b_mem = matched.replace("x_benchmark_mem = ", "").replace(" MB", "");
938-
939-
*output += prev.as_str();
940-
*output += matched.as_str();
941-
942-
// number of threads: 3
943-
let (prev, matched) = p.exp_regex(r#"number of threads: (\d+)"#)?;
944-
// println!("> {}", matched);
945-
let b_threads = matched.replace("number of threads: ", "");
946-
947-
*output += prev.as_str();
948-
*output += matched.as_str();
949-
950-
// number of keys: 131072
951-
let (prev, matched) = p.exp_regex(r#"number of keys: (\d+)"#)?;
952-
// println!("> {}", matched);
953-
954-
*output += prev.as_str();
955-
*output += matched.as_str();
956-
957-
// benchmark took 129 seconds
958-
let (prev, matched) = p.exp_regex(r#"benchmark took (\d+) ms"#)?;
959-
// println!("> {}", matched);
960-
let b_time = matched.replace("benchmark took ", "").replace(" ms", "");
961-
962-
*output += prev.as_str();
963-
*output += matched.as_str();
964-
965-
// benchmark took 7937984 queries / second
966-
let (prev, matched) = p.exp_regex(r#"benchmark took (\d+) queries / second"#)?;
967-
println!("> {}", matched);
968-
let b_thpt = matched
969-
.replace("benchmark took ", "")
970-
.replace(" queries / second", "");
971-
972-
*output += prev.as_str();
973-
*output += matched.as_str();
974-
975-
let (prev, matched) = p.exp_regex(r#"benchmark executed (\d+)"#)?;
976-
println!("> {}", matched);
977-
let b_queries = matched
978-
.replace("benchmark executed ", "")
979-
.split(" ")
980-
.next()
981-
.unwrap()
982-
.to_string();
983-
984-
*output += prev.as_str();
985-
*output += matched.as_str();
986-
987-
if output.contains("MEMORY ALLOCATION FAILURE") {
988-
println!("Detected memory allocation error in memcached output");
989-
Err("Memory allocation failure".into())
990-
} else {
991-
Ok(MemcachedShardedResult {
992-
b_threads,
993-
b_mem,
994-
b_queries,
995-
b_time,
996-
b_thpt,
997-
})
998-
}
999-
}
1000-
1001-
#[cfg(not(feature = "baremetal"))]
1002-
fn rackscale_memcached_checkout() {
1003-
let out_dir_path = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("sharded-memcached");
1004-
1005-
let out_dir = out_dir_path.display().to_string();
1006-
1007-
println!("CARGO_TARGET_TMPDIR {:?}", out_dir);
1008-
1009-
// clone abd build the benchmark
1010-
if !out_dir_path.is_dir() {
1011-
println!("RMDIR {:?}", out_dir_path);
1012-
Command::new(format!("rm",))
1013-
.args(&["-rf", out_dir.as_str()])
1014-
.status()
1015-
.unwrap();
1016-
1017-
println!("MKDIR {:?}", out_dir_path);
1018-
Command::new(format!("mkdir",))
1019-
.args(&["-p", out_dir.as_str()])
1020-
.status()
1021-
.unwrap();
1022-
1023-
println!("CLONE {:?}", out_dir_path);
1024-
let url = "https://github.com/achreto/memcached-bench.git";
1025-
Command::new("git")
1026-
.args(&["clone", "--depth=1", url, out_dir.as_str()])
1027-
.output()
1028-
.expect("failed to clone");
1029-
} else {
1030-
Command::new("git")
1031-
.args(&["pull"])
1032-
.current_dir(out_dir_path.as_path())
1033-
.output()
1034-
.expect("failed to pull");
1035-
}
1036-
1037-
println!(
1038-
"CHECKOUT a703eedd8032ff1e083e8c5972eacc95738c797b {:?}",
1039-
out_dir
1040-
);
1041-
1042-
let res = Command::new("git")
1043-
.args(&["checkout", "a703eedd8032ff1e083e8c5972eacc95738c797b"])
1044-
.current_dir(out_dir_path.as_path())
1045-
.output()
1046-
.expect("git checkout failed");
1047-
if !res.status.success() {
1048-
std::io::stdout().write_all(&res.stdout).unwrap();
1049-
std::io::stderr().write_all(&res.stderr).unwrap();
1050-
panic!("git checkout failed!");
1051-
}
1052-
1053-
println!("BUILD {:?}", out_dir_path);
1054-
for (key, value) in env::vars() {
1055-
println!("{}: {}", key, value);
1056-
}
1057-
1058-
let build_args = &["-j", "8"];
1059-
1060-
// now build the benchmark
1061-
let status = Command::new("make")
1062-
.args(build_args)
1063-
.current_dir(&out_dir_path)
1064-
.output()
1065-
.expect("Can't make app dir");
1066-
1067-
if !status.status.success() {
1068-
println!("BUILD FAILED");
1069-
std::io::stdout().write_all(&status.stdout).unwrap();
1070-
std::io::stderr().write_all(&status.stderr).unwrap();
1071-
panic!("BUILD FAILED");
1072-
}
1073-
}
1074-
1075861
#[test]
1076862
#[cfg(not(feature = "baremetal"))]
1077863
fn s11_rackscale_memcached_benchmark_sharded_linux() {
@@ -1083,7 +869,7 @@ fn s11_rackscale_memcached_benchmark_sharded_linux() {
1083869
let out_dir_path = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("sharded-memcached");
1084870
let is_smoke = cfg!(feature = "smoke");
1085871

1086-
rackscale_memcached_checkout();
872+
rackscale_memcached_checkout(env!("CARGO_TARGET_TMPDIR"));
1087873

1088874
// stuff has been built, now we can run the benchmark
1089875
let mut config = if is_smoke {
@@ -1354,7 +1140,7 @@ fn s11_rackscale_memcached_benchmark_sharded_nros() {
13541140
let out_dir_path = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("sharded-memcached");
13551141
let is_smoke = cfg!(feature = "smoke");
13561142

1357-
rackscale_memcached_checkout();
1143+
rackscale_memcached_checkout(env!("CARGO_TARGET_TMPDIR"));
13581144

13591145
// stuff has been built, now we can run the benchmark
13601146
let mut config = if is_smoke {

kernel/testutils/src/configs.rs

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

kernel/testutils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ extern crate rexpect;
99
extern crate serde;
1010

1111
pub mod builder;
12-
pub mod configs;
1312
pub mod helpers;
13+
pub mod memcached;
1414
pub mod rackscale_runner;
1515
pub mod redis;
1616
pub mod runner_args;

0 commit comments

Comments
 (0)