-
Notifications
You must be signed in to change notification settings - Fork 110
Closed
Description
https://docs.astral.sh/uv/reference/cli/#uv-pip-install--compile-bytecode
Problem Description
Container startup performance is significantly degraded due to missing --compile-bytecode
flag in uv pip install
commands across all Dockerfiles. This causes Python modules to compile bytecode at runtime during container startup instead of pre-compiling during the Docker build phase.
Impact
- CI Test Failures: Containers repeatedly fail Kubernetes readiness/liveness probes with connection refused errors
- Slow Startup: Container startup hangs during
jupyter elyra --generate-config
due to slow Python module imports - Non-deterministic Performance: Startup times vary significantly depending on runtime compilation overhead
- User Experience: Poor container startup reliability in production environments
Root Cause Analysis
Python modules without pre-compiled bytecode (.pyc
files) trigger on-the-fly compilation during import, causing:
- Significant startup delays when importing many modules (common in Jupyter environments)
- Kubernetes probe timeouts (typically 5-10 seconds) being exceeded
- Container restart loops in orchestrated environments
Affected Scope
35 Dockerfiles across the entire notebook ecosystem are affected:
Image Types:
- codeserver: ubi9-python-3.11, ubi9-python-3.12 (CPU variants)
- jupyter: datascience, minimal, pytorch, tensorflow, trustyai (CPU, CUDA, ROCm variants for both Python 3.11 and 3.12)
- runtimes: datascience, minimal, pytorch, tensorflow, rocm-pytorch, rocm-tensorflow (CPU, CUDA, ROCm variants)
- rstudio: c9s-python-3.11, rhel9-python-3.11 (CPU, CUDA variants)
Current Problematic Pattern:
uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --index-strategy=unsafe-best-match --requirements=./requirements.txt --build-constraints=./requirements.txt
Solution
Add --compile-bytecode
flag to all uv pip install
commands:
uv pip install --compile-bytecode --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --index-strategy=unsafe-best-match --requirements=./requirements.txt --build-constraints=./requirements.txt
Benefits:
- Pre-compiled Bytecode:
.pyc
files generated during Docker build, not at runtime - Faster Startup: Eliminates compilation overhead during container initialization
- Deterministic Performance: Consistent startup times across deployments
- Probe Reliability: Containers become ready within Kubernetes timeout windows
- Better UX: Reliable container startup in production environments
Implementation Approach
- Systematic Update: Add
--compile-bytecode
flag to all 35 affected Dockerfiles - Consistent Placement: Position flag consistently (after
--compile-bytecode
before other flags) - Verification Testing: Ensure CI tests pass with improved startup performance
- Performance Validation: Measure startup time improvements
Acceptance Criteria
Core Requirements:
- All 35 Dockerfiles updated with
--compile-bytecode
flag - Flag positioned consistently in command structure
- No regression in package installation functionality
- CI tests pass without probe timeout failures
Verification Steps:
- Container startup time measurements show improvement
- Kubernetes readiness/liveness probes succeed consistently
- Python module imports complete faster at runtime
- No build failures or dependency resolution issues
Testing Coverage:
- All affected image types (codeserver, jupyter, runtimes, rstudio)
- Both Python 3.11 and 3.12 variants
- CPU, CUDA, and ROCm accelerator configurations
- Cross-platform compatibility (amd64, arm64)
Context Links
- PR: RHOAIENG-21690: chore(Dockerfiles): augument
micropipenv
withuv
for faster package installs #968 - "RHOAIENG-21690: chore(Dockerfiles): augmentmicropipenv
withuv
for faster package installs" - Discussion: RHOAIENG-21690: chore(Dockerfiles): augument
micropipenv
withuv
for faster package installs #968 (comment) - CI Failure Example: https://github.com/jiridanek/notebooks/actions/runs/16784807126/job/47532526249
Related Documentation
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
✅Done