mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Change the QUEUE_STRUCTURE to an ArcSwap, further reducing locking.
This commit is contained in:
1
src/rust/Cargo.lock
generated
1
src/rust/Cargo.lock
generated
@@ -1782,6 +1782,7 @@ name = "lqos_queue_tracker"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arc-swap",
|
||||
"criterion",
|
||||
"dashmap",
|
||||
"lqos_bus",
|
||||
|
||||
@@ -17,6 +17,7 @@ tokio = { workspace = true }
|
||||
once_cell = { workspace = true}
|
||||
dashmap = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
arc-swap = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0", features = [ "html_reports"] }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::sync::RwLock;
|
||||
|
||||
use std::sync::Arc;
|
||||
use arc_swap::ArcSwap;
|
||||
use crate::queue_structure::{
|
||||
queue_network::QueueNetwork, queue_node::QueueNode, read_queueing_structure,
|
||||
};
|
||||
@@ -9,8 +9,8 @@ use once_cell::sync::Lazy;
|
||||
use thiserror::Error;
|
||||
use crate::tracking::ALL_QUEUE_SUMMARY;
|
||||
|
||||
pub(crate) static QUEUE_STRUCTURE: Lazy<RwLock<QueueStructure>> =
|
||||
Lazy::new(|| RwLock::new(QueueStructure::new()));
|
||||
pub(crate) static QUEUE_STRUCTURE: Lazy<ArcSwap<QueueStructure>> =
|
||||
Lazy::new(|| ArcSwap::new(Arc::new(QueueStructure::new())));
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct QueueStructure {
|
||||
@@ -25,15 +25,6 @@ impl QueueStructure {
|
||||
Self { maybe_queues: None }
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self) {
|
||||
ALL_QUEUE_SUMMARY.clear();
|
||||
if let Ok(queues) = read_queueing_structure() {
|
||||
self.maybe_queues = Some(queues);
|
||||
} else {
|
||||
self.maybe_queues = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Global file watched for `queueStructure.json`.
|
||||
@@ -52,7 +43,9 @@ pub fn spawn_queue_structure_monitor() -> anyhow::Result<()> {
|
||||
|
||||
fn update_queue_structure() {
|
||||
debug!("queueingStructure.json reloaded");
|
||||
QUEUE_STRUCTURE.write().unwrap().update();
|
||||
let new_queue_structure = QueueStructure::new();
|
||||
ALL_QUEUE_SUMMARY.clear();
|
||||
QUEUE_STRUCTURE.store(Arc::new(new_queue_structure));
|
||||
}
|
||||
|
||||
/// Fires up a Linux file system watcher than notifies
|
||||
|
||||
@@ -139,7 +139,7 @@ fn connect_queues_to_circuit_up(structure: &[QueueNode], queues: &[QueueType]) -
|
||||
|
||||
fn all_queue_reader() {
|
||||
let start = Instant::now();
|
||||
let structure = QUEUE_STRUCTURE.read().unwrap();
|
||||
let structure = QUEUE_STRUCTURE.load();
|
||||
if let Some(structure) = &structure.maybe_queues {
|
||||
if let Ok(config) = lqos_config::load_config() {
|
||||
// Get all the queues
|
||||
|
||||
@@ -55,7 +55,8 @@ pub fn add_watched_queue(circuit_id: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(queues) = &QUEUE_STRUCTURE.read().unwrap().maybe_queues {
|
||||
let queues = QUEUE_STRUCTURE.load();
|
||||
if let Some(queues) = &queues.maybe_queues {
|
||||
if let Some(circuit) = queues.iter().find(|c| {
|
||||
c.circuit_id.is_some() && c.circuit_id.as_ref().unwrap() == circuit_id
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user