Skip to content

Commit 22ada22

Browse files
authored
Better nightly performance test (#2075)
1 parent d95e7b3 commit 22ada22

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
#!/bin/bash
22

3+
# Setup
34
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
45
perf_test_aws_s3_bucket=${PERF_TEST_AWS_S3_BUCKET:-notify-performance-test-results-staging}
56
perf_test_csv_directory_path=${PERF_TEST_CSV_DIRECTORY_PATH:-/tmp/notify_performance_test}
6-
77
mkdir -p $perf_test_csv_directory_path/$current_time
88

9+
# Run old performance test and copy results to S3
910
locust --headless --config tests-perf/locust/locust.conf --html $perf_test_csv_directory_path/$current_time/index.html --csv $perf_test_csv_directory_path/$current_time/perf_test
10-
1111
aws s3 cp $perf_test_csv_directory_path/ "s3://$perf_test_aws_s3_bucket" --recursive || exit 1
1212

13+
# Sleep 15 minutes to allow the system to stabilize
14+
sleep 900
15+
16+
# Run email send rate performance test
17+
# This configuration should send 10K emails / minute for 10 minutes for 100K emails total.
18+
# We run this test on Tuesday through Friday (just after midnight UTC) only.
19+
if [ "$(date +%u)" -ge 2 ] && [ "$(date +%u)" -le 5 ]; then
20+
locust --headless --host https://api.staging.notification.cdssandbox.xyz --locustfile tests-perf/locust/send_rate_email.py --users 5 --run-time 10m --spawn-rate 1
21+
fi
22+
23+
# Cleanup
1324
rm -rf $perf_test_csv_directory_path/$current_time

tests-perf/locust/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You should not have to modify the configuration to run the stress-tests locally.
3636

3737
There are two ways to run Locust, with the UI or headless.
3838

39-
### Add the following to your .env file (ask a coworker):
39+
### Add the following to your .env file (see 1Password):
4040

4141
```
4242
PERF_TEST_AUTH_HEADER =
@@ -67,6 +67,13 @@ locust -f .\locust-notifications.py --headless --users=5500 --spawn-rate=200 --r
6767

6868
You can also modify the *locust.config* file to enable the headless mode and define the necessary users, spawn rate and run time.
6969

70+
## Email send rate test
71+
72+
We also max out the email send rate by sending 2000 x 5 emails per minute for 10 minutes. This can be run manually with the command
73+
```
74+
locust --headless --host https://api.staging.notification.cdssandbox.xyz --locustfile tests-perf/locust/send_rate_email.py --users 5 --run-time 10m --spawn-rate 1
75+
```
76+
7077
### Performance Testing on AWS
7178

7279
We run Notify performance tests on a daily manner through AWS ECS tasks

tests-perf/locust/send_rate_email.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
""" send_rate_email.py
2+
isort:skip_file
3+
"""
4+
# flake8: noqa
5+
6+
BULK_EMAIL_SIZE = 2000
7+
8+
import os
9+
import sys
10+
from datetime import datetime
11+
from dataclasses import make_dataclass
12+
13+
sys.path.append(os.path.abspath(os.path.join("..", "tests_smoke")))
14+
15+
from dotenv import load_dotenv
16+
from locust import HttpUser, constant_pacing, task
17+
from tests_smoke.smoke.common import job_line, rows_to_csv # type: ignore
18+
19+
load_dotenv()
20+
NotifyApiUserTemplateGroup = make_dataclass('NotifyApiUserTemplateGroup', [
21+
'bulk_email_id',
22+
'email_id',
23+
'email_with_attachment_id',
24+
'email_with_link_id',
25+
'sms_id',
26+
])
27+
28+
29+
class NotifyApiUser(HttpUser):
30+
31+
wait_time = constant_pacing(60) # 60 seconds between each task
32+
host = os.getenv("PERF_TEST_DOMAIN", "https://api.staging.notification.cdssandbox.xyz")
33+
34+
def __init__(self, *args, **kwargs):
35+
super(NotifyApiUser, self).__init__(*args, **kwargs)
36+
37+
self.headers = {"Authorization": os.getenv("PERF_TEST_AUTH_HEADER")}
38+
self.email = os.getenv("PERF_TEST_EMAIL", "[email protected]")
39+
self.phone_number = os.getenv("PERF_TEST_PHONE_NUMBER", "16135550123")
40+
self.template_group = NotifyApiUserTemplateGroup(
41+
bulk_email_id=os.getenv("PERF_TEST_BULK_EMAIL_TEMPLATE_ID"),
42+
email_id=os.getenv("PERF_TEST_EMAIL_TEMPLATE_ID"),
43+
email_with_attachment_id=os.getenv("PERF_TEST_EMAIL_WITH_ATTACHMENT_TEMPLATE_ID"),
44+
email_with_link_id=os.getenv("PERF_TEST_EMAIL_WITH_LINK_TEMPLATE_ID"),
45+
sms_id=os.getenv("PERF_TEST_SMS_TEMPLATE_ID"),
46+
)
47+
48+
@task(1)
49+
def send_bulk_email_notifications(self):
50+
"""
51+
Send BULK_EMAIL_SIZE emails through the /bulk endpoint
52+
"""
53+
54+
json = {
55+
"name": f"Send rate test {datetime.utcnow().isoformat()}",
56+
"template_id": self.template_group.bulk_email_id,
57+
"csv": rows_to_csv([["email address", "application_file"], *job_line(self.email, BULK_EMAIL_SIZE)])
58+
}
59+
60+
self.client.post("/v2/notifications/bulk", json=json, headers=self.headers)

0 commit comments

Comments
 (0)