1- use criterion:: { criterion_group, criterion_main , BenchmarkId , Criterion } ;
1+ use criterion:: { criterion_group, BenchmarkId , Criterion } ;
22use cubestore:: config:: Config ;
33use cubestore:: metastore:: { BaseRocksStoreFs , Column , ColumnType , MetaStore , RocksMetaStore } ;
44use cubestore:: remotefs:: LocalDirRemoteFs ;
@@ -8,6 +8,13 @@ use std::fs;
88use std:: sync:: Arc ;
99use tokio:: runtime:: { Builder , Runtime } ;
1010
11+ mod tracking_allocator;
12+
13+ use tracking_allocator:: TrackingAllocator ;
14+
15+ #[ global_allocator]
16+ static ALLOCATOR : TrackingAllocator = TrackingAllocator :: new ( ) ;
17+
1118fn prepare_metastore ( name : & str ) -> Result < Arc < RocksMetaStore > , CubeError > {
1219 let config = Config :: test ( name) ;
1320
@@ -97,118 +104,86 @@ async fn bench_get_tables_with_path(
97104 }
98105}
99106
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;
101115 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 = prepare_metastore ( & format ! ( "get_tables_with_path_{}" , total_tables ) ) . unwrap ( ) ;
117+ populate_metastore ( & metastore, num_schemas , tables_per_schema ) . await . unwrap ( ) ;
104118 metastore
105119 } ) ;
106120
107121 c. bench_with_input (
108- BenchmarkId :: new ( "get_tables_with_path_small_include_non_ready_true " , 100 ) ,
109- & 100 ,
122+ BenchmarkId :: new ( "get_tables_with_path_include_non_ready_true " , total_tables ) ,
123+ & iterations ,
110124 |b, & iterations| {
111125 b. to_async ( runtime)
112126 . iter ( || bench_get_tables_with_path ( & metastore, true , iterations) ) ;
113127 } ,
114128 ) ;
115129
116130 c. bench_with_input (
117- BenchmarkId :: new ( "get_tables_with_path_small_include_non_ready_false " , 100 ) ,
118- & 100 ,
131+ BenchmarkId :: new ( "get_tables_with_path_include_non_ready_false " , total_tables ) ,
132+ & iterations ,
119133 |b, & iterations| {
120134 b. to_async ( runtime)
121135 . iter ( || bench_get_tables_with_path ( & metastore, false , iterations) ) ;
122136 } ,
123137 ) ;
124138}
125139
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- ) ;
140+ async fn do_cold_cache_test ( num_schemas : usize , tables_per_schema : usize ) {
141+ let fresh_metastore = prepare_metastore ( "cold_cache_fresh" ) . unwrap ( ) ;
142+ populate_metastore ( & fresh_metastore, num_schemas, tables_per_schema) . await . unwrap ( ) ;
143+ let result = fresh_metastore. get_tables_with_path ( false ) . await ;
144+ assert ! ( result. is_ok( ) ) ;
150145}
151146
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- ) ;
147+ async fn do_warm_cache_test ( metastore : & Arc < RocksMetaStore > ) {
148+ let result = metastore. get_tables_with_path ( false ) . await ;
149+ assert ! ( result. is_ok( ) ) ;
176150}
177151
178- fn cold_vs_warm_cache_benchmark ( c : & mut Criterion , runtime : & Runtime ) {
152+ fn do_cold_vs_warm_cache_bench (
153+ c : & mut Criterion ,
154+ runtime : & Runtime ,
155+ num_schemas : usize ,
156+ tables_per_schema : usize ,
157+ ) {
179158 let metastore = runtime. block_on ( async {
180159 let metastore = prepare_metastore ( "cold_warm_cache" ) . unwrap ( ) ;
181- populate_metastore ( & metastore, 20 , 50 ) . await . unwrap ( ) ; // 1,000 tables
160+ populate_metastore ( & metastore, num_schemas , tables_per_schema ) . await . unwrap ( ) ;
182161 metastore
183162 } ) ;
184163
185- // Cold cache benchmark (first call)
186164 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- } ) ;
165+ b. to_async ( runtime) . iter ( || do_cold_cache_test ( num_schemas, tables_per_schema) ) ;
193166 } ) ;
194167
195- // Warm cache benchmark (subsequent calls)
196168 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- } ) ;
169+ b. to_async ( runtime) . iter ( || do_warm_cache_test ( & metastore) ) ;
201170 } ) ;
202171}
203172
204173fn do_benches ( c : & mut Criterion ) {
174+ ALLOCATOR . reset_stats ( ) ;
205175 let runtime = Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) ;
206176
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) ;
177+ do_get_tables_with_path_bench ( c, & runtime, 10 , 10 , 100 ) ;
178+ do_get_tables_with_path_bench ( c, & runtime, 50 , 20 , 50 ) ;
179+ do_get_tables_with_path_bench ( c, & runtime, 25 , 1000 , 10 ) ;
180+
181+ do_cold_vs_warm_cache_bench ( c, & runtime, 20 , 50 ) ;
211182}
212183
213184criterion_group ! ( benches, do_benches) ;
214- criterion_main ! ( benches) ;
185+
186+ fn main ( ) {
187+ benches ( ) ;
188+ ALLOCATOR . print_stats ( ) ;
189+ }
0 commit comments