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

Perf/background task scheduler #6655

Merged
merged 14 commits into from
Feb 8, 2024
Merged

Perf/background task scheduler #6655

merged 14 commits into from
Feb 8, 2024

Conversation

asdacap
Copy link
Contributor

@asdacap asdacap commented Feb 5, 2024

Add a general purpose scheduler for running background tasks.

  • Task is queued using a channel and have concurrency limit.
  • Task have deadline.
  • If block processing happen during a task processing, its cancellation token will be cancelled.

Effect

  • (after, before), OldBlocks and OldReceipts.
    Screenshot_2024-02-06_08-56-49

  • Looks more like it got worst. could just be that I was using the desktop before.

  • Snap serving barely have any effect in the first place.
    Screenshot_2024-02-06_22-45-29

  • With this background thread scheduler, I've no idea if it do something or it is just noise.
    Screenshot_2024-02-06_22-39-11

  • It does serve 25% more nodes per second though.

Changes

  • Added IBackgroundThreadScheduler.
  • Integrated with IBlockProcessor and other protocol handler including tx handling.

Types of changes

What types of changes does your code introduce?

  • Optimization

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

  • Barely see any effect. Need @kamilchodola to have a more precise look.

Documentation

Requires documentation update

  • Yes
  • No

Requires explanation in Release Notes

  • Yes

  • No

  • Schedule background task to not occur during block processing.

@asdacap asdacap changed the title Perf/background task scheduler scheduler Perf/background task scheduler Feb 5, 2024
@asdacap asdacap marked this pull request as ready for review February 6, 2024 15:09
@asdacap asdacap requested a review from rubo as a code owner February 6, 2024 15:09
Copy link
Member

@benaadams benaadams left a comment

Choose a reason for hiding this comment

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

_restartQueueSignal.WaitOneAsync in BackgroundTaskScheduler.cs needs a bit of work

@asdacap asdacap merged commit 956c49f into master Feb 8, 2024
67 checks passed
@asdacap asdacap deleted the perf/sync-scheduler branch February 8, 2024 01:31
Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

Consider using ValueTasks everywhere where Task.FromResult is used.
P2PMessages need to be disposable and use disposable objects - like ArrayPoolList for collections, maybe also Pools for some complex objects can be achieved?

}

protected BlockHeadersMessage FulfillBlockHeadersRequest(GetBlockHeadersMessage msg)
protected Task<BlockHeadersMessage> FulfillBlockHeadersRequest(GetBlockHeadersMessage msg, CancellationToken cancellationToken)
Copy link
Member

Choose a reason for hiding this comment

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

Why Task in the first place? Why not ValueTask if really needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that Task should still be the default unless it has been shown that ValueTask improve performance.

{
Array.Resize(ref blocks, i + 1);
break;
}
}

return new BlockBodiesMessage(blocks);
return Task.FromResult(new BlockBodiesMessage(blocks));
Copy link
Member

Choose a reason for hiding this comment

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

can we move from Array->ArrayPoolList?

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.

3 participants