1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
use obnam::benchmark::ChunkGenerator;
use obnam::index::Index;
use std::path::{Path, PathBuf};
use std::time::SystemTime;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(
name = "benchmark-index",
about = "Benhcmark the chunk store index without HTTP"
)]
enum Opt {
Create {
#[structopt(parse(from_os_str))]
chunks: PathBuf,
#[structopt()]
num: u32,
},
Lookup {
#[structopt(parse(from_os_str))]
chunks: PathBuf,
#[structopt()]
warmup_count: u32,
#[structopt()]
hot_count: u32,
},
}
fn main() -> anyhow::Result<()> {
pretty_env_logger::init();
let opt = Opt::from_args();
match opt {
Opt::Create { chunks, num } => create(&chunks, num)?,
Opt::Lookup {
chunks,
warmup_count,
hot_count,
} => {
let mut index = Index::new(chunks)?;
let time = SystemTime::now();
warmup(&mut index, warmup_count)?;
let warmup_time = time.elapsed()?;
hot(&mut index, hot_count)?;
let hot_time = time.elapsed()? - warmup_time;
println!("warmup {}", warmup_time.as_millis());
println!("hot {}", hot_time.as_millis());
}
}
Ok(())
}
fn create(chunks: &Path, num: u32) -> anyhow::Result<()> {
let mut index = Index::new(chunks)?;
let gen = ChunkGenerator::new(num);
for (id, _, chunk) in gen {
let meta = (*chunk.meta()).clone();
index.insert_meta(id, meta)?;
}
Ok(())
}
fn warmup(index: &mut Index, num: u32) -> anyhow::Result<()> {
println!("warming up cache");
lookup(index, num)
}
fn hot(index: &mut Index, num: u32) -> anyhow::Result<()> {
println!("using hot cache");
lookup(index, num)
}
fn lookup(index: &mut Index, num: u32) -> anyhow::Result<()> {
let mut done = 0;
loop {
let gen = ChunkGenerator::new(num);
for (_, _, chunk) in gen {
index.find_by_sha256(chunk.meta().sha256())?;
done += 1;
if done >= num {
return Ok(());
}
}
}
}
|