The following code loops indefinitely without pause, this leads to 100% CPU usage in all our environment (dev/qual/prod). We disabled the analytics processor in the meantime.
Solution
Use rx.recv_timeout rather than try_recv which is non blocking.
|
.spawn(move || { |
|
let mut last_flushed = chrono::Utc::now(); |
|
loop { |
|
let data = rx.try_recv(); |
|
let mut analytics_data = analytics_data_locked.write().unwrap(); |
|
match data { |
|
// Update the analytics data with feature_id received |
|
Ok(feature_name) => { |
|
analytics_data |
|
.entry(feature_name) |
|
.and_modify(|e| *e += 1) |
|
.or_insert(1); |
|
} |
|
Err(flume::TryRecvError::Empty) => {} |
|
Err(flume::TryRecvError::Disconnected) => { |
|
debug!("Shutting down analytics thread "); |
|
break; |
|
} |
|
}; |
|
if (chrono::Utc::now() - last_flushed).num_milliseconds() > timer as i64 { |
|
flush(&client, &analytics_data, &analytics_endpoint); |
|
analytics_data.clear(); |
|
last_flushed = chrono::Utc::now(); |
|
} |
The following code loops indefinitely without pause, this leads to 100% CPU usage in all our environment (dev/qual/prod). We disabled the analytics processor in the meantime.
Solution
Use
rx.recv_timeoutrather thantry_recvwhich is non blocking.flagsmith-rust-client/src/flagsmith/analytics.rs
Lines 38 to 61 in 693b1fe