@@ -24,13 +24,13 @@ use crate::{
24
24
components:: proxy:: { self , PendingSends , PipelineError , SendPacket } ,
25
25
metrics,
26
26
pool:: PoolBuffer ,
27
- time:: UtcTimestamp ,
28
27
} ;
29
28
use io_uring:: { squeue:: Entry , types:: Fd } ;
30
29
use socket2:: SockAddr ;
31
30
use std:: {
32
31
os:: fd:: { AsRawFd , FromRawFd } ,
33
32
sync:: Arc ,
33
+ time:: Instant ,
34
34
} ;
35
35
36
36
/// A simple wrapper around [eventfd](https://man7.org/linux/man-pages/man2/eventfd.2.html)
@@ -227,7 +227,8 @@ pub enum PacketProcessorCtx {
227
227
fn process_packet (
228
228
ctx : & mut PacketProcessorCtx ,
229
229
packet : RecvPacket ,
230
- last_received_at : & mut Option < UtcTimestamp > ,
230
+ last_received_at : & mut Option < Instant > ,
231
+ processing_time : & prometheus:: local:: LocalHistogram ,
231
232
) {
232
233
match ctx {
233
234
PacketProcessorCtx :: Router {
@@ -237,10 +238,10 @@ fn process_packet(
237
238
error_acc,
238
239
destinations,
239
240
} => {
240
- let received_at = UtcTimestamp :: now ( ) ;
241
+ let received_at = Instant :: now ( ) ;
241
242
if let Some ( last_received_at) = last_received_at {
242
243
metrics:: packet_jitter ( metrics:: READ , & metrics:: EMPTY )
243
- . set ( ( received_at - * last_received_at) . nanos ( ) ) ;
244
+ . set ( ( received_at - * last_received_at) . as_nanos ( ) as _ ) ;
244
245
}
245
246
* last_received_at = Some ( received_at) ;
246
247
@@ -256,6 +257,7 @@ fn process_packet(
256
257
sessions,
257
258
error_acc,
258
259
destinations,
260
+ processing_time,
259
261
) ;
260
262
}
261
263
PacketProcessorCtx :: SessionPool { pool, port, .. } => {
@@ -453,6 +455,8 @@ impl IoUringLoop {
453
455
// Just double buffer the pending writes for simplicity
454
456
let mut double_pending_sends = Vec :: with_capacity ( pending_sends. capacity ( ) ) ;
455
457
458
+ let processing_metrics = metrics:: ProcessingMetrics :: new ( ) ;
459
+
456
460
// When sending packets, this is the direction used when updating metrics
457
461
let send_dir = if matches ! ( ctx, PacketProcessorCtx :: Router { .. } ) {
458
462
metrics:: WRITE
@@ -478,6 +482,8 @@ impl IoUringLoop {
478
482
// onto the submission queue for the loop to actually function (ie, similar to await on futures)
479
483
loop_ctx. sync ( ) ;
480
484
485
+ const FLUSH_INTERVAL : std:: time:: Duration = std:: time:: Duration :: from_secs ( 15 ) ;
486
+ let mut time_since_flush = std:: time:: Duration :: default ( ) ;
481
487
let mut last_received_at = None ;
482
488
483
489
// The core io uring loop
@@ -520,7 +526,24 @@ impl IoUringLoop {
520
526
}
521
527
522
528
let packet = packet. finalize_recv ( ret as usize ) ;
523
- process_packet ( & mut ctx, packet, & mut last_received_at) ;
529
+ let old_received_at = last_received_at. clone ( ) ;
530
+ process_packet (
531
+ & mut ctx,
532
+ packet,
533
+ & mut last_received_at,
534
+ & processing_metrics. read_processing_time ,
535
+ ) ;
536
+
537
+ if let ( Some ( old_received_at) , Some ( last_received_at) ) =
538
+ ( & old_received_at, & last_received_at)
539
+ {
540
+ time_since_flush += * last_received_at - * old_received_at;
541
+
542
+ if time_since_flush >= FLUSH_INTERVAL {
543
+ time_since_flush = <_ >:: default ( ) ;
544
+ processing_metrics. flush ( ) ;
545
+ }
546
+ }
524
547
525
548
loop_ctx. enqueue_recv ( buffer_pool. clone ( ) . alloc ( ) ) ;
526
549
}
0 commit comments