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

Background service improvements #139

Open
1 of 6 tasks
mratsim opened this issue May 16, 2020 · 0 comments
Open
1 of 6 tasks

Background service improvements #139

mratsim opened this issue May 16, 2020 · 0 comments
Labels
enhancement :shipit: New feature or request

Comments

@mratsim
Copy link
Owner

mratsim commented May 16, 2020

#136 is an initial implementation of Weave as a background service
with facilities to submit jobs from threads foreign to Weave.

Here are parts that were sacrificed and can be improved:

  • The job queue is a MPSC queue accessible on Weave side by a single manager/root thread.

    • It can be working and prevents jobs from entering scheduling on steal request
      • This was already true and is not a problem if tasks are fine-graind or with loadBalance calls in jobs.
    • If all workers are sleeping and 10 tasks are enqueued, only the direct child threads will be woken up. But those will work on the stolen task instead of requesting more for their children. This is the same problem as load balancing on backed off child wake-up. #90 solved
    • Alternatively, the job queue can be made MPMC however MPMC queue design is hard, they also suffer from contention which hurts latency and may not be better than having a MPSC queue and a thread redistributing work.
    • Furthermore the manager thread may become dedicated to the following tasks in the future:
  • Foreign thread waitFor is implemented via exponential backoff

    proc waitFor*[T](p: Pending[T]): T {.inline.} =
    ## Wait for a pending value
    ## This blocks the thread until the value is ready
    ## and then returns it.
    preCondition: onSubmitterThread
    var backoff = 1
    while not p.isReady:
    sleep(backoff)
    backoff *= 2
    if backoff > 16:
    backoff = 16
    let ok = p.fv.tryComplete(result)
    ascertain: ok
    cleanup(p.fv)
    . Instead it should use the event notifier to not use any CPU resource at all and save on energy. This would probably require a new flag in task/job and storing a pointer to the whole Pending instead of just to the channel. Hopefully checking this flag is costless due to branch prediction.

  • the parallel_jobs and parallel_tasks module are 90% the same code. This should be factorized in parallel_macros

  • There is no metrics and profiling for jobs

  • There is almost no example for Weave as a background service

  • There is no benchmark for Weave as a background service

@mratsim mratsim added the enhancement :shipit: New feature or request label May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement :shipit: New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant