Skip to content

Commit d6c3315

Browse files
authored
feat(worker): expose OPEN_NOTEBOOK_WORKER_MAX_TASKS to control worker concurrency (#1141)
The worker processes all queued tasks up to a fixed concurrency of 5, which overloads single-GPU / local-LLM setups and triggers rate limits (#893). The surreal-commands worker already accepts --max-tasks; wire it to a new OPEN_NOTEBOOK_WORKER_MAX_TASKS env var (default 5, set 1 for sequential) at every launch point. - Makefile (worker-start, start-all): --max-tasks "$${VAR:-5}" (Make-escaped) - dev-init.sh: POSIX ${VAR:-5} default expansion - supervisord.conf: wrap in sh -c so the shell expands the var (command= does not run through a shell) - docker-compose.yml: commented environment example - .env.example + environment-reference.md: document it, incl. the launch-time sourcing behavior Also fixes a phantom doc entry: SURREAL_COMMANDS_MAX_TASKS was documented but is not read anywhere (the worker's --max-tasks Typer option has no envvar); replaced with the real OPEN_NOTEBOOK_WORKER_MAX_TASKS. Closes #893
1 parent 16c9c9d commit d6c3315

6 files changed

Lines changed: 21 additions & 6 deletions

File tree

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ SURREAL_DATABASE=open_notebook
5454
# CHUNK_SIZE=1500
5555
# CHUNK_OVERLAP=150
5656

57+
# Max background tasks the worker runs concurrently (default 5). Set to 1 for
58+
# sequential processing on single-GPU / local-LLM setups to avoid rate limits.
59+
# NOTE: consumed at worker launch, not by the app — for `make`/dev-init export
60+
# it in your shell; for Docker set it under `environment:` in docker-compose.yml.
61+
# OPEN_NOTEBOOK_WORKER_MAX_TASKS=1
62+
5763
# Maximum upload/request body size in MB (default: 100). Raise this if you
5864
# need to upload larger audio/video files. A fronting reverse proxy's own
5965
# limit (e.g. nginx client_max_body_size) still applies and should be raised

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ worker: worker-start
162162

163163
worker-start:
164164
@echo "Starting surreal-commands worker..."
165-
uv run --env-file .env surreal-commands-worker --import-modules commands
165+
uv run --env-file .env surreal-commands-worker --import-modules commands --max-tasks "$${OPEN_NOTEBOOK_WORKER_MAX_TASKS:-5}"
166166

167167
worker-stop:
168168
@echo "Stopping surreal-commands worker..."
@@ -182,7 +182,7 @@ start-all:
182182
@uv run run_api.py &
183183
@sleep 3
184184
@echo "⚙️ Starting background worker..."
185-
@uv run --env-file .env surreal-commands-worker --import-modules commands &
185+
@uv run --env-file .env surreal-commands-worker --import-modules commands --max-tasks "$${OPEN_NOTEBOOK_WORKER_MAX_TASKS:-5}" &
186186
@sleep 2
187187
@echo "🌐 Starting Next.js frontend..."
188188
@echo "✅ All services started!"

dev-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sleep 3
2929

3030
# Start background worker in background
3131
echo "Starting background worker..."
32-
uv run --env-file .env surreal-commands-worker --import-modules commands &
32+
uv run --env-file .env surreal-commands-worker --import-modules commands --max-tasks "${OPEN_NOTEBOOK_WORKER_MAX_TASKS:-5}" &
3333
sleep 2
3434

3535
# Start frontend (foreground)

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ services:
4848
# - OPEN_NOTEBOOK_ENABLE_DOCLING=true # Docling engine + OCR + image sources (large ML stack)
4949
# - OPEN_NOTEBOOK_ENABLE_CRAWL4AI=true # local Crawl4AI (bundles a Chromium browser)
5050
# - CRAWL4AI_API_URL=http://crawl4ai:11235 # use a remote Crawl4AI server instead (no local install)
51+
52+
# OPTIONAL: max concurrent background tasks the worker processes at once
53+
# (default 5). Set to 1 for sequential processing on single-GPU / local
54+
# LLM setups to avoid overloading the model with parallel requests.
55+
# - OPEN_NOTEBOOK_WORKER_MAX_TASKS=1
5156
volumes:
5257
- ./notebook_data:/app/data
5358
depends_on:

docs/5-CONFIGURATION/environment-reference.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ Comprehensive list of all environment variables available in Open Notebook.
4545

4646
---
4747

48-
## Database: Concurrency
48+
## Worker: Concurrency
4949

5050
| Variable | Required? | Default | Description |
5151
|----------|-----------|---------|-------------|
52-
| `SURREAL_COMMANDS_MAX_TASKS` | No | 5 | Maximum concurrent database tasks |
52+
| `OPEN_NOTEBOOK_WORKER_MAX_TASKS` | No | 5 | Maximum number of background tasks (source processing, embeddings, podcasts) the worker runs concurrently. Passed to the worker as `--max-tasks` at launch. Set to `1` for **sequential processing** on single-GPU or local-LLM setups, where parallel requests overload the model and trigger rate limits. |
53+
54+
> **Read at worker launch, from the process environment.** In Docker this comes from the container environment — set it under `environment:` in `docker-compose.yml` (or your orchestrator). For local `make worker-start` / `dev-init.sh`, export it in your shell (e.g. `export OPEN_NOTEBOOK_WORKER_MAX_TASKS=1`) — it is consumed by the shell before the app loads `.env`, so a value placed only in `.env` will not apply to these local launch paths.
5355
5456
---
5557

supervisord.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ autostart=true
2020
startsecs=3
2121

2222
[program:worker]
23-
command=uv run --no-sync surreal-commands-worker --import-modules commands
23+
; sh -c so the shell expands ${OPEN_NOTEBOOK_WORKER_MAX_TASKS:-5} (supervisord's
24+
; own command= does not run through a shell). Falls back to 5 when unset.
25+
command=sh -c "uv run --no-sync surreal-commands-worker --import-modules commands --max-tasks ${OPEN_NOTEBOOK_WORKER_MAX_TASKS:-5}"
2426
stdout_logfile=/dev/stdout
2527
stdout_logfile_maxbytes=0
2628
stderr_logfile=/dev/stderr

0 commit comments

Comments
 (0)