Skip to content

Commit aebba2b

Browse files
authored
Merge pull request #747 from async-rs/fix/scheduler-perf
Fix new scheduler loop
2 parents fc4e472 + 0c9a66c commit aebba2b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: src/rt/runtime.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ impl Machine {
249249
continue;
250250
}
251251

252+
let mut sched = rt.sched.lock().unwrap();
253+
252254
// One final check for available tasks while the scheduler is locked.
253255
if let Some(task) = iter::repeat_with(|| self.find_task(rt))
254256
.find(|s| !s.is_retry())
@@ -258,19 +260,19 @@ impl Machine {
258260
continue;
259261
}
260262

261-
let mut sched = rt.sched.lock().unwrap();
262-
263+
// If another thread is already blocked on the reactor, there is no point in keeping
264+
// the current thread around since there is too little work to do.
263265
if sched.polling {
264-
thread::sleep(Duration::from_micros(10));
265-
continue;
266+
break;
266267
}
267268

269+
// Unlock the schedule poll the reactor until new I/O events arrive.
268270
sched.polling = true;
269271
drop(sched);
270-
271272
rt.reactor.poll(None).unwrap();
272273

273-
let mut sched = rt.sched.lock().unwrap();
274+
// Lock the scheduler again and re-register the machine.
275+
sched = rt.sched.lock().unwrap();
274276
sched.polling = false;
275277

276278
runs = 0;

0 commit comments

Comments
 (0)