From 55b04875839ab4c74aace16c6a907ba41be66526 Mon Sep 17 00:00:00 2001 From: abbycin Date: Sat, 2 Aug 2025 17:11:46 +0800 Subject: [PATCH] update --- Cargo.toml | 4 ++++ scripts/plot.py | 40 +++++++++++++++++++++++++++++++--------- scripts/x.sh | 10 ++++++---- src/main.rs | 6 ++++-- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6330fa4..8f4bb26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,7 @@ edition = "2024" mace = { git = "https://git.o2c.fun/abby/mace.git", branch = "task-63" } clap = { version = "4.5.42", features = ["derive"] } rand = "0.9.2" + +[profile.release] +lto = true +opt-level = 3 diff --git a/scripts/plot.py b/scripts/plot.py index d02dc6a..b98f05a 100644 --- a/scripts/plot.py +++ b/scripts/plot.py @@ -1,28 +1,50 @@ import pandas as pd import matplotlib.pyplot as plt +from adjustText import adjust_text + +def real_mode(m): + if m == "mixed": + return "mixed (70% read, 30% write)" + return m # 读取数据 df = pd.read_csv("./x.csv") -# group by mode +# 按 mode 分组 modes = df["mode"].unique() + for mode in modes: - plt.figure(figsize=(12, 6)) + plt.figure(figsize=(16, 9)) subset = df[df["mode"] == mode] - # group by key_size/value_size + # 按 key_size/value_size 分组 key_value_combinations = subset.groupby(["key_size", "value_size"]) + texts = [] for (key_size, value_size), group in key_value_combinations: label = f"key={key_size}B, val={value_size}B" - plt.plot(group["threads"], group["ops"], marker="o", label=label) + x = group["threads"] + y = group["ops"] - plt.title(f"Performance: {mode.upper()}") - plt.xlabel("Threads") - plt.ylabel("OPS") - plt.grid(True) + # 绘制折线 + line, = plt.plot(x, y, marker="o", label=label) + + # 添加文本标签 + for xi, yi, ops in zip(x, y, group["ops"]): + texts.append( + plt.text(xi, yi, f"{int(ops)}", color=line.get_color(), fontsize=12) + ) + + # 自动调整文本位置 + adjust_text(texts, arrowprops=dict(arrowstyle="->", color='gray')) + + # 设置图表样式 + plt.title(f"Performance: {real_mode(mode).upper()}", fontsize=16) + plt.xlabel("Threads", fontsize=14) + plt.ylabel("OPS", fontsize=14) + plt.grid(True, linestyle="--", alpha=0.6) plt.legend() plt.tight_layout() plt.savefig(f"{mode}.png") - plt.close() + plt.close() \ No newline at end of file diff --git a/scripts/x.sh b/scripts/x.sh index d1fe0de..b3d58cc 100755 --- a/scripts/x.sh +++ b/scripts/x.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +pushd . cd .. cargo build --release 1>/dev/null 2> /dev/null @@ -21,7 +22,7 @@ function samples() { then exit 1 fi - ./target/release/kv_bench --path /home/abby/mace_bench --threads $i --iterations 100000 --mode mixed --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]} --insert-ratio 70 + ./target/release/kv_bench --path /home/abby/mace_bench --threads $i --iterations 100000 --mode mixed --key-size ${kv_sz[j]} --value-size ${kv_sz[j+1]} --insert-ratio 30 if test $? -ne 0 then exit 1 @@ -30,6 +31,7 @@ function samples() { done } -echo mode,threads,key_size,value_size,insert_ratio,ops > x.csv -samples 2>> x.csv - +echo mode,threads,key_size,value_size,insert_ratio,ops > scripts/x.csv +samples 2>> scripts/x.csv +popd +./bin/python plot.py diff --git a/src/main.rs b/src/main.rs index 83d6aae..0c2f59b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,6 +62,8 @@ fn main() { let mut opt = Options::new(path); opt.sync_on_write = false; opt.tmp_store = true; + // currently we don't have prefix encode, so enlarge the inline size to avoid indirection + opt.max_inline_size = 4096; let db = Mace::new(opt.validate().unwrap()).unwrap(); let value = Arc::new(vec![b'0'; args.value_size]); @@ -70,7 +72,7 @@ fn main() { for i in 0..args.iterations { let key = format!("key_{tid}_{i}"); let mut tmp = key.into_bytes(); - tmp.resize(args.key_size, 0); + tmp.resize(args.key_size, b'x'); let pre_tx = db.begin().unwrap(); pre_tx.put(&tmp, &*value).unwrap(); pre_tx.commit().unwrap(); @@ -97,7 +99,7 @@ fn main() { for i in 0..args.iterations { let key = format!("key_{tid}_{i}"); let mut tmp = key.into_bytes(); - tmp.resize(args.key_size, 0); + tmp.resize(args.key_size, b'x'); keys.push(tmp); }