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

feat: sched: Cache worker calls #9737

Merged
merged 3 commits into from
Nov 29, 2022
Merged

Conversation

magik6k
Copy link
Contributor

@magik6k magik6k commented Nov 28, 2022

Related Issues

Based on on #9738

Proposed Changes

I've re-read the scheduler code today, and realized that all calls to workers in the scheduling loop are perfectly cachable. This PR adds some caching in the scheduling loop, theoretically reducing the number of workers calls in a scheduling cycle from tasksToSchedule*candidateOpenWindows to unique(candidateOpenWindows.Worker)

Additional Info

Benchmark on 400 deep queue with 200 workers (tldr ~700x faster when network roundtrips are ~100us)

Before:

BenchmarkTrySched/200w-400q
BenchmarkTrySched/200w-400q-32         	       1	79 854 360 185 ns/op

After:

BenchmarkTrySched/200w-400q
BenchmarkTrySched/200w-400q-32         	       9	 114 381 511 ns/op

Checklist

Before you mark the PR ready for review, please make sure that:

  • Commits have a clear commit message.
  • PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
    • area, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps
  • New features have usage guidelines and / or documentation updates in
  • Tests exist for new functionality or change in behavior
  • CI is green

@magik6k magik6k force-pushed the feat/cache-sched-worker-calls branch 4 times, most recently from 329116a to fb3e9a6 Compare November 28, 2022 18:28
@magik6k magik6k marked this pull request as ready for review November 28, 2022 18:31
@magik6k magik6k requested a review from a team as a code owner November 28, 2022 18:31
@magik6k magik6k force-pushed the feat/cache-sched-worker-calls branch from fb3e9a6 to dee3de9 Compare November 28, 2022 19:05
Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

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

Approved with two nits looking for comments to make code slightly more clear.

Comment on lines 591 to 602
func (s slowishSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, a SchedWorker) (bool, bool, error) {
_, _ = a.Paths(ctx)
_, _ = a.TaskTypes(ctx)
return bool(s), false, nil
}

func (s slowishSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b *WorkerHandle) (bool, error) {
time.Sleep(100 * time.Microsecond)
func (s slowishSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b SchedWorker) (bool, error) {
_, _ = a.Paths(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you leave a comment here as to why you're ignoring the outputs of the function calls?

Comment on lines 68 to 72
partDone := metrics.Timer(sh.mctx, metrics.SchedAssignerCandidatesDuration)
defer func() {
partDone()
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you leave a comment here saying that this defer is meant to call the latest value of partDone in case we error out somewhere.

@magik6k magik6k force-pushed the feat/cache-sched-worker-calls branch from dee3de9 to 2fd7550 Compare November 29, 2022 10:45
@magik6k magik6k force-pushed the feat/cache-sched-worker-calls branch from 2fd7550 to 1597e85 Compare November 29, 2022 10:46
@magik6k magik6k merged commit a0422f6 into master Nov 29, 2022
@magik6k magik6k deleted the feat/cache-sched-worker-calls branch November 29, 2022 11:58
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