locust_load_testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineselocust_load_testing
locust_load_testing
Locust simula múltiples usuarios concurrentes enviando solicitudes de verificación KYC. Las pruebas de carga validan que el sistema cumple el SLO de 8 segundos p95 bajo carga sostenida y descubren cuellos de botella antes de producción.
Locust 模拟多个并发用户发送 KYC 验证请求。负载测试用于验证系统在持续负载下 p95 延迟满足8秒SLO的要求,可在上线前提前发现系统瓶颈。
When to use
适用场景
Ejecutar en staging antes de cada release que afecte al pipeline KYC o a la infraestructura. También ejecutar pruebas de capacidad para determinar el número óptimo de workers GPU.
在每次会影响 KYC pipeline 或基础设施的版本发布前,于 staging 环境执行。也可执行容量测试来确定 GPU worker 的最优数量。
Instructions
使用说明
- Instalar:
pip install locust - Crear :
load_tests/locustfile.pypythonfrom locust import HttpUser, task, between import base64, os SAMPLE_SELFIE = base64.b64encode(open("tests/fixtures/sample_selfie.jpg", "rb").read()).decode() SAMPLE_DOC = base64.b64encode(open("tests/fixtures/sample_passport.jpg", "rb").read()).decode() class KYCUser(HttpUser): wait_time = between(1, 3) @task def verify_identity(self): response = self.client.post("/v1/verify", json={ "selfie_b64": SAMPLE_SELFIE, "document_b64": SAMPLE_DOC, "document_type": "passport", }, headers={"Authorization": f"Bearer {os.environ['TEST_JWT']}"}) assert response.elapsed.total_seconds() < 8, f"SLO violated: {response.elapsed.total_seconds()}s" - Ejecutar:
locust -f load_tests/locustfile.py --host=https://staging.kyc.company.com --users=50 --spawn-rate=5 --run-time=5m --headless - Targets de SLO a validar: p50 < 4s, p95 < 8s, p99 < 15s, error_rate < 0.1%.
- Guardar el HTML report: y adjuntarlo al release.
--html=load-test-report.html - Si p95 > 8s: escalar workers GPU, optimizar batching o revisar los agentes con mayor latencia (ver Jaeger traces).
- 安装:
pip install locust - 创建 :
load_tests/locustfile.pypythonfrom locust import HttpUser, task, between import base64, os SAMPLE_SELFIE = base64.b64encode(open("tests/fixtures/sample_selfie.jpg", "rb").read()).decode() SAMPLE_DOC = base64.b64encode(open("tests/fixtures/sample_passport.jpg", "rb").read()).decode() class KYCUser(HttpUser): wait_time = between(1, 3) @task def verify_identity(self): response = self.client.post("/v1/verify", json={ "selfie_b64": SAMPLE_SELFIE, "document_b64": SAMPLE_DOC, "document_type": "passport", }, headers={"Authorization": f"Bearer {os.environ['TEST_JWT']}"}) assert response.elapsed.total_seconds() < 8, f"SLO violated: {response.elapsed.total_seconds()}s" - 执行:
locust -f load_tests/locustfile.py --host=https://staging.kyc.company.com --users=50 --spawn-rate=5 --run-time=5m --headless - 待验证的SLO指标:p50 < 4s,p95 < 8s,p99 < 15s,错误率 < 0.1%。
- 保存HTML报告:并将报告附在版本发布记录中。
--html=load-test-report.html - 如果p95 > 8s:扩容GPU worker、优化批处理策略,或者检查延迟最高的Agent(查看Jaeger traces)。
Notes
注意事项
- Las pruebas de carga deben ejecutarse con imágenes representativas de producción (resolución, formato, calidad).
- Simular también el escenario de liveness activo (challenge-response) que tiene mayor latencia que el pasivo.
- Un test de 50 usuarios concurrentes durante 5 minutos es un buen punto de partida — ajustar según el volumen esperado en producción.
- 负载测试必须使用贴近生产环境的代表性图片(分辨率、格式、质量)。
- 同时需要模拟活跃的活体检测场景(挑战-响应模式),该场景比被动场景延迟更高。
- 50个并发用户持续5分钟的测试是不错的基线配置,可根据生产环境预期的流量规模调整。