refactor: massively speed up docker init process
This commit is contained in:
+2
-4
@@ -143,10 +143,10 @@ impl AppData {
|
|||||||
Self {
|
Self {
|
||||||
args,
|
args,
|
||||||
containers: StatefulList::new(vec![]),
|
containers: StatefulList::new(vec![]),
|
||||||
hidden_containers: vec![],
|
|
||||||
error: None,
|
error: None,
|
||||||
sorted_by: None,
|
|
||||||
filter: Filter::new(),
|
filter: Filter::new(),
|
||||||
|
hidden_containers: vec![],
|
||||||
|
sorted_by: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +350,6 @@ impl AppData {
|
|||||||
.back()
|
.back()
|
||||||
.cmp(&item_ord.1.mem_stats.back())
|
.cmp(&item_ord.1.mem_stats.back())
|
||||||
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
|
|
||||||
Header::Id => item_ord
|
Header::Id => item_ord
|
||||||
.0
|
.0
|
||||||
.id
|
.id
|
||||||
@@ -372,7 +371,6 @@ impl AppData {
|
|||||||
.tx
|
.tx
|
||||||
.cmp(&item_ord.1.tx)
|
.cmp(&item_ord.1.tx)
|
||||||
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
|
|
||||||
Header::Name => item_ord
|
Header::Name => item_ord
|
||||||
.0
|
.0
|
||||||
.name
|
.name
|
||||||
|
|||||||
+18
-22
@@ -59,7 +59,6 @@ pub struct DockerData {
|
|||||||
binate: Binate,
|
binate: Binate,
|
||||||
docker: Arc<Docker>,
|
docker: Arc<Docker>,
|
||||||
gui_state: Arc<Mutex<GuiState>>,
|
gui_state: Arc<Mutex<GuiState>>,
|
||||||
init: Option<Arc<AtomicUsize>>,
|
|
||||||
receiver: Receiver<DockerMessage>,
|
receiver: Receiver<DockerMessage>,
|
||||||
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
|
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
|
||||||
}
|
}
|
||||||
@@ -106,12 +105,11 @@ impl DockerData {
|
|||||||
app_data: Arc<Mutex<AppData>>,
|
app_data: Arc<Mutex<AppData>>,
|
||||||
docker: Arc<Docker>,
|
docker: Arc<Docker>,
|
||||||
id: ContainerId,
|
id: ContainerId,
|
||||||
init: Option<(Arc<AtomicUsize>, usize)>,
|
|
||||||
state: State,
|
state: State,
|
||||||
spawn_id: SpawnId,
|
spawn_id: SpawnId,
|
||||||
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
|
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
|
||||||
) {
|
) {
|
||||||
if state.is_alive() || init.is_some() {
|
if state.is_alive() {
|
||||||
let mut stream = docker
|
let mut stream = docker
|
||||||
.stats(
|
.stats(
|
||||||
id.get(),
|
id.get(),
|
||||||
@@ -168,9 +166,6 @@ impl DockerData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
spawns.lock().remove(&spawn_id);
|
spawns.lock().remove(&spawn_id);
|
||||||
if let Some((target, _)) = init {
|
|
||||||
target.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update all stats, spawn each container into own tokio::spawn thread
|
/// Update all stats, spawn each container into own tokio::spawn thread
|
||||||
@@ -181,7 +176,6 @@ impl DockerData {
|
|||||||
let spawns = Arc::clone(&self.spawns);
|
let spawns = Arc::clone(&self.spawns);
|
||||||
let spawn_id = SpawnId::Stats((id.clone(), self.binate));
|
let spawn_id = SpawnId::Stats((id.clone(), self.binate));
|
||||||
|
|
||||||
let init = self.init.as_ref().map(|i| (Arc::clone(i), all_ids.len()));
|
|
||||||
self.spawns
|
self.spawns
|
||||||
.lock()
|
.lock()
|
||||||
.entry(spawn_id.clone())
|
.entry(spawn_id.clone())
|
||||||
@@ -190,7 +184,6 @@ impl DockerData {
|
|||||||
app_data,
|
app_data,
|
||||||
docker,
|
docker,
|
||||||
id.clone(),
|
id.clone(),
|
||||||
init,
|
|
||||||
*state,
|
*state,
|
||||||
spawn_id,
|
spawn_id,
|
||||||
spawns,
|
spawns,
|
||||||
@@ -257,6 +250,7 @@ impl DockerData {
|
|||||||
app_data: Arc<Mutex<AppData>>,
|
app_data: Arc<Mutex<AppData>>,
|
||||||
docker: Arc<Docker>,
|
docker: Arc<Docker>,
|
||||||
id: ContainerId,
|
id: ContainerId,
|
||||||
|
init: Option<Arc<AtomicUsize>>,
|
||||||
since: u64,
|
since: u64,
|
||||||
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
|
spawns: Arc<Mutex<HashMap<SpawnId, JoinHandle<()>>>>,
|
||||||
) {
|
) {
|
||||||
@@ -279,18 +273,22 @@ impl DockerData {
|
|||||||
}
|
}
|
||||||
spawns.lock().remove(&SpawnId::Log(id.clone()));
|
spawns.lock().remove(&SpawnId::Log(id.clone()));
|
||||||
app_data.lock().update_log_by_id(output, &id);
|
app_data.lock().update_log_by_id(output, &id);
|
||||||
|
init.map(|i| i.fetch_add(1, std::sync::atomic::Ordering::SeqCst));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update all logs, spawn each container into own tokio::spawn thread
|
/// Update all logs, spawn each container into own tokio::spawn thread
|
||||||
fn init_all_logs(&self, all_ids: &[(State, ContainerId)]) {
|
fn init_all_logs(&self, all_ids: &[(State, ContainerId)], init: &Option<Arc<AtomicUsize>>) {
|
||||||
for (_, id) in all_ids {
|
for (_, id) in all_ids {
|
||||||
let docker = Arc::clone(&self.docker);
|
|
||||||
let app_data = Arc::clone(&self.app_data);
|
|
||||||
let spawns = Arc::clone(&self.spawns);
|
|
||||||
let key = SpawnId::Log(id.clone());
|
|
||||||
self.spawns.lock().insert(
|
self.spawns.lock().insert(
|
||||||
key,
|
SpawnId::Log(id.clone()),
|
||||||
tokio::spawn(Self::update_log(app_data, docker, id.clone(), 0, spawns)),
|
tokio::spawn(Self::update_log(
|
||||||
|
Arc::clone(&self.app_data),
|
||||||
|
Arc::clone(&self.docker),
|
||||||
|
id.clone(),
|
||||||
|
init.clone(),
|
||||||
|
0,
|
||||||
|
Arc::clone(&self.spawns),
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,6 +306,7 @@ impl DockerData {
|
|||||||
Arc::clone(&self.app_data),
|
Arc::clone(&self.app_data),
|
||||||
Arc::clone(&self.docker),
|
Arc::clone(&self.docker),
|
||||||
container.id.clone(),
|
container.id.clone(),
|
||||||
|
None,
|
||||||
last_updated,
|
last_updated,
|
||||||
Arc::clone(&self.spawns),
|
Arc::clone(&self.spawns),
|
||||||
))
|
))
|
||||||
@@ -327,14 +326,12 @@ impl DockerData {
|
|||||||
|
|
||||||
self.update_all_container_stats(&all_ids);
|
self.update_all_container_stats(&all_ids);
|
||||||
|
|
||||||
self.init_all_logs(&all_ids);
|
let init = Arc::new(AtomicUsize::new(0));
|
||||||
|
self.init_all_logs(&all_ids, &Some(Arc::clone(&init)));
|
||||||
|
|
||||||
while let Some(x) = self.init.as_ref() {
|
while init.load(std::sync::atomic::Ordering::SeqCst) != all_ids.len() {
|
||||||
self.app_data.lock().sort_containers();
|
self.app_data.lock().sort_containers();
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
|
||||||
if x.load(std::sync::atomic::Ordering::SeqCst) == all_ids.len() {
|
|
||||||
self.init = None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.gui_state.lock().stop_loading_animation(loading_uuid);
|
self.gui_state.lock().stop_loading_animation(loading_uuid);
|
||||||
self.gui_state.lock().status_del(Status::Init);
|
self.gui_state.lock().status_del(Status::Init);
|
||||||
@@ -441,7 +438,6 @@ impl DockerData {
|
|||||||
binate: Binate::One,
|
binate: Binate::One,
|
||||||
docker: Arc::new(docker),
|
docker: Arc::new(docker),
|
||||||
gui_state,
|
gui_state,
|
||||||
init: Some(Arc::new(AtomicUsize::new(0))),
|
|
||||||
receiver: docker_rx,
|
receiver: docker_rx,
|
||||||
spawns: Arc::new(Mutex::new(HashMap::new())),
|
spawns: Arc::new(Mutex::new(HashMap::new())),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user