Skip to content

auto spawn new worker thread #744

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

Closed
wants to merge 2 commits into from
Closed

auto spawn new worker thread #744

wants to merge 2 commits into from

Conversation

win-t
Copy link

@win-t win-t commented Apr 9, 2020

Hi guys, this is my proposal for solving #740

what changes I made:

  • make the runtime to able scale up dan scale down the number of workers thread
    • Wrap stealers with RwLock because we need to able to modify it later
    • instead of creating stealer for each worker in Runtime::new I combined it with the creation of the thread into Runtime::start_new_thread
    • scaling up is by sending a message to runtime to call Runtime::start_new_thread
    • scaling down is by pushing exit message to the global queue, so a random worker will pick it later and terminate itself
  • Create a monitor thread
    • this thread will run alongside runtime thread
    • this thread will detect blocking call by creating a task that does an infinite loop, this task is an indicator that runtime is still running if this task failed to run, it means that all worker thread is blocked

btw, I need insight on atomic ordering, I don't understand it well, I don't think SeqCst is needed

I don't know how to test the performance overhead of this solution, so I need advice here

@win-t win-t force-pushed the master branch 2 times, most recently from 7714038 to b46c151 Compare April 9, 2020 09:46
@win-t
Copy link
Author

win-t commented Apr 9, 2020

adding the capability for the users to set their own monitoring policy, so they can tunning the monitor to meet specific performance requirement.

@skade
Copy link
Collaborator

skade commented Apr 9, 2020

@win-t I would not want to expose an additional public module.

@win-t
Copy link
Author

win-t commented Apr 9, 2020

yeah, @skade I think so, introducing public API was not my original proposal, let's do it step by step,
for now, just focus on how to handle the blocking part,

I still have doubt about the action: scaling up the runtime or just abort the whole program

that doubt drive me to think that the user should decide it by themself by exposing via new API, but I don't think that is also a good idea,

@win-t
Copy link
Author

win-t commented Apr 9, 2020

I decide to just scale up the runtime, if the users want to abort, they can create their own monitor thread, because that doesn't need access to internal runtime

now we need to come up with the right value of probing interval that everyone happy with

fn schedule(&self, rt: &Runtime, task: Runnable) {
self.processor.lock().schedule(rt, task);
fn schedule(&self, rt: &Runtime, task: Task) {
if !self.drained.load(Ordering::SeqCst /* ??? */) {
Copy link
Author

@win-t win-t Apr 9, 2020

Choose a reason for hiding this comment

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

this is hot path, and I don't fully understand what SeqCst mean, maybe other values give better performance

@win-t win-t mentioned this pull request Apr 9, 2020
@win-t
Copy link
Author

win-t commented Apr 10, 2020

Just hold this PR for now until #748 is resolved

@win-t win-t closed this Apr 10, 2020
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.

2 participants