@@ -20,23 +20,26 @@ pub struct BenchResult {
20
20
#[ tokio:: main]
21
21
async fn main ( ) {
22
22
let base_url = "http://localhost:8080" ;
23
+ // let base_url = "https://prenet.polybase.xyz";
23
24
24
25
// client hangs on 100k on MacOS
25
- for n in [ 1 , 10 , 100 , 1000 ] {
26
+ for n in [ 1 , 10 , 100 , 1000 , 5000 ] {
26
27
let BenchResult {
27
28
total_duration,
28
29
avg_duration,
29
30
variance_duration,
30
31
std_dev_duration,
31
32
throughput,
32
- ..
33
+ durations ,
33
34
} = create_records ( n, base_url) . await ;
34
35
35
36
println ! ( "Took {}s to create {n} records" , total_duration) ;
36
37
println ! ( " Average duration: {} seconds" , avg_duration) ;
37
38
println ! ( " Variance deviation: {} seconds" , variance_duration) ;
38
39
println ! ( " Standard deviation: {} seconds" , std_dev_duration) ;
39
40
println ! ( " Throughput: {} requests per second" , throughput) ;
41
+
42
+ generate_chart ( format ! ( "results/create_records_{}.svg" , n) , durations, 50 ) ;
40
43
}
41
44
}
42
45
@@ -77,7 +80,11 @@ async fn create_records(n: u64, base_url: &str) -> BenchResult {
77
80
let duration = start. elapsed ( ) ;
78
81
79
82
// Make sure the request was successful
80
- assert ! ( response. status( ) . is_success( ) ) ;
83
+ assert ! (
84
+ response. status( ) . is_success( ) ,
85
+ "Request failed: {:?}" ,
86
+ response. status( )
87
+ ) ;
81
88
82
89
duration. as_secs_f64 ( )
83
90
} ) ;
@@ -141,7 +148,7 @@ async fn create_collection(base_url: &str) -> String {
141
148
id
142
149
}
143
150
144
- async fn generate_chart ( name : String , durations : Vec < f64 > , num_bins : usize ) {
151
+ fn generate_chart ( name : String , durations : Vec < f64 > , num_bins : usize ) {
145
152
let current_file = file ! ( ) ;
146
153
let project_root = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . parent ( ) . unwrap ( ) ;
147
154
let absolute_current_file = fs:: canonicalize ( project_root. join ( current_file) ) . unwrap ( ) ;
@@ -164,22 +171,27 @@ async fn generate_chart(name: String, durations: Vec<f64>, num_bins: usize) {
164
171
. min_by ( |a, b| a. partial_cmp ( b) . unwrap ( ) )
165
172
. unwrap ( ) ;
166
173
174
+ let histogram = durations. iter ( ) . fold ( vec ! [ 0 ; num_bins] , |mut acc, & v| {
175
+ let index =
176
+ ( ( v - min_duration) / ( max_duration - min_duration) * ( num_bins as f64 ) - 1.0 ) as usize ;
177
+ acc[ index] += 1 ;
178
+ acc
179
+ } ) ;
180
+
181
+ let max: & usize = histogram. iter ( ) . max ( ) . unwrap ( ) ;
182
+ let height = max + max / 10 ;
183
+
167
184
let mut chart = ChartBuilder :: on ( & root)
168
185
// .caption("Histogram of Request Durations", ("", 50).into_font())
169
186
. margin ( 5 )
170
187
. x_label_area_size ( 30 )
171
188
. y_label_area_size ( 30 )
172
- . build_cartesian_2d ( min_duration..max_duration, 0usize ..400usize )
189
+ . build_cartesian_2d ( min_duration..max_duration, 0usize ..height )
173
190
. unwrap ( ) ;
174
191
175
192
chart. configure_mesh ( ) . draw ( ) . unwrap ( ) ;
176
193
177
- let histogram = durations. iter ( ) . fold ( vec ! [ 0 ; num_bins] , |mut acc, & v| {
178
- let index =
179
- ( ( v - min_duration) / ( max_duration - min_duration) * ( num_bins as f64 ) - 1.0 ) as usize ;
180
- acc[ index] += 1 ;
181
- acc
182
- } ) ;
194
+ let diff = max_duration - min_duration;
183
195
184
196
chart
185
197
. draw_series ( histogram. into_iter ( ) . zip ( 0 ..) . map ( |( y, x) | {
@@ -188,13 +200,13 @@ async fn generate_chart(name: String, durations: Vec<f64>, num_bins: usize) {
188
200
(
189
201
( x as f64 / num_bins as f64 ) * ( max_duration - min_duration)
190
202
+ min_duration
191
- + 0.0001 ,
203
+ + ( diff * 0.001 ) ,
192
204
0 ,
193
205
) ,
194
206
(
195
207
( ( x + 1 ) as f64 / num_bins as f64 ) * ( max_duration - min_duration)
196
208
+ min_duration
197
- - 0.0001 ,
209
+ - ( diff * 0.001 ) ,
198
210
y,
199
211
) ,
200
212
] ,
0 commit comments