Skip to content

feat: add semaphore for blocking IO requests#20289

Merged
mattsse merged 7 commits intomainfrom
matt/add-max-call-requests
Dec 11, 2025
Merged

feat: add semaphore for blocking IO requests#20289
mattsse merged 7 commits intomainfrom
matt/add-max-call-requests

Conversation

@mattsse
Copy link
Collaborator

@mattsse mattsse commented Dec 11, 2025

Adds settings for explicitly limiting concurrent tokio blocking tasks intended for IO (for now enabled for ethcall)

Note: this isnt yet enforced for all spawned tasks and should be applied selectively, gonna use this to investigate #20059

closes #20090

see also #20059

Adds configurable limit for concurrent blocking IO requests (eth_call,
eth_estimateGas, etc.) to prevent tokio blocking thread pool exhaustion.

Configuration:
- New config: max_blocking_io_requests (default: 256)
- CLI arg: --rpc.max-blocking-io-requests
- Semaphore limits concurrent blocking IO operations

Trait additions to SpawnBlocking:
- blocking_io_task_guard(): Returns blocking IO semaphore
- acquire_owned_blocking_io(): Acquires single permit
- acquire_many_owned_blocking_io(n): Acquires multiple permits
- acquire_weighted_blocking_io(weight): Weighted permit acquisition
  that divides total permits by weight to limit concurrent requests

The weighted variant ensures at least (weight - 1) permits remain
available when total_permits divides evenly by weight, preventing
complete semaphore exhaustion.

Applied to:
- eth_call: Uses single permit acquisition
- eth_getProof: Uses weighted acquisition (weight=5)
@mattsse mattsse requested a review from Rjected as a code owner December 11, 2025 07:02
@mattsse mattsse added the A-rpc Related to the RPC implementation label Dec 11, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Dec 11, 2025
@mattsse mattsse requested a review from gakonst as a code owner December 11, 2025 07:55
@mattsse mattsse force-pushed the matt/add-max-call-requests branch from e0f59a1 to 2b0567a Compare December 11, 2025 07:59
@mattsse mattsse requested a review from shekhirin as a code owner December 11, 2025 07:59
@mattsse mattsse force-pushed the matt/add-max-call-requests branch from 2b0567a to 0732132 Compare December 11, 2025 08:00
Ok(async move {
let _permit = self
.acquire_owned()
.acquire_weighted_blocking_io(5)
Copy link
Member

Choose a reason for hiding this comment

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

this feels like a magic number, can you elaborate why it's 5?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this basically enforces most 5 concurrent requests for this endpoint, while still leaving permits available

Copy link
Member

@shekhirin shekhirin Dec 11, 2025

Choose a reason for hiding this comment

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

can we make this configurable? I expect some users have more than 5 concurrent eth_getProof and it's expected behaviour that they're ready for in terms of RAM

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can restore the previous behaviour by allocating the other semaphore

Copy link
Member

@klkvr klkvr left a comment

Choose a reason for hiding this comment

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

makes sense

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Dec 11, 2025
@mattsse mattsse added this pull request to the merge queue Dec 11, 2025
Merged via the queue into main with commit 2e567d6 Dec 11, 2025
45 checks passed
@mattsse mattsse deleted the matt/add-max-call-requests branch December 11, 2025 11:45
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Dec 11, 2025
Vui-Chee added a commit to okx/reth that referenced this pull request Dec 12, 2025
…number

* upstream: (203 commits)
  feat(node-core): make rpc server args customizable (paradigmxyz#20312)
  feat: add `account_history_in_rocksdb` field to `StorageSettings` (paradigmxyz#20282)
  feat(engine): Add BAL stub methods to ExecutionPayload and BlockOrPayload (paradigmxyz#20311)
  docs: fix misleading links (paradigmxyz#20300)
  ci: add more sccache (paradigmxyz#20316)
  feat: bump alloy-evm (paradigmxyz#20314)
  feat: allow larger ws frames on client side (paradigmxyz#20307)
  docs: add architecture diagrams to ExEx documentation (paradigmxyz#20193)
  feat: add semaphore for blocking IO requests (paradigmxyz#20289)
  ci: scale down depot runners (paradigmxyz#20295)
  perf: fetch header directly (paradigmxyz#20294)
  docs(exex): fix DebugApi comment (paradigmxyz#20296)
  feat: add support for testing_ rpc namespace and testing_buildBlockV1 (paradigmxyz#20094)
  chore: update engine_getBlobs metric (paradigmxyz#20290)
  chore(optimism): move predeploy constant to op-alloy (paradigmxyz#20181)
  docs: fix stages order and add missing EraStage (paradigmxyz#20283)
  docs: improve map_add_ons method documentation (paradigmxyz#20248)
  feat: add `transaction_hash_numbers_in_rocksdb` field to `StorageSettings` (paradigmxyz#20209)
  docs: clarify network mode, tx gossip and NAT (paradigmxyz#20247)
  feat: add support for debug_getBadBlock (paradigmxyz#20177)
  ...
theochap pushed a commit to ethereum-optimism/optimism that referenced this pull request Jan 22, 2026
theochap pushed a commit to ethereum-optimism/optimism that referenced this pull request Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rpc Related to the RPC implementation

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Respect request drops properly in spawned execution tasks

3 participants