-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Question
The 'all-extras' tests take around 2mins and have ~2000 tests inside. I think We should pursue ~12-20 workers to speed this up since the compute required for each is so low.
Looking at your situation with ~2000 pytest jobs that are each lightweight, you're right that -n auto (which gives you 4 workers on GitHub Actions) is likely suboptimal. Here's how to think about the optimal number:
Key Factors for Optimization
- GitHub Actions typically provides 2-core machines for standard runners (4 logical cores with hyperthreading)
- Your tests are I/O or setup bound (minimal compute) - this means you can oversubscribe CPU cores
- Overhead costs: Each worker has startup time and memory overhead
Optimal Range
For lightweight tests on GitHub Actions, the sweet spot is usually between 8-20 workers. Here's why:
- 8-12 workers: Conservative oversubscription (2-3x physical cores)
- 16-20 workers: Aggressive but often effective for I/O-bound tests
- Beyond 20: Diminishing returns due to coordination overhead
Testing Strategy
I'd recommend benchmarking with these values:
# In your GitHub Actions workflow
- name: Run tests
run: pytest -n 12 # Start hereOr make it configurable:
env:
PYTEST_WORKERS: 12 # Easy to adjust
steps:
- run: pytest -n ${{ env.PYTEST_WORKERS }}Quick Optimization Test
Try running locally with different values:
time pytest -n 4 # Current baseline
time pytest -n 8
time pytest -n 12
time pytest -n 16
time pytest -n 20Additional Optimizations
Looking at the pydantic-ai repo, you might also consider:
- pytest-split: Distribute tests across multiple GitHub Actions jobs running in parallel
- Test ordering: Run fast tests first with
pytest-orderorpytest-randomly - Caching: Make sure you're caching pip dependencies and any test fixtures
For your specific case with minimal compute per test, I'd start with -n 12 and adjust based on results. You should see significant improvement over the current 4 workers, potentially cutting your time from 2 minutes to under 1 minute.
Additional Context
No response