Skip to content

feat: allow an external semaphore for executor task concurrency#1892

Merged
milenkovicm merged 5 commits into
apache:mainfrom
spiceai:upstream/external-semaphore-busy-state
Jul 20, 2026
Merged

feat: allow an external semaphore for executor task concurrency#1892
milenkovicm merged 5 commits into
apache:mainfrom
spiceai:upstream/external-semaphore-busy-state

Conversation

@Jeadie

@Jeadie Jeadie commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

None Closes #. Suggested by @milenkovicm that we should upstream our changes (see comment).

Rationale for this change

Useful in spiceai/datafusion-ballista for production features.

What changes are included in this PR?

Adds an optional available_task_slots: Option<Arc<Semaphore>> parameter to the executor poll_loop. When provided, the caller supplies the semaphore that bounds concurrent task execution; when None, the loop creates one internally sized to the executor's task slots (unchanged behavior).

Enables:

  • sharing the concurrency semaphore across poll loops connected to different schedulers,
  • observing executor busy state externally via available_permits().

Ported from spiceai#14.

Jeadie added 2 commits June 23, 2026 14:03
Adds an optional available_task_slots: Option<Arc<Semaphore>> parameter to
the executor poll_loop. When provided, the caller supplies the semaphore
that bounds concurrent task execution; this enables sharing it across poll
loops connected to different schedulers and observing executor busy state
via available_permits(). When None, the loop creates one internally sized
to the executor's task slots (unchanged behavior).

Ported from #14 for upstreaming. Note: layers
on the poll_loop signature; if landed after #12 (poll_now_notify) it needs
a trivial rebase to add both parameters.

@andygrove andygrove left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for upstreaming this. The opt-in shape is clean and the default behavior is preserved exactly, which makes it easy to reason about. My only notes are a couple of doc-comment clarifications for the shared-semaphore path. Separately, would it be worth a small test that passes in a semaphore and asserts the loop uses it rather than creating its own? I realize that's awkward to set up against poll_loop, so feel free to wave it off if it's more trouble than it's worth.

This review was prepared with the help of an LLM.

Comment thread ballista/executor/src/execution_loop.rs Outdated

@andygrove andygrove left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @Jeadie

@andygrove
andygrove requested a review from martin-g June 26, 2026 18:03
Comment thread ballista/executor/src/execution_loop.rs Outdated
Comment thread ballista/executor/src/execution_loop.rs Outdated
Comment thread ballista/executor/src/execution_loop.rs Outdated
Comment thread ballista/executor/src/execution_loop.rs
Jeadie added 2 commits July 3, 2026 09:45
- Handle AcquireError from semaphore acquire/acquire_owned by mapping to
  BallistaError instead of panicking, since the semaphore may now be
  externally owned and closed by the caller
- Assert that the provided semaphore has at least one permit on entry to
  fail fast rather than deadlock
- Rewrite poll_loop doc comment to be public-facing: remove references
  to internal variable names and implementation types, document shared-
  semaphore over-commit semantics and sizing tradeoffs in behavioral
  terms, and add a # Panics section for the zero-permit case
@milenkovicm

Copy link
Copy Markdown
Contributor

thanks @Jeadie, looks like one clippy issue left

@phillipleblanc

Copy link
Copy Markdown
Contributor

@milenkovicm this should be good now

@milenkovicm

Copy link
Copy Markdown
Contributor

thanks @Jeadie @phillipleblanc & @andygrove

@milenkovicm
milenkovicm merged commit 5408c76 into apache:main Jul 20, 2026
18 checks passed
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.

5 participants