|
1 | 1 | #[macro_use] |
2 | 2 | extern crate criterion; |
3 | 3 | use criterion::{BenchmarkId, Criterion}; |
4 | | -use redirectionio::action::Action; |
| 4 | +use redirectionio::action::{Action, UnitTrace}; |
5 | 5 | use redirectionio::api::{Rule, RulesMessage}; |
6 | 6 | use redirectionio::http::Request; |
7 | 7 | use redirectionio::router::{Router, RouterConfig}; |
@@ -125,41 +125,97 @@ fn build_action_rule_in_200k(c: &mut Criterion) { |
125 | 125 | let rules = router.match_request(&request); |
126 | 126 | let mut action = Action::from_routes_rule(rules.clone(), &request); |
127 | 127 |
|
128 | | - let action_status_code = action.get_status_code(0); |
| 128 | + let action_status_code = action.get_status_code(0, None); |
129 | 129 | let (_, backend_status_code) = if action_status_code != 0 { |
130 | 130 | (action_status_code, action_status_code) |
131 | 131 | } else { |
132 | 132 | // We call the backend and get a response code |
133 | | - let final_status_code = action.get_status_code(200); |
| 133 | + let final_status_code = action.get_status_code(200, None); |
134 | 134 | (final_status_code, 200) |
135 | 135 | }; |
136 | 136 |
|
137 | | - action.filter_headers(Vec::new(), backend_status_code, false); |
| 137 | + action.filter_headers(Vec::new(), backend_status_code, false, None); |
138 | 138 |
|
139 | 139 | let body = "<!DOCTYPE html> |
140 | 140 | <html> |
141 | 141 | <head> |
142 | 142 | </head> |
143 | 143 | <body> |
144 | 144 | </body> |
145 | | -</html>" |
146 | | - .to_string(); |
| 145 | +</html>"; |
147 | 146 |
|
148 | | - if let Some(mut body_filter) = action.create_filter_body(backend_status_code) { |
149 | | - body_filter.filter(body); |
150 | | - body_filter.end(); |
| 147 | + if let Some(mut body_filter) = action.create_filter_body(backend_status_code, &[]) { |
| 148 | + body_filter.filter(body.into(), None); |
| 149 | + body_filter.end(None); |
151 | 150 | } |
152 | 151 | }); |
153 | 152 | }); |
154 | 153 |
|
155 | 154 | group.finish(); |
156 | 155 | } |
157 | 156 |
|
| 157 | +fn impact(c: &mut Criterion) { |
| 158 | + let config = RouterConfig::default(); |
| 159 | + let mut router = create_router("../bench-files/large-rules-200k.json".to_string(), &config); |
| 160 | + let request = Request::from_config( |
| 161 | + &config, |
| 162 | + "/sites/default/files/image-gallery/lowtideonuseppaimage000000edited_0.jpg".to_string(), |
| 163 | + Some("usharbors.com".to_string()), |
| 164 | + None, |
| 165 | + None, |
| 166 | + None, |
| 167 | + None, |
| 168 | + ); |
| 169 | + |
| 170 | + router.cache(1000); |
| 171 | + |
| 172 | + let mut unit_trace = UnitTrace::default(); |
| 173 | + |
| 174 | + let mut group = c.benchmark_group("impact"); |
| 175 | + group.sample_size(10); |
| 176 | + |
| 177 | + group.bench_function("impact", |b| { |
| 178 | + b.iter(|| { |
| 179 | + let rules = router.match_request(&request); |
| 180 | + let mut action = Action::from_routes_rule(rules.clone(), &request); |
| 181 | + |
| 182 | + let action_status_code = action.get_status_code(0, Some(&mut unit_trace)); |
| 183 | + let (_, backend_status_code) = if action_status_code != 0 { |
| 184 | + (action_status_code, action_status_code) |
| 185 | + } else { |
| 186 | + // We call the backend and get a response code |
| 187 | + let final_status_code = action.get_status_code(200, Some(&mut unit_trace)); |
| 188 | + (final_status_code, 200) |
| 189 | + }; |
| 190 | + |
| 191 | + action.filter_headers(Vec::new(), backend_status_code, false, Some(&mut unit_trace)); |
| 192 | + |
| 193 | + let body = "<!DOCTYPE html> |
| 194 | +<html> |
| 195 | + <head> |
| 196 | + </head> |
| 197 | + <body> |
| 198 | + </body> |
| 199 | +</html>"; |
| 200 | + |
| 201 | + if let Some(mut body_filter) = action.create_filter_body(backend_status_code, &[]) { |
| 202 | + body_filter.filter(body.into(), Some(&mut unit_trace)); |
| 203 | + body_filter.end(Some(&mut unit_trace)); |
| 204 | + } |
| 205 | + |
| 206 | + unit_trace.squash_with_target_unit_traces(); |
| 207 | + }); |
| 208 | + }); |
| 209 | + |
| 210 | + group.finish(); |
| 211 | +} |
| 212 | + |
158 | 213 | criterion_group!( |
159 | 214 | benches, |
160 | 215 | no_match_bench, |
161 | 216 | no_match_cache_bench, |
162 | 217 | match_rule_in_200k, |
163 | | - build_action_rule_in_200k |
| 218 | + build_action_rule_in_200k, |
| 219 | + impact, |
164 | 220 | ); |
165 | 221 | criterion_main!(benches); |
0 commit comments