From 922de70d993b8a5eec3e29f5146227f0282aa418 Mon Sep 17 00:00:00 2001 From: Yiheng Tao Date: Tue, 3 Dec 2024 15:16:01 -0800 Subject: [PATCH] Add windows support for benchmark --- evaluation/benchmark/Cargo.toml | 8 ++- evaluation/benchmark/src/capybarakv_client.rs | 15 +++-- evaluation/benchmark/src/config.rs | 26 ++++++++ evaluation/benchmark/src/main.rs | 59 +++++++++++++++---- 4 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 evaluation/benchmark/src/config.rs diff --git a/evaluation/benchmark/Cargo.toml b/evaluation/benchmark/Cargo.toml index 90ae8e48..c6a68a57 100644 --- a/evaluation/benchmark/Cargo.toml +++ b/evaluation/benchmark/Cargo.toml @@ -14,7 +14,9 @@ vstd = { git = "https://github.com/verus-lang/verus.git", rev="a53f39271666ac7dc toml = { version = "0.8.19", features = ["parse"] } serde = { version = "1.0.215", features = ["derive"] } chrono = "0.4.38" -redis = "0.27.5" rand = "0.8.5" -rocksdb = { path = "../rust-rocksdb/" } -num_cpus = "1.16.0" \ No newline at end of file +num_cpus = "1.16.0" + +[target.'cfg(target_os = "linux")'.dependencies] +redis = "0.27.5" +rocksdb = { path = "../rust-rocksdb/" } \ No newline at end of file diff --git a/evaluation/benchmark/src/capybarakv_client.rs b/evaluation/benchmark/src/capybarakv_client.rs index e04a0630..4d8df15d 100644 --- a/evaluation/benchmark/src/capybarakv_client.rs +++ b/evaluation/benchmark/src/capybarakv_client.rs @@ -1,20 +1,19 @@ use storage_node::kv::kvimpl_t::*; +#[cfg(target_os = "linux")] use storage_node::pmem::linux_pmemfile_t::*; +#[cfg(target_os = "windows")] +use storage_node::pmem::windows_pmemfile_t::*; use crate::{Key, Value, KvInterface, init_and_mount_pm_fs, remount_pm_fs, unmount_pm_fs}; use storage_node::pmem::pmcopy_t::*; use storage_node::pmem::traits_t::{ConstPmSized, PmSized, UnsafeSpecPmSized, PmSafe}; use pmsafe::PmCopy; +use crate::config::*; use std::fmt::Debug; use std::hash::Hash; use std::thread::sleep; use std::time::{Duration, Instant}; -// TODO: read these from config file -const KVSTORE_ID: u128 = 1234; -const KVSTORE_FILE: &str = "/mnt/pmem/capybarakv"; -const REGION_SIZE: u64 = 1024*1024*1024*115; - // TODO: should make a capybarakv util crate so that you // can share some of these functions with ycsb_ffi? @@ -109,7 +108,7 @@ fn open_pm_region(file_name: &str, region_size: u64) -> FileBackedPersistentMemo #[cfg(target_os = "windows")] let pm_region = FileBackedPersistentMemoryRegion::restore( &file_name, - MemoryMappedFileMediaType::SSD, + MemoryMappedFileMediaType::BatteryBackedDRAM, region_size, ).unwrap(); #[cfg(target_os = "linux")] @@ -126,9 +125,9 @@ fn create_pm_region(file_name: &str, region_size: u64) -> FileBackedPersistentMe { #[cfg(target_os = "windows")] let pm_region = FileBackedPersistentMemoryRegion::new( - &file_name, MemoryMappedFileMediaType::SSD, + &file_name, MemoryMappedFileMediaType::BatteryBackedDRAM, region_size, - FileCloseBehavior::TestingSoDeleteOnClose + FileCloseBehavior::Persistent ).unwrap(); #[cfg(target_os = "linux")] let pm_region = FileBackedPersistentMemoryRegion::new( diff --git a/evaluation/benchmark/src/config.rs b/evaluation/benchmark/src/config.rs new file mode 100644 index 00000000..740268ab --- /dev/null +++ b/evaluation/benchmark/src/config.rs @@ -0,0 +1,26 @@ +#[cfg(target_os = "linux")] +pub const PM_DEV: &str = "/dev/pmem0"; +#[cfg(target_os = "linux")] +pub const MOUNT_POINT: &str = "/mnt/pmem"; +#[cfg(target_os = "linux")] +pub const KVSTORE_FILE: &str = "/mnt/pmem/capybarakv"; + +#[cfg(target_os = "windows")] +pub const PM_DEV: &str = "C:\\pmem"; +#[cfg(target_os = "windows")] +pub const MOUNT_POINT: &str = PM_DEV; +#[cfg(target_os = "windows")] +pub const KVSTORE_FILE: &str = "C:\\pmem\\capybarakv"; + +// TODO: read these from config file +pub const KVSTORE_ID: u128 = 1234; +pub const REGION_SIZE: u64 = 1024*1024*1024*15; + +// TODO: read these from a config file? +pub const NUM_KEYS: u64 = 3125000; + +// for use in the full startup experiment +// 1024*1024*1024*115 / (1024 + 1024*512 + 128) (approximately) +// 115GB CapybaraKV instances uses 100% of PM device +// the extra 128 bytes accounts for metadata and CRCs +pub const CAPYBARAKV_MAX_KEYS: u64 = 30000; \ No newline at end of file diff --git a/evaluation/benchmark/src/main.rs b/evaluation/benchmark/src/main.rs index 9e85110d..e5485ac0 100644 --- a/evaluation/benchmark/src/main.rs +++ b/evaluation/benchmark/src/main.rs @@ -9,6 +9,7 @@ use builtin::*; #[allow(unused_imports)] use builtin_macros::*; +#[cfg(target_os = "linux")] use redis::{FromRedisValue, RedisResult}; use std::fs; @@ -22,15 +23,22 @@ use rand::thread_rng; use rand::seq::SliceRandom; use crate::kv_interface::*; +#[cfg(target_os = "linux")] use crate::redis_client::*; +#[cfg(target_os = "linux")] use crate::rocksdb_client::*; use crate::capybarakv_client::*; pub mod kv_interface; +#[cfg(target_os = "linux")] pub mod redis_client; +#[cfg(target_os = "linux")] pub mod rocksdb_client; pub mod capybarakv_client; +use crate::config::*; +pub mod config; + // length of key and value in byte for most tests const KEY_LEN: usize = 64; const VALUE_LEN: usize = 1024; @@ -40,18 +48,7 @@ const VALUE_LEN: usize = 1024; const BIG_KEY_LEN: usize = 1024; const BIG_VALUE_LEN: usize = 1024 * 512; -const PM_DEV: &str = "/dev/pmem0"; -const MOUNT_POINT: &str = "/mnt/pmem"; - -// TODO: read these from a config file? -const NUM_KEYS: u64 = 25000000; const ITERATIONS: u64 = 1; -// for use in the full startup experiment -// 1024*1024*1024*115 / (1024 + 1024*512 + 128) (approximately) -// 115GB CapybaraKV instances uses 100% of PM device -// the extra 128 bytes accounts for metadata and CRCs -const CAPYBARAKV_MAX_KEYS: u64 = 235000; - #[repr(C)] #[derive(PmCopy, Copy, Hash, Debug)] @@ -161,6 +158,7 @@ pub struct PlaceholderListElem { _val: u64, } +#[cfg(target_os = "linux")] impl FromRedisValue for TestValue { fn from_redis_value(v: &redis::Value) -> RedisResult { use redis::Value::*; @@ -187,6 +185,7 @@ impl FromRedisValue for TestValue { } } +#[cfg(target_os = "linux")] impl FromRedisValue for BigTestValue { fn from_redis_value(v: &redis::Value) -> RedisResult { use redis::Value::*; @@ -223,24 +222,36 @@ fn main() { }; // create per-KV output directories + #[cfg(target_os = "linux")] let redis_output_dir = output_dir.clone() + "/" + &RedisClient::::db_name(); + #[cfg(target_os = "linux")] let rocksdb_output_dir = output_dir.clone() + "/" + &RocksDbClient::::db_name(); + let capybara_output_dir = output_dir.clone() + "/" + &CapybaraKvClient::::db_name(); + #[cfg(target_os = "linux")] fs::create_dir_all(&redis_output_dir).unwrap(); + #[cfg(target_os = "linux")] fs::create_dir_all(&rocksdb_output_dir).unwrap(); + fs::create_dir_all(&capybara_output_dir).unwrap(); for i in 1..ITERATIONS+1 { + #[cfg(target_os = "linux")] run_experiments::>(&redis_output_dir, i).unwrap(); + #[cfg(target_os = "linux")] run_experiments::>(&rocksdb_output_dir, i).unwrap(); + run_experiments::>(&capybara_output_dir, i).unwrap(); } // full setup works differently so that we don't have to rebuild the full KV every iteration + #[cfg(target_os = "linux")] run_full_setup::>(&redis_output_dir, NUM_KEYS).unwrap(); + #[cfg(target_os = "linux")] run_full_setup::>(&rocksdb_output_dir, NUM_KEYS).unwrap(); + run_full_setup::>(&capybara_output_dir, CAPYBARAKV_MAX_KEYS).unwrap(); } @@ -657,6 +668,7 @@ fn run_full_setup(output_dir: &str, num_keys: u64) -> Result<(), KV::E> Ok(()) } +#[cfg(target_os = "linux")] pub fn init_and_mount_pm_fs() { println!("Mounting PM FS..."); @@ -682,6 +694,19 @@ pub fn init_and_mount_pm_fs() { println!("Mounted"); } +#[cfg(target_os = "windows")] +pub fn init_and_mount_pm_fs() { + + let output = Command::new("cmd") + .args(["/C", "del", "/Q", format!("{}\\capybarakv*", MOUNT_POINT).as_str()]) + .status() + .expect("Failed to delete files under the mount point"); + println!("[Windows] Deleted files under the mount point"); + + println!("[Windows] Mounting PM FS..."); +} + +#[cfg(target_os = "linux")] pub fn remount_pm_fs() { println!("Remounting existing FS..."); @@ -697,6 +722,17 @@ pub fn remount_pm_fs() { println!("Mounted"); } +#[cfg(target_os = "windows")] +pub fn remount_pm_fs() { + println!("[Windows] Remounting existing FS..."); +} + +#[cfg(target_os = "windows")] +pub fn unmount_pm_fs() { + println!("[Windows] Unmounting PM FS..."); +} + +#[cfg(target_os = "linux")] pub fn unmount_pm_fs() { let status = Command::new("sudo") .args(["umount", PM_DEV]) @@ -706,7 +742,6 @@ pub fn unmount_pm_fs() { } } - fn remove_file(name: &str) { let _ = std::fs::remove_file(name); }