11use criterion:: { criterion_group, criterion_main, BenchmarkId , Criterion } ;
2- use cubestore:: cachestore:: { CacheStore , QueueAddPayload , QueueItemStatus , RocksCacheStore } ;
2+ use cubestore:: cachestore:: {
3+ CacheStore , QueueAddPayload , QueueItemStatus , QueueKey , RocksCacheStore ,
4+ } ;
35use cubestore:: config:: { Config , CubeServices } ;
46use cubestore:: CubeError ;
57use std:: sync:: Arc ;
@@ -25,6 +27,14 @@ fn prepare_cachestore(name: &str) -> Result<Arc<RocksCacheStore>, CubeError> {
2527 Ok ( cachestore)
2628}
2729
30+ fn generate_queue_path ( queue_path : & str , queue_id : usize ) -> String {
31+ format ! (
32+ "{}:{}" ,
33+ queue_path,
34+ format!( "{:x}" , md5:: compute( queue_id. to_be_bytes( ) ) )
35+ )
36+ }
37+
2838async fn do_insert (
2939 cachestore : & Arc < RocksCacheStore > ,
3040 total : usize ,
@@ -33,11 +43,7 @@ async fn do_insert(
3343) {
3444 for i in 0 ..total {
3545 let fut = cachestore. queue_add ( QueueAddPayload {
36- path : format ! (
37- "{}:{}" ,
38- queue_path,
39- format!( "{:x}" , md5:: compute( i. to_be_bytes( ) ) )
40- ) ,
46+ path : generate_queue_path ( queue_path, i) ,
4147 value : "a" . repeat ( size_kb * 1024 ) , // size in bytes
4248 priority : 0 ,
4349 orphaned : None ,
@@ -50,15 +56,15 @@ async fn do_insert(
5056
5157fn do_insert_bench ( c : & mut Criterion , runtime : & Runtime , total : usize , size_kb : usize ) {
5258 let cachestore = runtime. block_on ( async {
53- prepare_cachestore ( & format ! ( "cachestore_queue_insert_ {}" , size_kb) ) . unwrap ( )
59+ prepare_cachestore ( & format ! ( "cachestore_queue_add_ {}" , size_kb) ) . unwrap ( )
5460 } ) ;
5561
5662 c. bench_with_input (
57- BenchmarkId :: new ( format ! ( "insert queues:1, size:{} kb" , size_kb) , total) ,
63+ BenchmarkId :: new ( format ! ( "queue_add queues:1, size:{} kb" , size_kb) , total) ,
5864 & ( total, size_kb) ,
5965 |b, ( total, size_kb) | {
6066 b. to_async ( runtime)
61- . iter ( || do_insert ( & cachestore, * total, * size_kb, "STANDALONE#queue:1 " ) ) ;
67+ . iter ( || do_insert ( & cachestore, * total, * size_kb, "STANDALONE#queue" ) ) ;
6268 } ,
6369 ) ;
6470}
@@ -69,7 +75,12 @@ async fn do_list(
6975 total : usize ,
7076) {
7177 for _ in 0 ..total {
72- let fut = cachestore. queue_list ( "queue:1" . to_string ( ) , status_filter. clone ( ) , true , false ) ;
78+ let fut = cachestore. queue_list (
79+ "STANDALONE#queue:1" . to_string ( ) ,
80+ status_filter. clone ( ) ,
81+ true ,
82+ false ,
83+ ) ;
7384
7485 let res = fut. await ;
7586 assert ! ( res. is_ok( ) ) ;
@@ -92,19 +103,19 @@ fn do_list_bench(
92103 ) )
93104 . unwrap ( ) ;
94105
95- do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue:1 " ) . await ;
96- do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue:2 " ) . await ;
97- do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue:3 " ) . await ;
98- do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue:4 " ) . await ;
99- do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue:5 " ) . await ;
106+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
107+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
108+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
109+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
110+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
100111
101112 cachestore
102113 } ) ;
103114
104115 c. bench_with_input (
105116 BenchmarkId :: new (
106117 format ! (
107- "list status_filter: {:?} queues:5, size:{} kb, per_queue:{}" ,
118+ "queue_list status_filter: {:?} queues:5, size:{} kb, per_queue:{}" ,
108119 status_filter, size_kb, per_queue
109120 ) ,
110121 total,
@@ -117,6 +128,52 @@ fn do_list_bench(
117128 ) ;
118129}
119130
131+ async fn do_get ( cachestore : & Arc < RocksCacheStore > , total : usize ) {
132+ for i in 0 ..total {
133+ let fut = cachestore. queue_get ( QueueKey :: ByPath ( generate_queue_path (
134+ "STANDALONE#queue" ,
135+ i + ( ( i - 1 ) * 5 ) ,
136+ ) ) ) ;
137+
138+ let res = fut. await ;
139+ assert ! ( res. is_ok( ) ) ;
140+ }
141+ }
142+
143+ fn do_get_bench (
144+ c : & mut Criterion ,
145+ runtime : & Runtime ,
146+ per_queue : usize ,
147+ size_kb : usize ,
148+ total : usize ,
149+ ) {
150+ let cachestore = runtime. block_on ( async {
151+ let cachestore = prepare_cachestore ( & format ! ( "cachestore_queue_get_{}" , size_kb) ) . unwrap ( ) ;
152+
153+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
154+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
155+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
156+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
157+ do_insert ( & cachestore, per_queue, size_kb, "STANDALONE#queue" ) . await ;
158+
159+ cachestore
160+ } ) ;
161+
162+ c. bench_with_input (
163+ BenchmarkId :: new (
164+ format ! (
165+ "queue_get queues:5, size:{} kb, per_queue:{}" ,
166+ size_kb, per_queue
167+ ) ,
168+ total,
169+ ) ,
170+ & total,
171+ |b, total| {
172+ b. to_async ( runtime) . iter ( || do_get ( & cachestore, * total) ) ;
173+ } ,
174+ ) ;
175+ }
176+
120177fn do_benches ( c : & mut Criterion ) {
121178 let runtime = Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) ;
122179
@@ -126,6 +183,8 @@ fn do_benches(c: &mut Criterion) {
126183
127184 do_list_bench ( c, & runtime, Some ( QueueItemStatus :: Pending ) , 1_000 , 128 , 128 ) ;
128185 do_list_bench ( c, & runtime, Some ( QueueItemStatus :: Active ) , 1_000 , 128 , 128 ) ;
186+
187+ do_get_bench ( c, & runtime, 10_000 , 128 , 128 ) ;
129188}
130189
131190criterion_group ! ( benches, do_benches) ;
0 commit comments