Skip to content

Commit 1d116f5

Browse files
committed
chore(cubestore): Add simple allocator tracking stats for benchmarks
1 parent 28de77a commit 1d116f5

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

rust/cubestore/cubestore/benches/metastore.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ fn do_get_tables_with_path_bench(
113113
) {
114114
let total_tables = num_schemas * tables_per_schema;
115115
let metastore = runtime.block_on(async {
116-
let metastore = prepare_metastore(&format!("get_tables_with_path_{}", total_tables)).unwrap();
117-
populate_metastore(&metastore, num_schemas, tables_per_schema).await.unwrap();
116+
let metastore =
117+
prepare_metastore(&format!("get_tables_with_path_{}", total_tables)).unwrap();
118+
populate_metastore(&metastore, num_schemas, tables_per_schema)
119+
.await
120+
.unwrap();
118121
metastore
119122
});
120123

@@ -139,7 +142,9 @@ fn do_get_tables_with_path_bench(
139142

140143
async fn do_cold_cache_test(num_schemas: usize, tables_per_schema: usize) {
141144
let fresh_metastore = prepare_metastore("cold_cache_fresh").unwrap();
142-
populate_metastore(&fresh_metastore, num_schemas, tables_per_schema).await.unwrap();
145+
populate_metastore(&fresh_metastore, num_schemas, tables_per_schema)
146+
.await
147+
.unwrap();
143148
let result = fresh_metastore.get_tables_with_path(false).await;
144149
assert!(result.is_ok());
145150
}
@@ -157,12 +162,15 @@ fn do_cold_vs_warm_cache_bench(
157162
) {
158163
let metastore = runtime.block_on(async {
159164
let metastore = prepare_metastore("cold_warm_cache").unwrap();
160-
populate_metastore(&metastore, num_schemas, tables_per_schema).await.unwrap();
165+
populate_metastore(&metastore, num_schemas, tables_per_schema)
166+
.await
167+
.unwrap();
161168
metastore
162169
});
163170

164171
c.bench_function("get_tables_with_path_cold_cache", |b| {
165-
b.to_async(runtime).iter(|| do_cold_cache_test(num_schemas, tables_per_schema));
172+
b.to_async(runtime)
173+
.iter(|| do_cold_cache_test(num_schemas, tables_per_schema));
166174
});
167175

168176
c.bench_function("get_tables_with_path_warm_cache", |b| {
@@ -177,7 +185,7 @@ fn do_benches(c: &mut Criterion) {
177185
do_get_tables_with_path_bench(c, &runtime, 10, 10, 100);
178186
do_get_tables_with_path_bench(c, &runtime, 50, 20, 50);
179187
do_get_tables_with_path_bench(c, &runtime, 25, 1000, 10);
180-
188+
181189
do_cold_vs_warm_cache_bench(c, &runtime, 20, 50);
182190
}
183191

rust/cubestore/cubestore/benches/tracking_allocator.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ impl TrackingAllocator {
3333
self.total_allocated.store(0, Ordering::Relaxed);
3434
}
3535

36-
3736
pub fn print_stats(&self) {
3837
let allocations = self.allocations.load(Ordering::Relaxed);
3938
let deallocations = self.deallocations.load(Ordering::Relaxed);
@@ -46,9 +45,21 @@ impl TrackingAllocator {
4645
println!("Total allocations: {}", allocations);
4746
println!("Total deallocations: {}", deallocations);
4847
println!("Total reallocations: {}", reallocations);
49-
println!("Current allocated: {} bytes ({:.2} MB)", current_allocated, current_allocated as f64 / 1024.0 / 1024.0);
50-
println!("Peak allocated: {} bytes ({:.2} MB)", peak_allocated, peak_allocated as f64 / 1024.0 / 1024.0);
51-
println!("Total allocated: {} bytes ({:.2} MB)", total_allocated, total_allocated as f64 / 1024.0 / 1024.0);
48+
println!(
49+
"Current allocated: {} bytes ({:.2} MB)",
50+
current_allocated,
51+
current_allocated as f64 / 1024.0 / 1024.0
52+
);
53+
println!(
54+
"Peak allocated: {} bytes ({:.2} MB)",
55+
peak_allocated,
56+
peak_allocated as f64 / 1024.0 / 1024.0
57+
);
58+
println!(
59+
"Total allocated: {} bytes ({:.2} MB)",
60+
total_allocated,
61+
total_allocated as f64 / 1024.0 / 1024.0
62+
);
5263
println!("===============================");
5364
}
5465

@@ -57,7 +68,7 @@ impl TrackingAllocator {
5768
self.allocations.fetch_add(1, Ordering::Relaxed);
5869
self.total_allocated.fetch_add(size, Ordering::Relaxed);
5970
let current = self.current_allocated.fetch_add(size, Ordering::Relaxed) + size;
60-
71+
6172
// Update peak if current exceeds it
6273
let mut peak = self.peak_allocated.load(Ordering::Relaxed);
6374
while current > peak {
@@ -96,12 +107,16 @@ unsafe impl GlobalAlloc for TrackingAllocator {
96107
let new_ptr = self.inner.realloc(ptr, layout, new_size);
97108
if !new_ptr.is_null() {
98109
self.reallocations.fetch_add(1, Ordering::Relaxed);
99-
110+
100111
// Update counters: subtract old size, add new size
101-
self.current_allocated.fetch_sub(layout.size(), Ordering::Relaxed);
112+
self.current_allocated
113+
.fetch_sub(layout.size(), Ordering::Relaxed);
102114
self.total_allocated.fetch_add(new_size, Ordering::Relaxed);
103-
let current = self.current_allocated.fetch_add(new_size, Ordering::Relaxed) + new_size;
104-
115+
let current = self
116+
.current_allocated
117+
.fetch_add(new_size, Ordering::Relaxed)
118+
+ new_size;
119+
105120
// Update peak if current exceeds it
106121
let mut peak = self.peak_allocated.load(Ordering::Relaxed);
107122
while current > peak {
@@ -118,4 +133,4 @@ unsafe impl GlobalAlloc for TrackingAllocator {
118133
}
119134
new_ptr
120135
}
121-
}
136+
}

0 commit comments

Comments
 (0)