Skip to content

Bound async PPL capacity and fail saturated queries with 429 - #22

Open
penghuo wants to merge 10 commits into
mainfrom
feat/5801-async-capacity
Open

penghuo wants to merge 10 commits into
mainfrom
feat/5801-async-capacity

Conversation

@penghuo

@penghuo penghuo commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Description

This PR stops async PPL queries from overloading a node, and stops queries from hanging when the SQL worker pools are full.

Busy worker pools. When the SQL worker pools were full, a new query was dropped without an error. A normal query never got a response, and an async query showed RUNNING forever. Now the query fails right away with 429 "thread pool is saturated; retry later". An async query whose id was already returned ends FAILED with the same error.

Too many async queries. One user could start thousands of async queries and slow down everyone else. Now each node runs only as many async queries at a time as its sql-worker thread pool has threads. Extra queries wait in a queue with the status PENDING and start in the order they were submitted, like a thread pool with a bounded work queue. When the queue is full, new submits get 429. A query that waits too long ends FAILED.

Setting Default What it limits
plugins.ppl.async.max_queued_queries 100 Queries waiting as PENDING. Extra submits get 429.
plugins.ppl.async.max_queued_time 5m How long a query may wait as PENDING before it ends FAILED.

A queued query can start on a different thread from the one that submitted it, so it runs with the submitting user's permissions and context.

Normal queries share the SQL worker pools and are not counted. An async query can still be refused by a full pool, and then it fails as described above. Admitting every query through one scheduler is tracked in opensearch-project#5912.

All new settings can be changed at runtime. They are documented in docs/user/ppl/admin/settings.md and docs/user/ppl/interfaces/endpoint.md. docs/dev/ppl-async-query-lifecycle.md explains the states of an async query and how it moves between them.

Related Issues

Part of opensearch-project#5801. Parent: opensearch-project#5765.

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…rch-project#5801)

When the SQL worker pools were full, ThreadPool.schedule dropped the
rejection, so a sync query never got a response and an async query stayed
RUNNING forever. Submit to the executor directly and report the rejection
as 429 "thread pool is saturated; retry later".

Run at most plugins.ppl.async.node_concurrent_running_queries async
queries per node. Extra queries wait as PENDING in a queue bounded by
plugins.ppl.async.max_queued_queries and fail after
plugins.ppl.async.max_queued_time. Limit the finished queries kept for
polling with plugins.ppl.async.max_retained_jobs. A queued query starts
with its submitter's thread context.

Signed-off-by: Peng Huo <penghuo@gmail.com>
@penghuo
penghuo requested a review from dai-chen as a code owner October 27, 2026 23:32
…oject#5801)

Only a queued job starts on another thread, and the scheduler is what
starts it. Capture the submitting thread's context when the job is
queued and restore it when the job starts, as the other executors in
the opensearch module do for the query task. This replaces
ContextPreservingQueryRunner in the plugin module and works for any
QueryRunner.

Signed-off-by: Peng Huo <penghuo@gmail.com>
…oject#5801)

plugins.ppl.async.max_retained_jobs bounds finished jobs kept for
polling, as the retained result budget does. Both are tracked in opensearch-project#5804,
so this change keeps only the running and queue limits.

Signed-off-by: Peng Huo <penghuo@gmail.com>
…-project#5801)

Report a job whose submit wait expires as PENDING while it is queued and
RUNNING otherwise, without re-reading its outcome; the inline race
handling belongs with the retained result budget (opensearch-project#5804). Drop the
executor-shutdown flag that only the removed retry read, make
failQueued void, and keep the scheduler's counters package-private.

Signed-off-by: Peng Huo <penghuo@gmail.com>
…#5801)

A running limit only makes sense at or below the worker threads, and
users cannot pick it well. Run as many async queries as sql-worker has
threads and drop plugins.ppl.async.node_concurrent_running_queries;
further queries wait as PENDING in the scheduler's queue instead of the
worker pool's.

Signed-off-by: Peng Huo <penghuo@gmail.com>
…pensearch-project#5801)

Wrap the task with ThreadContext.preserveContext before execute, as
ThreadPool.schedule does, so the submitted task carries the caller's
context regardless of the executor implementation.

Signed-off-by: Peng Huo <penghuo@gmail.com>
…roject#5801)

The plugin always wires the scheduler, so the service no longer starts
jobs without one; tests pass a scheduler instead. Remove the
QueryResult.Running(id) constructor that only tests used, and arm the
wait deadline before queueing so a failure to schedule it cannot leave
the job queued.

Signed-off-by: Peng Huo <penghuo@gmail.com>
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.

1 participant