Skip to content

Commit c4145f0

Browse files
Avoid spinning when workers have no dataflows (#463)
* Avoid spinning when workers have no dataflows * Improve worker API to be more clear
1 parent 6f50573 commit c4145f0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

timely/src/execute.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ where
155155
let alloc = crate::communication::allocator::thread::Thread::new();
156156
let mut worker = crate::worker::Worker::new(WorkerConfig::default(), alloc);
157157
let result = func(&mut worker);
158-
while worker.step_or_park(None) { }
158+
while worker.has_dataflows() {
159+
worker.step_or_park(None);
160+
}
159161
result
160162
}
161163

@@ -283,7 +285,9 @@ where
283285
}
284286

285287
let result = func(&mut worker);
286-
while worker.step_or_park(None) { }
288+
while worker.has_dataflows() {
289+
worker.step_or_park(None);
290+
}
287291
result
288292
})
289293
}
@@ -382,7 +386,9 @@ where
382386
initialize_from(builders, others, move |allocator| {
383387
let mut worker = Worker::new(worker_config.clone(), allocator);
384388
let result = func(&mut worker);
385-
while worker.step_or_park(None) { }
389+
while worker.has_dataflows() {
390+
worker.step_or_park(None);
391+
}
386392
result
387393
})
388394
}

timely/src/worker.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl<A: Allocate> Worker<A> {
366366
(x, y) => x.or(y),
367367
};
368368

369-
if !self.dataflows.borrow().is_empty() && delay != Some(Duration::new(0,0)) {
369+
if delay != Some(Duration::new(0,0)) {
370370

371371
// Log parking and flush log.
372372
if let Some(l) = self.logging().as_mut() {
@@ -698,6 +698,11 @@ impl<A: Allocate> Worker<A> {
698698
self.dataflows.borrow().keys().cloned().collect()
699699
}
700700

701+
/// True if there is at least one dataflow under management.
702+
pub fn has_dataflows(&self) -> bool {
703+
!self.dataflows.borrow().is_empty()
704+
}
705+
701706
// Acquire a new distinct dataflow identifier.
702707
fn allocate_dataflow_index(&mut self) -> usize {
703708
*self.dataflow_counter.borrow_mut() += 1;

0 commit comments

Comments
 (0)