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

Commit 6ff9ce8

Browse files
committed
Start to consolidate memcached helper functions
1 parent 9318ba5 commit 6ff9ce8

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
@@ -24,8 +24,10 @@ use testutils::builder::Machine;
2424
use testutils::rackscale_runner::{RackscaleBench, RackscaleRun};
2525
use testutils::runner_args::RackscaleTransport;
2626

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

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

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

574519
// Append parsed results to a CSV file
575520
let write_headers = !Path::new(file_name).exists();
@@ -589,8 +534,14 @@ fn rackscale_memcached_benchmark(transport: RackscaleTransport) {
589534
let r = csv_file.write(format!("{},", env!("GIT_HASH")).as_bytes());
590535
assert!(r.is_ok());
591536
let out = format!(
592-
"memcached,{},{},{},{},{},{},{}",
593-
b_threads, b_mem, b_queries, b_time, b_thpt, actual_num_clients, num_clients
537+
"memcached_internal,{},{},{},{},{},{},{}",
538+
ret.b_threads,
539+
ret.b_mem,
540+
ret.b_queries,
541+
ret.b_time,
542+
ret.b_thpt,
543+
actual_num_clients,
544+
num_clients
594545
);
595546
let r = csv_file.write(out.as_bytes());
596547
assert!(r.is_ok());
@@ -681,171 +632,6 @@ fn rackscale_memcached_benchmark(transport: RackscaleTransport) {
681632
bench.run_bench(false, is_smoke);
682633
}
683634

684-
#[derive(Clone)]
685-
struct MemcachedShardedConfig {
686-
pub num_servers: usize,
687-
pub num_queries: usize,
688-
pub is_local_host: bool,
689-
pub mem_size: usize,
690-
pub protocol: &'static str,
691-
pub num_threads: usize,
692-
pub path: PathBuf,
693-
}
694-
695-
#[derive(Clone, Debug)]
696-
struct MemcachedShardedResult {
697-
b_threads: String,
698-
b_mem: String,
699-
b_queries: String,
700-
b_time: String,
701-
b_thpt: String,
702-
}
703-
704-
fn parse_memcached_output(
705-
p: &mut PtySession,
706-
output: &mut String,
707-
) -> Result<MemcachedShardedResult> {
708-
// x_benchmark_mem = 10 MB
709-
let (prev, matched) = p.exp_regex(r#"x_benchmark_mem = (\d+) MB"#)?;
710-
// println!("> {}", matched);
711-
let b_mem = matched.replace("x_benchmark_mem = ", "").replace(" MB", "");
712-
713-
*output += prev.as_str();
714-
*output += matched.as_str();
715-
716-
// number of threads: 3
717-
let (prev, matched) = p.exp_regex(r#"number of threads: (\d+)"#)?;
718-
// println!("> {}", matched);
719-
let b_threads = matched.replace("number of threads: ", "");
720-
721-
*output += prev.as_str();
722-
*output += matched.as_str();
723-
724-
// number of keys: 131072
725-
let (prev, matched) = p.exp_regex(r#"number of keys: (\d+)"#)?;
726-
// println!("> {}", matched);
727-
728-
*output += prev.as_str();
729-
*output += matched.as_str();
730-
731-
// benchmark took 129 seconds
732-
let (prev, matched) = p.exp_regex(r#"benchmark took (\d+) ms"#)?;
733-
// println!("> {}", matched);
734-
let b_time = matched.replace("benchmark took ", "").replace(" ms", "");
735-
736-
*output += prev.as_str();
737-
*output += matched.as_str();
738-
739-
// benchmark took 7937984 queries / second
740-
let (prev, matched) = p.exp_regex(r#"benchmark took (\d+) queries / second"#)?;
741-
println!("> {}", matched);
742-
let b_thpt = matched
743-
.replace("benchmark took ", "")
744-
.replace(" queries / second", "");
745-
746-
*output += prev.as_str();
747-
*output += matched.as_str();
748-
749-
let (prev, matched) = p.exp_regex(r#"benchmark executed (\d+)"#)?;
750-
println!("> {}", matched);
751-
let b_queries = matched
752-
.replace("benchmark executed ", "")
753-
.split(" ")
754-
.next()
755-
.unwrap()
756-
.to_string();
757-
758-
*output += prev.as_str();
759-
*output += matched.as_str();
760-
761-
if output.contains("MEMORY ALLOCATION FAILURE") {
762-
println!("Detected memory allocation error in memcached output");
763-
Err("Memory allocation failure".into())
764-
} else {
765-
Ok(MemcachedShardedResult {
766-
b_threads,
767-
b_mem,
768-
b_queries,
769-
b_time,
770-
b_thpt,
771-
})
772-
}
773-
}
774-
775-
#[cfg(not(feature = "baremetal"))]
776-
fn rackscale_memcached_checkout() {
777-
let out_dir_path = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("sharded-memcached");
778-
779-
let out_dir = out_dir_path.display().to_string();
780-
781-
println!("CARGO_TARGET_TMPDIR {:?}", out_dir);
782-
783-
// clone abd build the benchmark
784-
if !out_dir_path.is_dir() {
785-
println!("RMDIR {:?}", out_dir_path);
786-
Command::new(format!("rm",))
787-
.args(&["-rf", out_dir.as_str()])
788-
.status()
789-
.unwrap();
790-
791-
println!("MKDIR {:?}", out_dir_path);
792-
Command::new(format!("mkdir",))
793-
.args(&["-p", out_dir.as_str()])
794-
.status()
795-
.unwrap();
796-
797-
println!("CLONE {:?}", out_dir_path);
798-
let url = "https://github.com/achreto/memcached-bench.git";
799-
Command::new("git")
800-
.args(&["clone", "--depth=1", url, out_dir.as_str()])
801-
.output()
802-
.expect("failed to clone");
803-
} else {
804-
Command::new("git")
805-
.args(&["pull"])
806-
.current_dir(out_dir_path.as_path())
807-
.output()
808-
.expect("failed to pull");
809-
}
810-
811-
println!(
812-
"CHECKOUT a703eedd8032ff1e083e8c5972eacc95738c797b {:?}",
813-
out_dir
814-
);
815-
816-
let res = Command::new("git")
817-
.args(&["checkout", "a703eedd8032ff1e083e8c5972eacc95738c797b"])
818-
.current_dir(out_dir_path.as_path())
819-
.output()
820-
.expect("git checkout failed");
821-
if !res.status.success() {
822-
std::io::stdout().write_all(&res.stdout).unwrap();
823-
std::io::stderr().write_all(&res.stderr).unwrap();
824-
panic!("git checkout failed!");
825-
}
826-
827-
println!("BUILD {:?}", out_dir_path);
828-
for (key, value) in env::vars() {
829-
println!("{}: {}", key, value);
830-
}
831-
832-
let build_args = &["-j", "8"];
833-
834-
// now build the benchmark
835-
let status = Command::new("make")
836-
.args(build_args)
837-
.current_dir(&out_dir_path)
838-
.output()
839-
.expect("Can't make app dir");
840-
841-
if !status.status.success() {
842-
println!("BUILD FAILED");
843-
std::io::stdout().write_all(&status.stdout).unwrap();
844-
std::io::stderr().write_all(&status.stderr).unwrap();
845-
panic!("BUILD FAILED");
846-
}
847-
}
848-
849635
#[test]
850636
#[cfg(not(feature = "baremetal"))]
851637
fn s11_rackscale_memcached_benchmark_sharded_linux() {
@@ -857,7 +643,7 @@ fn s11_rackscale_memcached_benchmark_sharded_linux() {
857643
let out_dir_path = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("sharded-memcached");
858644
let is_smoke = cfg!(feature = "smoke");
859645

860-
rackscale_memcached_checkout();
646+
rackscale_memcached_checkout(env!("CARGO_TARGET_TMPDIR"));
861647

862648
// stuff has been built, now we can run the benchmark
863649
let mut config = if is_smoke {
@@ -1128,7 +914,7 @@ fn s11_rackscale_memcached_benchmark_sharded_nros() {
1128914
let out_dir_path = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("sharded-memcached");
1129915
let is_smoke = cfg!(feature = "smoke");
1130916

1131-
rackscale_memcached_checkout();
917+
rackscale_memcached_checkout(env!("CARGO_TARGET_TMPDIR"));
1132918

1133919
// stuff has been built, now we can run the benchmark
1134920
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)