Load testing helps you understand your system’s performance characteristics under various loads. This guide covers three popular tools for load testing ML APIs.
Important: Always test in a staging environment first. Never run load tests against production without proper planning.
import numpy as npfrom locust import HttpUser, between, taskmovie_reviews = [ "A rollercoaster of emotions with stunning visuals and remarkable performances. A must-see!", "Despite its high production values, the plot is predictable and lacks originality.", "An epic space opera that pulls you in with its intricate plot and complex characters.", "Too reliant on CGI, and the storyline feels disjointed and hard to follow.", "An extraordinary cinematic experience that beautifully captures the human spirit.", "The pacing is too slow, and it tends to feel more like a documentary than a feature film.", "A superb adaptation with a gripping plot and fascinating characters. Truly unforgettable.", "Though the scenery is beautiful, the characters feel flat and the storyline lacks depth.", "A touching story of love and loss, paired with phenomenal acting. It will leave you teary-eyed.", "The script is clichéd, and the chemistry between the lead actors feels forced.", "A thrilling and suspenseful journey that keeps you on the edge of your seat till the end.", "The plot twists feel contrived, and the horror elements seem more comical than scary.", "A poignant exploration of life and love, combined with a mesmerizing soundtrack.", "The narrative is overly sentimental and fails to deliver a strong message.", "An underwater adventure that's both visually stunning and emotionally resonant.", "The visual effects overshadow the story, which is lacking in depth and originality.", "An action-packed thrill ride with memorable characters and an engaging plot.", "The action scenes are overdone and the storyline is paper thin.", "A captivating sci-fi thriller that challenges your perception of reality.", "The plot is confusing and the ending leaves too many questions unanswered.",]class PredictUser(HttpUser): wait_time = between(1, 5) @task def predict(self): num_of_review = np.random.randint(1, 100) reviews = np.random.choice(movie_reviews, size=num_of_review, replace=True) self.client.post("/predict", json={"text": reviews.tolist()})
import http from 'k6/http';import { sleep } from 'k6';const movie_reviews = [ "A rollercoaster of emotions with stunning visuals and remarkable performances. A must-see!", "Despite its high production values, the plot is predictable and lacks originality.", "An epic space opera that pulls you in with its intricate plot and complex characters.", "Too reliant on CGI, and the storyline feels disjointed and hard to follow.", "An extraordinary cinematic experience that beautifully captures the human spirit.", "The pacing is too slow, and it tends to feel more like a documentary than a feature film.", "A superb adaptation with a gripping plot and fascinating characters. Truly unforgettable.", "Though the scenery is beautiful, the characters feel flat and the storyline lacks depth.", "A touching story of love and loss, paired with phenomenal acting. It will leave you teary-eyed.", "The script is clichéd, and the chemistry between the lead actors feels forced.", "A thrilling and suspenseful journey that keeps you on the edge of your seat till the end.", "The plot twists feel contrived, and the horror elements seem more comical than scary.", "A poignant exploration of life and love, combined with a mesmerizing soundtrack.", "The narrative is overly sentimental and fails to deliver a strong message.", "An underwater adventure that's both visually stunning and emotionally resonant.", "The visual effects overshadow the story, which is lacking in depth and originality.", "An action-packed thrill ride with memorable characters and an engaging plot.", "The action scenes are overdone and the storyline is paper thin.", "A captivating sci-fi thriller that challenges your perception of reality.", "The plot is confusing and the ending leaves too many questions unanswered.",];export let options = { vus: 10, duration: '10m',};export default function () { sleep(Math.random() * 4 + 1); const num_of_review = Math.floor(Math.random() * 100) + 1; const reviews = []; for (let i = 0; i < num_of_review; i++) { const random_index = Math.floor(Math.random() * movie_reviews.length); reviews.push(movie_reviews[random_index]); } const payload = JSON.stringify({ text: reviews }); const params = { headers: { 'Content-Type': 'application/json', }, }; http.post('http://0.0.0.0:8080/predict', payload, params);}
---apiVersion: v1kind: ConfigMapmetadata: name: vegeta-cfgdata: cfg: | POST http://app-fastapi.default.svc.cluster.local:8080/predict Content-Type: application/json @/var/vegeta/payload payload: | { "text": [ "A rollercoaster of emotions with stunning visuals and remarkable performances. A must-see!", "Despite its high production values, the plot is predictable and lacks originality.", "An epic space opera that pulls you in with its intricate plot and complex characters.", "Too reliant on CGI, and the storyline feels disjointed and hard to follow.", "An extraordinary cinematic experience that beautifully captures the human spirit.", "The pacing is too slow, and it tends to feel more like a documentary than a feature film.", "A superb adaptation with a gripping plot and fascinating characters. Truly unforgettable.", "Though the scenery is beautiful, the characters feel flat and the storyline lacks depth.", "A touching story of love and loss, paired with phenomenal acting. It will leave you teary-eyed.", "The script is clichéd, and the chemistry between the lead actors feels forced." ] }---apiVersion: batch/v1kind: Jobmetadata: generateName: load-test-spec: backoffLimit: 6 parallelism: 1 template: metadata: annotations: sidecar.istio.io/inject: "false" spec: restartPolicy: OnFailure containers: - name: vegeta image: peterevans/vegeta:latest imagePullPolicy: Always command: - sh - -c args: - vegeta -cpus=2 attack -duration=1m -rate=100/1s -targets=/var/vegeta/cfg | vegeta report -type=text volumeMounts: - name: vegeta-cfg mountPath: /var/vegeta volumes: - name: vegeta-cfg configMap: name: vegeta-cfg defaultMode: 420