mbishu's picture
Update product database and vector store management with new features and optimizations
fe2866c
Raw History Blame Contribute Delete
1.08 kB
from __future__ import annotations
from locust import HttpUser, between, task
class EcommerceUser(HttpUser):
wait_time = between(0.5, 1.5)
@task(3)
def search_products(self) -> None:
payload = {"query": "red running shoes", "top_k": "10"}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
with self.client.post("/search", data=payload, headers=headers, catch_response=True) as response:
if response.status_code != 200:
response.failure(f"Unexpected status: {response.status_code} - {response.text}")
elif len(response.json().get("results", [])) == 0:
response.failure("Empty search results")
@task(1)
def list_products(self) -> None:
with self.client.get("/products?limit=20&offset=0", catch_response=True) as response:
if response.status_code != 200:
response.failure(f"Unexpected status: {response.status_code}")
# Usage:
# locust -f scripts/performance/locustfile.py --host=http://localhost:8000 --users 50 --spawn-rate 5