@@ -73,85 +73,33 @@ impl Repository {
7373 result
7474 }
7575
76- #[ allow( clippy:: cast_precision_loss) ]
77- #[ allow( clippy:: cast_possible_truncation) ]
78- #[ allow( clippy:: cast_sign_loss) ]
7976 pub async fn recalculate_udp_avg_connect_processing_time_ns ( & self , req_processing_time : Duration ) -> f64 {
8077 let stats_lock = self . stats . write ( ) . await ;
8178
82- let req_processing_time = req_processing_time. as_nanos ( ) as f64 ;
83- let udp_connections_handled = ( stats_lock. udp4_connections_handled ( ) + stats_lock. udp6_connections_handled ( ) ) as f64 ;
84-
85- let previous_avg = stats_lock. udp_avg_connect_processing_time_ns ( ) ;
86-
87- // Moving average: https://en.wikipedia.org/wiki/Moving_average
88- let new_avg = previous_avg as f64 + ( req_processing_time - previous_avg as f64 ) / udp_connections_handled;
79+ let new_avg = stats_lock. recalculate_udp_avg_connect_processing_time_ns ( req_processing_time) ;
8980
9081 drop ( stats_lock) ;
9182
92- tracing:: debug!(
93- "Recalculated UDP average connect processing time: {} ns (previous: {} ns, req_processing_time: {} ns, udp_connections_handled: {})" ,
94- new_avg,
95- previous_avg,
96- req_processing_time,
97- udp_connections_handled
98- ) ;
99-
10083 new_avg
10184 }
10285
103- #[ allow( clippy:: cast_precision_loss) ]
104- #[ allow( clippy:: cast_possible_truncation) ]
105- #[ allow( clippy:: cast_sign_loss) ]
10686 pub async fn recalculate_udp_avg_announce_processing_time_ns ( & self , req_processing_time : Duration ) -> f64 {
10787 let stats_lock = self . stats . write ( ) . await ;
10888
109- let req_processing_time = req_processing_time. as_nanos ( ) as f64 ;
110-
111- let udp_announces_handled = ( stats_lock. udp4_announces_handled ( ) + stats_lock. udp6_announces_handled ( ) ) as f64 ;
112-
113- let previous_avg = stats_lock. udp_avg_announce_processing_time_ns ( ) ;
114-
115- // Moving average: https://en.wikipedia.org/wiki/Moving_average
116- let new_avg = previous_avg as f64 + ( req_processing_time - previous_avg as f64 ) / udp_announces_handled;
89+ let new_avg = stats_lock. recalculate_udp_avg_announce_processing_time_ns ( req_processing_time) ;
11790
11891 drop ( stats_lock) ;
11992
120- tracing:: debug!(
121- "Recalculated UDP average announce processing time: {} ns (previous: {} ns, req_processing_time: {} ns, udp_announces_handled: {})" ,
122- new_avg,
123- previous_avg,
124- req_processing_time,
125- udp_announces_handled
126- ) ;
127-
12893 new_avg
12994 }
13095
131- #[ allow( clippy:: cast_precision_loss) ]
132- #[ allow( clippy:: cast_possible_truncation) ]
133- #[ allow( clippy:: cast_sign_loss) ]
13496 pub async fn recalculate_udp_avg_scrape_processing_time_ns ( & self , req_processing_time : Duration ) -> f64 {
13597 let stats_lock = self . stats . write ( ) . await ;
13698
137- let req_processing_time = req_processing_time. as_nanos ( ) as f64 ;
138- let udp_scrapes_handled = ( stats_lock. udp4_scrapes_handled ( ) + stats_lock. udp6_scrapes_handled ( ) ) as f64 ;
139-
140- let previous_avg = stats_lock. udp_avg_scrape_processing_time_ns ( ) ;
141-
142- // Moving average: https://en.wikipedia.org/wiki/Moving_average
143- let new_avg = previous_avg as f64 + ( req_processing_time - previous_avg as f64 ) / udp_scrapes_handled;
99+ let new_avg = stats_lock. recalculate_udp_avg_scrape_processing_time_ns ( req_processing_time) ;
144100
145101 drop ( stats_lock) ;
146102
147- tracing:: debug!(
148- "Recalculated UDP average scrape processing time: {} ns (previous: {} ns, req_processing_time: {} ns, udp_scrapes_handled: {})" ,
149- new_avg,
150- previous_avg,
151- req_processing_time,
152- udp_scrapes_handled
153- ) ;
154-
155103 new_avg
156104 }
157105}
0 commit comments