1
- use criterion:: { criterion_group, criterion_main , BenchmarkId , Criterion } ;
1
+ use criterion:: { criterion_group, BenchmarkId , Criterion } ;
2
2
use cubestore:: config:: Config ;
3
3
use cubestore:: metastore:: { BaseRocksStoreFs , Column , ColumnType , MetaStore , RocksMetaStore } ;
4
4
use cubestore:: remotefs:: LocalDirRemoteFs ;
@@ -8,6 +8,13 @@ use std::fs;
8
8
use std:: sync:: Arc ;
9
9
use tokio:: runtime:: { Builder , Runtime } ;
10
10
11
+ mod tracking_allocator;
12
+
13
+ use tracking_allocator:: TrackingAllocator ;
14
+
15
+ #[ global_allocator]
16
+ static ALLOCATOR : TrackingAllocator = TrackingAllocator :: new ( ) ;
17
+
11
18
fn prepare_metastore ( name : & str ) -> Result < Arc < RocksMetaStore > , CubeError > {
12
19
let config = Config :: test ( name) ;
13
20
@@ -97,118 +104,94 @@ async fn bench_get_tables_with_path(
97
104
}
98
105
}
99
106
100
- fn benchmark_get_tables_with_path_small ( c : & mut Criterion , runtime : & Runtime ) {
107
+ fn do_get_tables_with_path_bench (
108
+ c : & mut Criterion ,
109
+ runtime : & Runtime ,
110
+ num_schemas : usize ,
111
+ tables_per_schema : usize ,
112
+ iterations : usize ,
113
+ ) {
114
+ let total_tables = num_schemas * tables_per_schema;
101
115
let metastore = runtime. block_on ( async {
102
- let metastore = prepare_metastore ( "get_tables_with_path_small" ) . unwrap ( ) ;
103
- populate_metastore ( & metastore, 10 , 10 ) . await . unwrap ( ) ; // 100 tables
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 ( ) ;
104
121
metastore
105
122
} ) ;
106
123
107
124
c. bench_with_input (
108
- BenchmarkId :: new ( "get_tables_with_path_small_include_non_ready_true " , 100 ) ,
109
- & 100 ,
125
+ BenchmarkId :: new ( "get_tables_with_path_include_non_ready_true " , total_tables ) ,
126
+ & iterations ,
110
127
|b, & iterations| {
111
128
b. to_async ( runtime)
112
129
. iter ( || bench_get_tables_with_path ( & metastore, true , iterations) ) ;
113
130
} ,
114
131
) ;
115
132
116
133
c. bench_with_input (
117
- BenchmarkId :: new ( "get_tables_with_path_small_include_non_ready_false " , 100 ) ,
118
- & 100 ,
134
+ BenchmarkId :: new ( "get_tables_with_path_include_non_ready_false " , total_tables ) ,
135
+ & iterations ,
119
136
|b, & iterations| {
120
137
b. to_async ( runtime)
121
138
. iter ( || bench_get_tables_with_path ( & metastore, false , iterations) ) ;
122
139
} ,
123
140
) ;
124
141
}
125
142
126
- fn benchmark_get_tables_with_path_medium ( c : & mut Criterion , runtime : & Runtime ) {
127
- let metastore = runtime. block_on ( async {
128
- let metastore = prepare_metastore ( "get_tables_with_path_medium" ) . unwrap ( ) ;
129
- populate_metastore ( & metastore, 50 , 20 ) . await . unwrap ( ) ; // 1,000 tables
130
- metastore
131
- } ) ;
132
-
133
- c. bench_with_input (
134
- BenchmarkId :: new ( "get_tables_with_path_medium_include_non_ready_true" , 50 ) ,
135
- & 50 ,
136
- |b, & iterations| {
137
- b. to_async ( runtime)
138
- . iter ( || bench_get_tables_with_path ( & metastore, true , iterations) ) ;
139
- } ,
140
- ) ;
141
-
142
- c. bench_with_input (
143
- BenchmarkId :: new ( "get_tables_with_path_medium_include_non_ready_false" , 50 ) ,
144
- & 50 ,
145
- |b, & iterations| {
146
- b. to_async ( runtime)
147
- . iter ( || bench_get_tables_with_path ( & metastore, false , iterations) ) ;
148
- } ,
149
- ) ;
143
+ async fn do_cold_cache_test ( num_schemas : usize , tables_per_schema : usize ) {
144
+ let fresh_metastore = prepare_metastore ( "cold_cache_fresh" ) . unwrap ( ) ;
145
+ populate_metastore ( & fresh_metastore, num_schemas, tables_per_schema)
146
+ . await
147
+ . unwrap ( ) ;
148
+ let result = fresh_metastore. get_tables_with_path ( false ) . await ;
149
+ assert ! ( result. is_ok( ) ) ;
150
150
}
151
151
152
- fn benchmark_get_tables_with_path_large ( c : & mut Criterion , runtime : & Runtime ) {
153
- let metastore = runtime. block_on ( async {
154
- let metastore = prepare_metastore ( "get_tables_with_path_large" ) . unwrap ( ) ;
155
- populate_metastore ( & metastore, 25 , 1000 ) . await . unwrap ( ) ; // 25,000 tables
156
- metastore
157
- } ) ;
158
-
159
- c. bench_with_input (
160
- BenchmarkId :: new ( "get_tables_with_path_large_include_non_ready_true" , 10 ) ,
161
- & 10 ,
162
- |b, & iterations| {
163
- b. to_async ( runtime)
164
- . iter ( || bench_get_tables_with_path ( & metastore, true , iterations) ) ;
165
- } ,
166
- ) ;
167
-
168
- c. bench_with_input (
169
- BenchmarkId :: new ( "get_tables_with_path_large_include_non_ready_false" , 10 ) ,
170
- & 10 ,
171
- |b, & iterations| {
172
- b. to_async ( runtime)
173
- . iter ( || bench_get_tables_with_path ( & metastore, false , iterations) ) ;
174
- } ,
175
- ) ;
152
+ async fn do_warm_cache_test ( metastore : & Arc < RocksMetaStore > ) {
153
+ let result = metastore. get_tables_with_path ( false ) . await ;
154
+ assert ! ( result. is_ok( ) ) ;
176
155
}
177
156
178
- fn cold_vs_warm_cache_benchmark ( c : & mut Criterion , runtime : & Runtime ) {
157
+ fn do_cold_vs_warm_cache_bench (
158
+ c : & mut Criterion ,
159
+ runtime : & Runtime ,
160
+ num_schemas : usize ,
161
+ tables_per_schema : usize ,
162
+ ) {
179
163
let metastore = runtime. block_on ( async {
180
164
let metastore = prepare_metastore ( "cold_warm_cache" ) . unwrap ( ) ;
181
- populate_metastore ( & metastore, 20 , 50 ) . await . unwrap ( ) ; // 1,000 tables
165
+ populate_metastore ( & metastore, num_schemas, tables_per_schema)
166
+ . await
167
+ . unwrap ( ) ;
182
168
metastore
183
169
} ) ;
184
170
185
- // Cold cache benchmark (first call)
186
171
c. bench_function ( "get_tables_with_path_cold_cache" , |b| {
187
- b. to_async ( runtime) . iter ( || async {
188
- let fresh_metastore = prepare_metastore ( "cold_cache_fresh" ) . unwrap ( ) ;
189
- populate_metastore ( & fresh_metastore, 20 , 50 ) . await . unwrap ( ) ;
190
- let result = fresh_metastore. get_tables_with_path ( false ) . await ;
191
- assert ! ( result. is_ok( ) ) ;
192
- } ) ;
172
+ b. to_async ( runtime)
173
+ . iter ( || do_cold_cache_test ( num_schemas, tables_per_schema) ) ;
193
174
} ) ;
194
175
195
- // Warm cache benchmark (subsequent calls)
196
176
c. bench_function ( "get_tables_with_path_warm_cache" , |b| {
197
- b. to_async ( runtime) . iter ( || async {
198
- let result = metastore. get_tables_with_path ( false ) . await ;
199
- assert ! ( result. is_ok( ) ) ;
200
- } ) ;
177
+ b. to_async ( runtime) . iter ( || do_warm_cache_test ( & metastore) ) ;
201
178
} ) ;
202
179
}
203
180
204
181
fn do_benches ( c : & mut Criterion ) {
182
+ ALLOCATOR . reset_stats ( ) ;
205
183
let runtime = Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) ;
206
184
207
- benchmark_get_tables_with_path_small ( c, & runtime) ;
208
- benchmark_get_tables_with_path_medium ( c, & runtime) ;
209
- benchmark_get_tables_with_path_large ( c, & runtime) ;
210
- cold_vs_warm_cache_benchmark ( c, & runtime) ;
185
+ do_get_tables_with_path_bench ( c, & runtime, 10 , 10 , 100 ) ;
186
+ do_get_tables_with_path_bench ( c, & runtime, 50 , 20 , 50 ) ;
187
+ do_get_tables_with_path_bench ( c, & runtime, 25 , 1000 , 10 ) ;
188
+
189
+ do_cold_vs_warm_cache_bench ( c, & runtime, 20 , 50 ) ;
211
190
}
212
191
213
192
criterion_group ! ( benches, do_benches) ;
214
- criterion_main ! ( benches) ;
193
+
194
+ fn main ( ) {
195
+ benches ( ) ;
196
+ ALLOCATOR . print_stats ( ) ;
197
+ }
0 commit comments