1515use std:: time:: Duration ;
1616
1717use quickwit_common:: metrics:: MEMORY_METRICS ;
18+ use quickwit_common:: rate_limited_warn;
1819use tikv_jemallocator:: Jemalloc ;
19- use tracing:: { error, warn } ;
20+ use tracing:: error;
2021
2122#[ cfg( feature = "jemalloc-profiled" ) ]
2223#[ global_allocator]
@@ -39,28 +40,32 @@ pub async fn jemalloc_metrics_loop() -> tikv_jemalloc_ctl::Result<()> {
3940 let resident_mib = tikv_jemalloc_ctl:: stats:: resident:: mib ( ) ?;
4041
4142 let mut poll_interval = tokio:: time:: interval ( JEMALLOC_METRICS_POLLING_INTERVAL ) ;
43+ poll_interval. set_missed_tick_behavior ( tokio:: time:: MissedTickBehavior :: Delay ) ;
4244
4345 loop {
4446 poll_interval. tick ( ) . await ;
4547
46- // Many statistics are cached and only updated when the epoch is advanced. A transient
47- // failure here would not be expected, but we log and retry on the next tick rather than
48- // exiting the loop and leaving the metrics frozen forever.
4948 if let Err ( error) = epoch_mib. advance ( ) {
50- warn ! ( %error, "failed to advance jemalloc epoch" ) ;
49+ rate_limited_warn ! ( limit_per_min = 1 , %error, "failed to advance jemalloc epoch" ) ;
5150 continue ;
5251 }
5352 match active_mib. read ( ) {
5453 Ok ( active) => memory_metrics. active_bytes . set ( active as i64 ) ,
55- Err ( error) => warn ! ( %error, "failed to read jemalloc stats.active" ) ,
54+ Err ( error) => {
55+ rate_limited_warn ! ( limit_per_min = 1 , %error, "failed to read jemalloc stats.active" ) ;
56+ }
5657 }
5758 match allocated_mib. read ( ) {
5859 Ok ( allocated) => memory_metrics. allocated_bytes . set ( allocated as i64 ) ,
59- Err ( error) => warn ! ( %error, "failed to read jemalloc stats.allocated" ) ,
60+ Err ( error) => {
61+ rate_limited_warn ! ( limit_per_min = 1 , %error, "failed to read jemalloc stats.allocated" ) ;
62+ }
6063 }
6164 match resident_mib. read ( ) {
6265 Ok ( resident) => memory_metrics. resident_bytes . set ( resident as i64 ) ,
63- Err ( error) => warn ! ( %error, "failed to read jemalloc stats.resident" ) ,
66+ Err ( error) => {
67+ rate_limited_warn ! ( limit_per_min = 1 , %error, "failed to read jemalloc stats.resident" ) ;
68+ }
6469 }
6570 }
6671}
0 commit comments