Wait for process instead of polling its status.

This provides a huge performance boost for pipelines that end in an
external command. Rough testing shows an improvement from roughly 400ms
to 30ms when `cat`-ing a large file.
This commit is contained in:
Jason Gedge 2019-12-22 14:14:03 -03:30
parent f9da7f7d58
commit 8cadc5a4ac

View File

@ -170,29 +170,17 @@ pub(crate) async fn run_external_command(
let name_tag = command.name_tag.clone(); let name_tag = command.name_tag.clone();
if let Ok(mut popen) = popen { if let Ok(mut popen) = popen {
popen.detach();
match stream_next { match stream_next {
StreamNext::Last => { StreamNext::Last => {
popen.detach(); let _ = popen.wait();
loop {
match popen.poll() {
None => {
std::thread::sleep(std::time::Duration::new(0, 100_000_000));
}
_ => {
let _ = popen.terminate();
break;
}
}
}
Ok(ClassifiedInputStream::new()) Ok(ClassifiedInputStream::new())
} }
StreamNext::External => { StreamNext::External => {
popen.detach();
let stdout = popen.stdout.take().unwrap(); let stdout = popen.stdout.take().unwrap();
Ok(ClassifiedInputStream::from_stdout(stdout)) Ok(ClassifiedInputStream::from_stdout(stdout))
} }
StreamNext::Internal => { StreamNext::Internal => {
popen.detach();
let stdout = popen.stdout.take().unwrap(); let stdout = popen.stdout.take().unwrap();
let file = futures::io::AllowStdIo::new(stdout); let file = futures::io::AllowStdIo::new(stdout);
let stream = Framed::new(file, LinesCodec {}); let stream = Framed::new(file, LinesCodec {});