-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
functions: common concurrency stream for sync and async #314
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Couple questions @ccirello:
|
@treeder now that I have the information that the runner regulates itself, there's no need for max runners. I am going to remove this extra mechanism. |
ee7d4cf
to
993e1f9
Compare
Ensure that Sync tasks are consumed before Async tasks. Also, fixes termination races problems for free.
pedronasser
approved these changes
Nov 17, 2016
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proposal that addresses concerns some aspects of #165 and #69.
1 - We have now a supervised goroutine that spawns workers for the incoming load. They serve any kind of request, sync or async (#165)
2 - Because runners start are separate from request life-cycle, we would be a third way closer to have hot reusable containers (#69)
Edit:
Implementation Details
This PR introduces new goroutine responsible solely for executing tasks. It interfaces with the HTTP server and async modules through a channel, whose contents holds both the task information, and a channel to send the answer backer to the caller. https://github.com/iron-io/functions/blob/bounded-concurrency/api/server/runner.go#L183-L188 and https://github.com/iron-io/functions/blob/bounded-concurrency/api/runner/async_runner.go#L142-L145
In order to prevent resource starvation between competing sync and async tasks, we reserve a maxium of 50% of the memory for async tasks. This number is arbitrary and might be subject to changes later. https://github.com/iron-io/functions/blob/bounded-concurrency/api/runner/runner.go#L118-L123
In practice, when the memory allocated for async workers is maxed out, it keeps looping until memory is available: https://github.com/iron-io/functions/blob/bounded-concurrency/api/runner/async_runner.go#L117-L121
Also relevant is that
Server
now fathers handleRequest https://github.com/iron-io/functions/blob/bounded-concurrency/api/server/runner.go#L37 - with which it injects the tasks channel into the HTTP server.