proxmox-backup-proxy: use tokio::task::spawn_blocking instead of block_in_place

allow the current thread to do some other work in-between

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dietmar Maurer 2021-10-13 10:24:40 +02:00 committed by Thomas Lamprecht
parent fa49d0fde9
commit 4b709ade68

View File

@ -920,11 +920,16 @@ fn rrd_update_derive(name: &str, value: f64) {
} }
async fn generate_host_stats() { async fn generate_host_stats() {
match tokio::task::spawn_blocking(generate_host_stats_sync).await {
Ok(()) => (),
Err(err) => log::error!("generate_host_stats paniced: {}", err),
}
}
fn generate_host_stats_sync() {
use proxmox::sys::linux::procfs::{ use proxmox::sys::linux::procfs::{
read_meminfo, read_proc_stat, read_proc_net_dev, read_loadavg}; read_meminfo, read_proc_stat, read_proc_net_dev, read_loadavg};
pbs_runtime::block_in_place(move || {
match read_proc_stat() { match read_proc_stat() {
Ok(stat) => { Ok(stat) => {
rrd_update_gauge("host/cpu", stat.cpu); rrd_update_gauge("host/cpu", stat.cpu);
@ -994,8 +999,6 @@ async fn generate_host_stats() {
eprintln!("read datastore config failed - {}", err); eprintln!("read datastore config failed - {}", err);
} }
} }
});
} }
fn check_schedule(worker_type: &str, event_str: &str, id: &str) -> bool { fn check_schedule(worker_type: &str, event_str: &str, id: &str) -> bool {