Page MenuHomePhabricator
Paste P54934

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

Authored by kevinbazira on Jan 18 2024, 3:39 PM.
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)

Event Timeline

kevinbazira changed the title of this paste from [locust] article descriptions isvc load test script with lw_history_stats() to [locust] article descriptions isvc load test script with lw_stats_history().Jan 19 2024, 6:02 AM
kevinbazira edited the content of this paste. (Show Details)