@@ -18,7 +18,7 @@ use conduit::{RequestExt, StatusCode};
18
18
pub ( super ) struct BalanceCapacity {
19
19
handler : Option < Box < dyn Handler > > ,
20
20
capacity : usize ,
21
- in_flight_requests : AtomicUsize ,
21
+ in_flight_non_dl_requests : AtomicUsize ,
22
22
report_only : bool ,
23
23
log_at_percentage : usize ,
24
24
throttle_at_percentage : usize ,
@@ -30,7 +30,7 @@ impl BalanceCapacity {
30
30
Self {
31
31
handler : None ,
32
32
capacity,
33
- in_flight_requests : AtomicUsize :: new ( 0 ) ,
33
+ in_flight_non_dl_requests : AtomicUsize :: new ( 0 ) ,
34
34
report_only : env:: var ( "WEB_CAPACITY_REPORT_ONLY" ) . ok ( ) . is_some ( ) ,
35
35
log_at_percentage : read_env_percentage ( "WEB_CAPACITY_LOG_PCT" , 50 ) ,
36
36
throttle_at_percentage : read_env_percentage ( "WEB_CAPACITY_THROTTLE_PCT" , 70 ) ,
@@ -73,18 +73,18 @@ impl AroundMiddleware for BalanceCapacity {
73
73
74
74
impl Handler for BalanceCapacity {
75
75
fn call ( & self , request : & mut dyn RequestExt ) -> AfterResult {
76
+ // Download requests are always accepted and do not affect the request count
77
+ if request. path ( ) . starts_with ( "/api/v1/crates/" ) && request. path ( ) . ends_with ( "/download" ) {
78
+ return self . handle ( request) ;
79
+ }
80
+
76
81
// The _drop_on_exit ensures the counter is decremented for all exit paths (including panics)
77
- let ( _drop_on_exit, count) = RequestCounter :: add_one ( & self . in_flight_requests ) ;
82
+ let ( _drop_on_exit, count) = RequestCounter :: add_one ( & self . in_flight_non_dl_requests ) ;
78
83
let load = 100 * count / self . capacity ;
79
84
80
85
// Begin logging request count so early stages of load increase can be located
81
86
if load >= self . log_at_percentage {
82
- super :: log_request:: add_custom_metadata ( request, "in_flight_requests" , count) ;
83
- }
84
-
85
- // Download requests are always accepted
86
- if request. path ( ) . starts_with ( "/api/v1/crates/" ) && request. path ( ) . ends_with ( "/download" ) {
87
- return self . handle ( request) ;
87
+ super :: log_request:: add_custom_metadata ( request, "in_flight_non_dl_requests" , count) ;
88
88
}
89
89
90
90
// Reject read-only requests as load nears capacity. Bots are likely to send only safe
@@ -110,9 +110,6 @@ fn read_env_percentage(name: &str, default: usize) -> usize {
110
110
}
111
111
}
112
112
113
- // FIXME(JTG): I've copied the following from my `conduit-hyper` crate. Once we transition from
114
- // `civet`, we could pass the in_flight_request count from `condut-hyper` via a request extension.
115
-
116
113
/// A struct that stores a reference to an atomic counter so it can be decremented when dropped
117
114
struct RequestCounter < ' a > {
118
115
counter : & ' a AtomicUsize ,
0 commit comments