Skip to content

Commit

Permalink
add sql queries for send rates
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels committed Feb 18, 2025
1 parent b3f3e05 commit 7202a00
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests_nightly_performance/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ENV POETRY_VERSION="1.7.1"
ENV POETRY_VIRTUALENVS_CREATE="false"
ENV PATH="${APP_VENV}/bin:${POETRY_HOME}/bin:$PATH"

RUN apk add --no-cache bash build-base git libtool cmake autoconf automake gcc musl-dev postgresql-dev g++ make libffi-dev libmagic libcurl curl-dev rust cargo && rm -rf /var/cache/apk/*
RUN apk add --no-cache bash build-base git libtool cmake autoconf automake gcc musl-dev postgresql-dev g++ make libffi-dev libmagic libcurl curl-dev rust cargo postgresql-client && rm -rf /var/cache/apk/*

RUN set -ex && mkdir /app
WORKDIR /app
Expand Down
16 changes: 13 additions & 3 deletions tests_nightly_performance/execute_and_publish_performance_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cd tests_nightly_performance || exit 1

# Test 1 - Hammer the api
locust --config locust.conf \
--locustfile blast_api.py \
--locustfile src/blast_api.py \
--users 3000 \
--html "$perf_test_results_folder/index.html" --csv "$perf_test_results_folder/api_test"

Expand All @@ -26,7 +26,7 @@ sleep 900

if [ "$(date +%u)" -ge 2 ] && [ "$(date +%u)" -le 5 ]; then
locust --config locust.conf \
--locustfile email_send_rate.py \
--locustfile src/email_send_rate.py \
--users 5 \
--csv "$perf_test_results_folder/email_send_rate_test"
fi
Expand All @@ -40,11 +40,21 @@ sleep 1800

if [ "$(date +%u)" -ge 2 ] && [ "$(date +%u)" -le 5 ]; then
locust --config locust.conf \
--locustfile sms_send_rate.py \
--locustfile src/sms_send_rate.py \
--users 2 \
--csv "$perf_test_results_folder/sms_send_rate_test"
fi

# Sleep 20 minutes to allow the tests to finish
sleep 1200

# evaluate send rates
PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_URL" -U "$POSTGRES_USER" -d "$POSTGRES_DATABASE_NAME" \
-f sql_queries/email_send_rate_query.sql > "$perf_test_results_folder/email_send_rate.txt"

PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_URL" -U "$POSTGRES_USER" -d "$POSTGRES_DATABASE_NAME" \
-f sql_queries/sms_send_rate_query.sql > "$perf_test_results_folder/sms_send_rate.txt"

# Copy data to s3
aws s3 cp "$perf_test_csv_directory_path/" "s3://$perf_test_aws_s3_bucket" --recursive || exit 1

Expand Down
27 changes: 27 additions & 0 deletions tests_nightly_performance/sql_queries/email_send_rate_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This query is used to calculate the maximum sustained email send rate per minute.
* Here "sustained" means the average sent per minute over five minutes.
*/
with data as (
select id,
sent_at,
sent_at::date as day,
round_minutes(sent_at, 5) as sent_minute
from notifications
where sent_at is not null
and sent_at >= NOW() - INTERVAL '3 hours'
and sent_at >= CURRENT_DATE
and notification_type = 'email'
),
rollup as (
select day,
sent_minute,
count(*) / 5 as notifications_per_minute
from data
group by day,
sent_minute
)
select day,
max(notifications_per_minute) as sustained_emails_per_minute
from rollup
group by day
27 changes: 27 additions & 0 deletions tests_nightly_performance/sql_queries/sms_send_rate_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This query is used to calculate the maximum sustained SMS send rate per minute.
* Here "sustained" means the average sent per minute over five minutes.
*/
with data as (
select id,
sent_at,
sent_at::date as day,
round_minutes(sent_at, 5) as sent_minute
from notifications
where sent_at is not null
and sent_at >= NOW() - INTERVAL '3 hours'
and sent_at >= CURRENT_DATE
and notification_type = 'sms'
),
rollup as (
select day,
sent_minute,
count(*) / 5 as notifications_per_minute
from data
group by day,
sent_minute
)
select day,
max(notifications_per_minute) as sustained_sms_per_minute
from rollup
group by day
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7202a00

Please sign in to comment.