跳至主要內容

LiteLLM Proxy - 在 locust 上進行 1K RPS 負載測試

關於如何在 locust 上透過 LiteLLM Proxy 達到 1K+ RPS 的教學

測試前檢查清單

使用此設定進行測試:

注意: 我們目前正在遷移到 aiohttp,其吞吐量高出 10 倍。我們建議在負載測試中使用 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 端點

預期效能

指標數值
每秒請求數1174+
回應時間中位數96ms
平均回應時間142.18ms

執行測試

  1. fake-openai-endpoint 加入您的 proxy config.yaml,並啟動您的 litellm proxy 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 基礎 URL

  1. 預期結果

負載測試 - 具有速率限制的端點

對 2 個 LLM 部署執行負載測試,每個都有 10K RPM 配額。預期會看到約 20K RPM

預期效能

  • 我們預期在 1 分鐘內看到 20,000+ 個成功回應
  • 剩餘請求失敗,因為該端點超過了其 10K RPM 配額限制 - 來自 LLM API 提供者
指標數值
1 分鐘內成功回應數20,000+
每秒請求數~1170+
回應時間中位數70ms
平均回應時間640.18ms

執行測試

  1. 在您的 config.yaml 上加入 2 個 gemini-vision 部署。每個部署可處理 10K RPM。(我們在下方 /v1/projects/bad-adroit-crow 路由上設定了一個速率限制為 1000 RPM 的假端點)
資訊

所有帶有 model="gemini-vision" 的請求都會在這 2 個部署之間平均進行負載平衡。

model_list:
- model_name: gemini-vision
litellm_params:
model: vertex_ai/gemini-1.0-pro-vision-001
api_base: https://exampleopenaiendpoint-production.up.railway.app/v1/projects/bad-adroit-crow-413218/locations/us-central1/publishers/google/models/gemini-1.0-pro-vision-001
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-1.0-pro-vision-001
api_base: https://exampleopenaiendpoint-production-c715.up.railway.app/v1/projects/bad-adroit-crow-413218/locations/us-central1/publishers/google/models/gemini-1.0-pro-vision-001
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 上的 locust UI,並使用以下設定

  1. 預期結果
    • 1 分鐘內成功回應 = 19,800 = (69415 - 49615)
    • 每秒請求數 = 1170
    • 回應時間中位數 = 70ms
    • 平均回應時間 = 640ms

用於除錯負載測試的 Prometheus 指標

使用以下 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_downLiteLLM 負載平衡邏輯將部署降溫的次數。標籤:"litellm_model_name", "model_id", "api_base", "api_provider", "exception_status"

執行 Locust 的機器規格

指標數值
locust --processes 44
負載測試機器上的 vCPUs2.0 vCPUs
負載測試機器上的 Memory450 MB
負載測試機器的 Replicas1

執行 LiteLLM Proxy 的機器規格

👉 為了取得 1K+ RPS,LiteLLM Proxy 的副本數量=4

服務規格CPU記憶體架構版本
伺服器t2.large.2vCPUs8GBx86

測試所使用的 Locust 檔案

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-1234')
self.client.headers.update({'Authorization': f'Bearer {self.api_key}'})