Skip to content

Add LAMB_WORKERS configuration support for Docker next deployment#362

Open
xezpeleta wants to merge 2 commits into
Lamb-Project:devfrom
xezpeleta:feature/docker-workers-config
Open

Add LAMB_WORKERS configuration support for Docker next deployment#362
xezpeleta wants to merge 2 commits into
Lamb-Project:devfrom
xezpeleta:feature/docker-workers-config

Conversation

@xezpeleta
Copy link
Copy Markdown
Collaborator

Closes #361

Overview

This PR adds support for configuring Uvicorn worker processes via the LAMB_WORKERS environment variable in the Docker next deployment.

Changes Made

1. backend/docker-entrypoint.py

  • Added logic to detect LAMB_WORKERS environment variable
  • Automatically injects --workers N flag into uvicorn command
  • Validates that workers is a positive integer
  • Only applies to uvicorn commands (not other commands)
  • Prevents duplicate --workers flags

2. docker-compose.next.yaml

  • Added LAMB_WORKERS environment variable pass-through to lamb service
  • Uses empty string as default to maintain backward compatibility

3. .env.next.example

  • Added LAMB_WORKERS documentation in OPTIONAL VARIABLES section
  • Included usage recommendations (2-4 workers for production)
  • Clearly marked as commented/optional

Usage

Option 1 - Via .env file:

# Add to your .env file
LAMB_WORKERS=4
docker compose -f docker-compose.next.yaml up

Option 2 - Command line:

LAMB_WORKERS=4 docker compose -f docker-compose.next.yaml up

Option 3 - Override in compose file:

services:
  lamb:
    environment:
      LAMB_WORKERS: 4

Behavior

  • Not set/empty → Single worker (development mode, uvicorn default)
  • Positive integer (e.g., 4) → Multiple workers (production mode)
  • 0 or invalid → Ignored, defaults to single worker
  • Smart detection → Won't duplicate if --workers already in command

Testing

All test cases passed:

  • ✓ With LAMB_WORKERS=4
  • ✓ With LAMB_WORKERS not set
  • ✓ With LAMB_WORKERS=0 (ignored)
  • ✓ With --workers already present (not duplicated)
  • ✓ Non-uvicorn command (not affected)

Recommendations

  • Development: Leave unset (single worker)
  • Production: Set to 2-4 workers based on CPU cores and expected load

@xezpeleta xezpeleta force-pushed the feature/docker-workers-config branch from c0c3cdf to bdffb5c Compare May 7, 2026 13:18
…b-Project#361

- Enhanced docker-entrypoint.py to automatically inject --workers flag when LAMB_WORKERS env var is set
- Added LAMB_WORKERS environment variable pass-through in docker-compose.next.yaml
- Documented workers configuration in .env.next.example with usage recommendations
- Supports multiple workers for production deployments (recommended 2-4)
- Smart detection prevents duplicate --workers flags and validates positive integers
- Defaults to single worker when not set (suitable for development)
Copy link
Copy Markdown
Collaborator

@juananpe juananpe left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@juananpe
Copy link
Copy Markdown
Collaborator

juananpe commented May 7, 2026

Looks good to me!

Please, next time use dev for the PR

@xezpeleta xezpeleta changed the base branch from main to dev May 8, 2026 06:29
@xezpeleta
Copy link
Copy Markdown
Collaborator Author

You're right, I've changed to dev.

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.

Feature request: integrate workers in docker "next" deployment

2 participants