Skip to content

Commit da7915b

Browse files
rustyconoverclaude
andcommitted
worker: --http-threads CLI flag for waitress thread pool
waitress.serve()'s default thread pool is 4. Any caller issuing more concurrent HTTP requests than that (e.g. a DuckDB extension with SET threads=8 calling process() per scan worker plus setup/teardown overlap) sees half its parallelism queue on the WSGI pool. Symptom: waitress emits ``Task queue depth is N`` at INFO when the accept queue grows past 0. Add --http-threads to both `main()` (when --http) and `main_http()`, plumb it through `_run_http` to `waitress.serve(threads=N)`. Default None preserves waitress's built-in default (no behaviour change for existing callers); operators size up explicitly when the workload expects more concurrency than 4. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e804203 commit da7915b

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

‎vgi/worker.py‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,15 @@ def _run(
894894
"--idle-timeout",
895895
help="Self-shutdown after N seconds idle when serving --unix.",
896896
),
897+
http_threads: int | None = typer.Option( # noqa: B008
898+
None,
899+
"--http-threads",
900+
help=(
901+
"waitress worker thread count (only when --http). Default None "
902+
"uses waitress's default (4). Raise this when many concurrent "
903+
"process() ticks would otherwise queue on the WSGI threadpool."
904+
),
905+
),
897906
) -> None:
898907
env_debug = os.environ.get("VGI_WORKER_DEBUG", "").lower() in ("1", "true", "yes")
899908
effective_debug = debug or env_debug
@@ -930,6 +939,7 @@ def _run(
930939
oauth_resource_metadata=oauth_metadata,
931940
otel_config=otel_config,
932941
port_file=port_file,
942+
http_threads=http_threads,
933943
)
934944
elif unix is not None:
935945
# AF_UNIX launcher path. Bind to the requested socket,
@@ -1004,6 +1014,16 @@ def _run(
10041014
log_format: LogFormat = typer.Option( # noqa: B008
10051015
LogFormat.text, "--log-format", help="Stderr log format"
10061016
),
1017+
http_threads: int | None = typer.Option( # noqa: B008
1018+
None,
1019+
"--http-threads",
1020+
help=(
1021+
"waitress worker thread count. Default None uses waitress's "
1022+
"default (4). Raise this when many concurrent process() ticks "
1023+
"would otherwise queue on the WSGI threadpool — typical sign "
1024+
"is 'Task queue depth is N' messages from waitress."
1025+
),
1026+
),
10071027
) -> None:
10081028
env_debug = os.environ.get("VGI_WORKER_DEBUG", "").lower() in ("1", "true", "yes")
10091029
effective_debug = debug or env_debug
@@ -1035,6 +1055,7 @@ def _run(
10351055
authenticate=authenticate,
10361056
oauth_resource_metadata=oauth_metadata,
10371057
otel_config=otel_config,
1058+
http_threads=http_threads,
10381059
)
10391060

10401061
app()
@@ -1053,6 +1074,7 @@ def _run_http(
10531074
oauth_resource_metadata: Any = None,
10541075
otel_config: Any = None,
10551076
port_file: str | None = None,
1077+
http_threads: int | None = None,
10561078
) -> None:
10571079
"""Start the worker as an HTTP server (shared by ``main`` and ``main_http``)."""
10581080
import socket
@@ -1111,7 +1133,22 @@ def _run_http(
11111133
# syscall path that's been around since the 1970s, but waitress
11121134
# has supported the poll backend since its initial release and
11131135
# it's how every other production-grade WSGI server runs.
1114-
waitress.serve(wsgi_app, host=host, port=port, _quiet=True, asyncore_use_poll=True)
1136+
# ``threads=N`` controls waitress's worker pool. Default is 4, which
1137+
# under-serves any caller that issues more concurrent HTTP requests
1138+
# than that — for kafka_consume with ``SET threads=8`` plus setup/
1139+
# teardown overlap, half the parallelism queues on the WSGI pool.
1140+
# Symptom: waitress logs ``Task queue depth is N`` at INFO when the
1141+
# accept queue grows past 0. Pass ``--http-threads`` to size for
1142+
# the workload's expected concurrency.
1143+
serve_kwargs: dict[str, Any] = {
1144+
"host": host,
1145+
"port": port,
1146+
"_quiet": True,
1147+
"asyncore_use_poll": True,
1148+
}
1149+
if http_threads is not None:
1150+
serve_kwargs["threads"] = http_threads
1151+
waitress.serve(wsgi_app, **serve_kwargs)
11151152

11161153
@staticmethod
11171154
def _match_function_arguments(

0 commit comments

Comments
 (0)