This commit is contained in:
abbycin 2025-08-02 17:11:46 +08:00
parent cd851adc7e
commit 55b0487583
Signed by: abby
GPG Key ID: B636E0F0307EF8EB
4 changed files with 45 additions and 15 deletions

View File

@ -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

View File

@ -1,27 +1,49 @@
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")

View File

@ -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

View File

@ -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);
}