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

Implement worker autoscaling #12

Merged
merged 1 commit into from Aug 5, 2019

Conversation

talbenari1
Copy link

@talbenari1 talbenari1 commented Jul 16, 2019

Rather than running each worker in a single separate thread, I'm now creating a new threadpool for each worker. Since threadpools will only spawn new threads as needed, we don't have to create our own load pressure detection method. One downside of this is that the first request to each worker is slower, so to deal with that (and to fix issues with workers that fail to start) I spawn an empty task onto the isolate's threadpool to wake up a single isolate instance.

This should speed things up, like, a lot. Especially in cases where most of the time is spent in userland.

A couple of other minor things:

  • This also features backpressure support from the main threadpool, but since Tokio internally handles autoscaling, it's not currently being used (I'll take advantage of it in a future commit) EDIT: this was removed due to crosstalk-like issues among requests being handled by the same hyper tokio thread
  • Removed trailing slashes from gitignore
  • Increased delay before running integration tests because they were being a bit flaky for me

src/main.rs Outdated Show resolved Hide resolved
@talbenari1 talbenari1 force-pushed the talbenari1/autoscale branch 2 times, most recently from d2ce306 to a135eef Compare July 16, 2019 23:27
@talbenari1 talbenari1 force-pushed the talbenari1/autoscale branch 2 times, most recently from d3452c7 to 5d77fa2 Compare July 31, 2019 00:07
Rather than running each worker in a single separate thread, I'm now
creating a new threadpool for each worker. Since threadpools will only
spawn new threads as needed, we don't have to create our own load
pressure detection method. One downside of this is that the first
request to each worker is slower, so to deal with that (and to fix
issues with workers that fail to start) I spawn an empty task onto the
isolate's threadpool to wake up a single isolate instance.

Note that the while the threadpool will always be created, only one
instance will be created by default (i.e. autoscaling will be disabled)
until we figure out a good story for applications that rely on global
state. For now, the feature will be hidden behind a
'--experimental-autoscale' flag.
@@ -37,6 +37,7 @@ pub fn handle_inbound((req, tx): Message, origin: &str) -> impl Future<Item = ()

req.into_body()
.for_each(move |chunk| {
let context = get_context();
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you need these in this file for?

Copy link
Author

@talbenari1 talbenari1 Aug 5, 2019

Choose a reason for hiding this comment

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

Since the body chunks are received asynchronously, there is a possibility that the context will have been destroyed before the request finishes processing, which can cause segfaults. These will panic with sane error messages instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha.

@bengl bengl merged commit 1d3e54c into IntrinsicLabs:master Aug 5, 2019
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