File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -397,11 +397,28 @@ where
397397 if !cur_info. on_blacklist && cur_info. msg_type == LogMessageType :: Request {
398398 timeout_counter. in_cache [ index] += 1 ;
399399 }
400+ let cur_is_req = cur_info. msg_type == LogMessageType :: Request ;
401+ let cur_on_blacklist = cur_info. on_blacklist ;
400402 let prev_info = rtt_cache. put ( key, cur_info) . unwrap ( ) ;
401- if !prev_info. on_blacklist {
402- Some ( L7PerfStats :: from ( & prev_info) )
403- } else {
403+ // Requests are counted (req=1) eagerly when they first enter the cache,
404+ // so re-emitting a displaced Request here would double-count it.
405+ // Responses were cached with None on arrival and must be counted here.
406+ let mut result =
407+ if !prev_info. on_blacklist && prev_info. msg_type == LogMessageType :: Response {
408+ L7PerfStats :: from ( & prev_info)
409+ } else {
410+ L7PerfStats :: default ( )
411+ } ;
412+ // A new Request entering the cache via this path (replacing a previous entry)
413+ // was never counted by the first-entry path, so emit req=1 now so that
414+ // "request accounted before" holds when its response arrives via is_request_of.
415+ if !cur_on_blacklist && cur_is_req {
416+ result. inc_req ( ) ;
417+ }
418+ if result == L7PerfStats :: default ( ) {
404419 None
420+ } else {
421+ Some ( result)
405422 }
406423 }
407424 } else {
Original file line number Diff line number Diff line change @@ -532,6 +532,12 @@ impl RrtCache {
532532 let mut backward = L7PerfStats :: default ( ) ;
533533 for ( key, _) in keys {
534534 if let Some ( cache) = self . logs . pop ( & key) {
535+ // Requests were already counted (req=1) when they first entered the cache;
536+ // re-counting them here would double-count. Only Responses need to be
537+ // counted here because they were cached with None on arrival.
538+ if cache. msg_type != LogMessageType :: Response {
539+ continue ;
540+ }
535541 if key. is_reversed ( ) {
536542 backward. sequential_merge ( & L7PerfStats :: from ( & cache) ) ;
537543 } else {
You can’t perform that action at this time.
0 commit comments