Skip to content

Commit

Permalink
Merge pull request #844 from golemfactory/mf/exe-unit/fix-cores-threads
Browse files Browse the repository at this point in the history
Fix for used VM cpu core count + hardware change detection
  • Loading branch information
mfranciszkiewicz authored Dec 2, 2020
2 parents ad5db54 + f418d18 commit ea893c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions agent/provider/src/startup_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,37 @@ impl FileMonitor {
let (tx, rx) = mpsc::channel();
let (tx_ctl, mut rx_ctl) = oneshot::channel();

let watch_delay = Duration::from_secs(2);
let sleep_delay = Duration::from_secs_f32(0.5);
let watch_delay = Duration::from_secs(3);
let sleep_delay = Duration::from_secs(2);
let mut watcher: RecommendedWatcher = Watcher::new(tx, watch_delay)?;

std::thread::spawn(move || {
if let Err(e) = watcher.watch(&path_th, RecursiveMode::NonRecursive) {
log::error!("Unable to monitor path '{:?}': {}", path_th, e);
return;
}
let mut active = false;
loop {
if !active {
match watcher.watch(&path_th, RecursiveMode::NonRecursive) {
Ok(_) => active = true,
Err(e) => log::error!("Unable to monitor path '{:?}': {}", path_th, e),
}
}
if let Ok(event) = rx.try_recv() {
match &event {
DebouncedEvent::Rename(_, _) | DebouncedEvent::Remove(_) => {
let _ = watcher.unwatch(&path_th);
active = false
}
_ => (),
}
handler(event);
continue;
}

if let Ok(Some(_)) = rx_ctl.try_recv() {
break;
}
std::thread::sleep(sleep_delay);
}
log::debug!("Stopping file monitor: {:?}", path_th);
log::error!("Stopping file monitor: {:?}", path_th);
});

Ok(Self {
Expand All @@ -278,6 +290,7 @@ impl FileMonitor {
DebouncedEvent::Write(p)
| DebouncedEvent::Chmod(p)
| DebouncedEvent::Create(p)
| DebouncedEvent::Remove(p)
| DebouncedEvent::Rename(_, p) => {
f(p);
}
Expand Down
2 changes: 1 addition & 1 deletion exe-unit/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl RuntimeArgs {
let mut mem_gib = None;
let mut storage_gib = None;
if with_inf {
cpu_cores = agreement.infrastructure.get("cpu.cores").cloned();
cpu_cores = agreement.infrastructure.get("cpu.threads").cloned();
mem_gib = agreement.infrastructure.get("mem.gib").cloned();
storage_gib = agreement.infrastructure.get("storage.gib").cloned();
}
Expand Down

0 comments on commit ea893c1

Please sign in to comment.