C.W.K.
Stream
Lesson 13 of 13 · published

병렬 job

~12 min · parallel, jobs, split

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Wall-clock 시간이 metric

Test suite 가 직렬로 30 분이면 6 개 병렬 job 으로 나누면 wall clock 이 ~5 분 (shard 당 고정 checkout/install overhead 추가). 유료 runner 가격 모델에선 분은 같이 쓰지만 — 개발자가 30 분 대신 5 분 기다려.

Test 분할 방법

  • 디렉토리 별 — 한 job 에서 pytest tests/api/, 다른 job 에서 pytest tests/db/.
  • Marker 별pytest -m 'unit' vs -m 'integration'.
  • 자동 shardpytest-xdist --dist=loadgroup -n 4 가 단일 runner 안에서 분할; matrix 와 결합해 runner 간 분할.
  • 시간 버킷 별 — 테스트별 시간 기록, 같은 시간 버킷으로 그룹. pytest-split 가 이걸 함.

조정 도전

  • 각 shard 는 자기 install. Cache 적극.
  • Coverage 리포트는 shard 간 병합. coverage combine 사용.
  • Flaky test 는 sharding 으로 증폭 — 실패한 shard 만 re-run.

Code

pytest-split 으로 sharded pytest·yaml
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        shard: [1, 2, 3, 4]
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v3
      - run: uv sync --all-extras --dev
      - name: Run shard ${{ matrix.shard }} of 4
        run: uv run pytest --splits 4 --group ${{ matrix.shard }} --cov=src --cov-report=xml:coverage.${{ matrix.shard }}.xml
      - uses: actions/upload-artifact@v4
        with:
          name: coverage-${{ matrix.shard }}
          path: coverage.${{ matrix.shard }}.xml

  coverage:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with: { pattern: coverage-*, merge-multiple: true }
      - run: pip install coverage && coverage combine && coverage report

External links

Exercise

Test suite 직렬 시간 재. 10 분 넘으면 pytest-split 으로 4-way 분할. Wall-clock 과 총 분 비교. Wall-clock 은 ~3.5× 떨어져야 함; 총 분은 shard 별 overhead 추가해서 대략 안정.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.