LiteLLM Proxy - locust 1K RPS 부하 테스트

LiteLLM Proxy - locust 1K RPS 부하 테스트

LiteLLM Proxy로 locust에서 1K+ RPS를 달성하는 방법에 대한 튜토리얼이에요.

출처: 문서

본문

테스트 전 체크리스트 (Pre-Testing Checklist)

  • 최신 -stable 버전의 litellm을 사용하고 있는지 확인하세요.
  • 프로덕션 모범 사례모두 따르고 있는지 확인하세요.
  • Locust - Locust 인스턴스가 초당 1K+ 요청을 생성할 수 있는지 확인하세요.
    • 👉 우리가 유지 관리하는 locust 인스턴스 를 사용할 수 있어요.
    • locust를 자체 호스팅한다면
      • 여기에 우리가 locust 머신에 사용한 사양이 있어요
      • 여기에 우리가 테스트에 사용한 locustfile.py가 있어요
  • 5. LiteLLM 프록시 실행을 위한 머신 사양 사용
  • 6. 엔터프라이즈 LiteLLM — 부하 테스트 메트릭을 얻으려면 proxy_config.yaml에서 콜백으로 prometheus를 사용하세요. litellm_settings.callbacks를 설정해 성공/실패/모든 유형의 오류를 모니터링해 주세요.
litellm_settings:
    callbacks: ["prometheus"] # Enterprise LiteLLM Only - use prometheus to get metrics on your load test

테스트에 이 config 사용:

참고: 현재 처리량이 10배 높은 aiohttp로 마이그레이션하고 있어요. 부하 테스트에는 openai/ 프로바이더를 사용하는 것을 권장해요.

가짜 OpenAI 엔드포인트 설정

호스팅된 가짜 엔드포인트를 사용하거나 github.com/BerriAI/example_openai_endpoint로 자체 호스팅할 수 있어요.

model_list:
  - model_name: "fake-openai-endpoint"
    litellm_params:
      model: openai/any
      api_base: https://exampleopenaiendpoint-production.up.railway.app/  # or your self-hosted endpoint
      api_key: "test"

부하 테스트 - 가짜 OpenAI 엔드포인트 (Load Test - Fake OpenAI Endpoint)

예상 성능 (Expected Performance)

메트릭
초당 요청 수 1174+
중앙값 응답 시간 96ms
평균 응답 시간 142.18ms

테스트 실행 (Run Test)

  1. fake-openai-endpoint를 proxy config.yaml에 추가하고 litellm 프록시를 시작하세요. litellm은 부하 테스트할 수 있는 호스팅 fake-openai-endpoint를 제공해요.
model_list:
  - model_name: fake-openai-endpoint
    litellm_params:
      model: openai/fake
      api_key: fake-key
      api_base: https://exampleopenaiendpoint-production.up.railway.app/

litellm_settings:
  callbacks: ["prometheus"] # Enterprise LiteLLM Only - use prometheus to get metrics on your load test
  1. uv add locust

  2. 로컬 머신에 locustfile.py 파일 생성. 여기에 있는 litellm 부하 테스트의 내용을 복사하세요.

  3. locust 시작. 2단계의 locustfile.py와 같은 디렉터리에서 locust 실행.

locust -f locustfile.py --processes 4
  1. locust에서 부하 테스트 실행

http://0.0.0.0:8089의 locust UI로 이동하세요.

Users=1000, Ramp Up Users=1000, Host=LiteLLM Proxy의 Base URL 설정

  1. 예상 결과

부하 테스트 - 속도 제한이 있는 엔드포인트 (Load test - Endpoints with Rate Limits)

각각 10K RPM 쿼터가 있는 2개의 LLM 배포에서 부하 테스트를 실행해 주세요. ~20K RPM이 예상돼요.

예상 성능 (Expected Performance)

  • 1분 안에 20,000+ 성공 응답이 예상돼요.
  • 나머지 요청은 LLM API 프로바이더의 10K RPM 쿼터 한도를 초과해 실패해요.
메트릭
1분 내 성공 응답 20,000+
초당 요청 수 ~1170+
중앙값 응답 시간 70ms
평균 응답 시간 640.18ms

테스트 실행 (Run Test)

  1. config.yaml에 2개의 gemini-vision 배포를 추가하세요. 각 배포는 10K RPM을 처리할 수 있어요. (아래 /v1/projects/bad-adroit-crow 경로에 1000 RPM 속도 제한이 있는 가짜 엔드포인트를 설정했어요.)

infomodel="gemini-vision"인 모든 요청은 2개 배포에 균등하게 로드밸런싱돼요.

model_list:
  - model_name: gemini-vision
    litellm_params:
      model: vertex_ai/gemini-3.1-pro-preview
      api_base: https://exampleopenaiendpoint-production.up.railway.app/v1/projects/bad-adroit-crow-413218/locations/us-central1/publishers/google/models/gemini-3.1-pro-preview
      vertex_project: "adroit-crow-413218"
      vertex_location: "us-central1"
      vertex_credentials: /etc/secrets/adroit_crow.json
  - model_name: gemini-vision
    litellm_params:
      model: vertex_ai/gemini-3.1-pro-preview
      api_base: https://exampleopenaiendpoint-production-c715.up.railway.app/v1/projects/bad-adroit-crow-413218/locations/us-central1/publishers/google/models/gemini-3.1-pro-preview
      vertex_project: "adroit-crow-413218"
      vertex_location: "us-central1"
      vertex_credentials: /etc/secrets/adroit_crow.json

litellm_settings:
  callbacks: ["prometheus"] # Enterprise LiteLLM Only - use prometheus to get metrics on your load test
  1. uv add locust

  2. 로컬 머신에 locustfile.py 파일 생성. 여기에 있는 litellm 부하 테스트의 내용을 복사하세요.

  3. locust 시작. 2단계의 locustfile.py와 같은 디렉터리에서 locust 실행.

locust -f locustfile.py --processes 4 -t 60
  1. locust에서 부하 테스트 실행

http://0.0.0.0:8089로 이동해 다음 설정을 사용하세요.

  1. 예상 결과
    • 1분 내 성공 응답 = 19,800 = (69415 - 49615)
    • 초당 요청 수 = 1170
    • 중앙값 응답 시간 = 70ms
    • 평균 응답 시간 = 640ms

부하 테스트 디버깅용 Prometheus 메트릭 (Prometheus Metrics for debugging load tests)

부하 테스트/실패를 디버깅하려면 다음 prometheus 메트릭을 사용하세요.

메트릭 이름 설명
litellm_deployment_failure_responses 특정 LLM 배포의 실패한 LLM API 호출 총수. 라벨: "requested_model", "litellm_model_name", "model_id", "api_base", "api_provider", "hashed_api_key", "api_key_alias", "team", "team_alias", "exception_status", "exception_class".
litellm_deployment_cooled_down LiteLLM 로드밸런싱 로직이 배포를 쿨다운한 횟수. 라벨: "litellm_model_name", "model_id", "api_base", "api_provider", "exception_status".

Locust 실행 머신 사양 (Machine Specifications for Running Locust)

메트릭
locust --processes 4 4
부하 테스트 머신의 vCPUs 2.0 vCPUs
부하 테스트 머신의 Memory 450 MB
부하 테스트 머신의 Replicas 1

LiteLLM 프록시 실행 머신 사양 (Machine Specifications for Running LiteLLM Proxy)

👉 1K+ RPS를 얻으려면 LiteLLM Proxy Replicas 수=4

서비스 스펙 CPU 메모리 아키텍처 버전
서버 t2.large 2vCPUs 8GB x86

테스트에 사용한 Locust 파일 (Locust file used for testing)

import os
import uuid
from locust import HttpUser, task, between

class MyUser(HttpUser):
    wait_time = between(0.5, 1)  # Random wait time between requests

    @task(100)
    def litellm_completion(self):
        # no cache hits with this
        payload = {
            "model": "fake-openai-endpoint",
            "messages": [{"role": "user", "content": f"{uuid.uuid4()} This is a test there will be no cache hits and we'll fill up the context" * 150 }],
            "user": "my-new-end-user-1"
        }
        response = self.client.post("chat/completions", json=payload)
        if response.status_code != 200:
            # log the errors in error.txt
            with open("error.txt", "a") as error_log:
                error_log.write(response.text + "\n")
    

    def on_start(self):
        self.api_key = os.getenv('API_KEY', 'sk-<your-litellm-api-key>')
        self.client.headers.update({'Authorization': f'Bearer {self.api_key}'})

더 알아보기 (Learn more)