Skip to content
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
Merged

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

merged 1 commit into from Mar 18, 2017

Conversation

rorygraves
Copy link
Contributor

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.

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)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents allocations during each cycle.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@rorygraves
Copy link
Contributor Author

@lihaoyi CI build failure looks unrelated

@lihaoyi
Copy link
Member

lihaoyi commented Mar 18, 2017

Thanks!

@lihaoyi lihaoyi merged commit fabce69 into com-lihaoyi:master Mar 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants