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

Run queries in dedicated threads #1101

Merged
merged 15 commits into from
Feb 5, 2024
Merged

Run queries in dedicated threads #1101

merged 15 commits into from
Feb 5, 2024

Conversation

abizjak
Copy link
Contributor

@abizjak abizjak commented Nov 30, 2023

Purpose

Use a dedicated threadpool for running queries.

Since the queries call into Haskell it typically takes much more than 100us between await points. As a result there are problems with availability where queries pause for some time before resuming. The main reason for this seems to be that all the tokio workers are stuck in the "haskell code" so the scheduler cannot schedule other tasks, such as accepting connections, responding to requests, etc.

The guideline from tokio is that there should not be more than 10-100us in between await points.

To give a sense of scale of how much time is too much, a good rule of thumb is no more than 10 to 100 microseconds between each .await. That said, this depends on the kind of application you are writing.

(from one of the tokio developers https://ryhl.io/blog/async-what-is-blocking/ )

This is much less than the queries take typically (and queries can also block for a time due to locking).

Changes

  • Run node queries in a dedicated threadpool
  • Introduce a configuration option to limit the number of threads used for executing queries in Haskell code.
    This also allows limiting the resources the node is using for non-consensus related operations.
  • Default max-concurrent-streams to 200. This is also the default in new releases of the hyper server. Without limiting this there seem to occassionally be some blocking issues as well where the queries end up doing nothing. The default value makes the node more robust in the default configuration.
  • Update dependencies, mainly tonic & prost to get fixes for some other blocking behaviour.

Checklist

  • My code follows the style of this project.
  • The code compiles without warnings.
  • I have performed a self-review of the changes.
  • I have documented my code, in particular the intent of the
    hard-to-understand areas.
  • (If necessary) I have updated the CHANGELOG.

@abizjak abizjak changed the title Run queries in blocking threads. Run queries in dedicated threads Jan 31, 2024
concordium-node/src/configuration.rs Outdated Show resolved Hide resolved
Co-authored-by: Emil Lai <[email protected]>
Copy link
Contributor

@td202 td202 left a comment

Choose a reason for hiding this comment

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

Looks good.

concordium-node/src/grpc2.rs Show resolved Hide resolved
@abizjak abizjak merged commit 516529c into main Feb 5, 2024
3 checks passed
@abizjak abizjak deleted the grpc2-blocking-threads branch February 5, 2024 10:45
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