New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sleep in Shellout.executeStream to reduce spinning. #578

Merged
merged 1 commit into from Mar 18, 2017

Conversation

Projects
None yet
2 participants
@rorygraves
Contributor

rorygraves commented Mar 18, 2017

Whilst waiting for IO Shellout.executeStream was running a tight loop and consuming significant
amounts of CPU. Adding a small sleep when no input was seen reduces cpu usage significant.

Add a sleep in Shellout.executeStream to reduce spinning.
Whilst waiting for IO Shellout.executeStream was running a tight loop and consuming significant
amounts of CPU.  Adding a small sleep when no input was seen reduces cpu usage significant.
@@ -65,14 +65,17 @@ object Shellout{
val stdout = process.getInputStream
val stderr = process.getErrorStream
val chunks = collection.mutable.Buffer.empty[Either[Bytes, Bytes]]
val sources = Seq(stdout -> (Left(_: Bytes)), stderr -> (Right(_: Bytes)))

This comment has been minimized.

@rorygraves

rorygraves Mar 18, 2017

Contributor

This prevents allocations during each cycle.

@@ -81,6 +84,9 @@ object Shellout{
))
}
}
// if we did not read anything sleep briefly to avoid spinning

This comment has been minimized.

@rorygraves

rorygraves Mar 18, 2017

Contributor

Only sleep if we have not seen input during this iteration. This means that for fast processes we do not add unnecessary pauses.

@rorygraves

This comment has been minimized.

Contributor

rorygraves commented Mar 18, 2017

@lihaoyi CI build failure looks unrelated

@lihaoyi

This comment has been minimized.

Owner

lihaoyi commented Mar 18, 2017

Thanks!

@lihaoyi lihaoyi merged commit fabce69 into lihaoyi:master Mar 18, 2017

1 of 2 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment