Page MenuHomePhabricator

[locust] article descriptions isvc load test script with lw_stats_history()

Authored By
kevinbazira
Jan 19 2024, 6:02 AM
Size
1 KB
Referenced Files
None
Subscribers
None

[locust] article descriptions isvc load test script with lw_stats_history()

import os
import csv
from datetime import datetime
from locust import FastHttpUser, task, between, events
@events.test_stop.add_listener
def lw_stats_history(**kwargs):
with open("article_descriptions_stats.csv", "r") as csvfile:
reader = csv.reader(csvfile)
header = next(reader) # Read the header row
aggregated_row = None
for row in reader:
if row[header.index("Name")] == "Aggregated": # Find the row with "Aggregated" in the "Name" column
aggregated_row = row
break
if aggregated_row:
current_time = datetime.now().strftime("%Y%m%d%H%M%S")
aggregated_row = [current_time] + aggregated_row[2:]
with open("lw_stats_history.csv", "a", newline="") as csvfile:
writer = csv.writer(csvfile)
if os.path.getsize("lw_stats_history.csv") == 0: # Check if file is empty
header = ["Timestamp"] + header[2:]
writer.writerow(header) # Write header if file is empty
writer.writerow(aggregated_row) # Write the data row
class ArticleDescriptionsUser(FastHttpUser):
wait_time = between(1, 2) # Adjust wait time as needed
host = "https://inference-staging.svc.codfw.wmnet:30443"
@task
def predict(self):
headers = {
"Host": "article-descriptions.experimental.wikimedia.org",
"Content-Type": "application/json"
}
data = {"lang": "en", "title": "Clandonald", "num_beams": 3}
self.client.post("/v1/models/article-descriptions:predict",
json=data,
headers=headers)

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14488889
Default Alt Text
[locust] article descriptions isvc load test script with lw_stats_history() (1 KB)

Event Timeline