Skip to content

Commit afbbd11

Browse files
committed
(benchmark): Add a script to send events to Lambdas
This sends 2000 events to each Lambda which should have a good range of cold and hot starts to calculate some summary statistics
1 parent 17bb63c commit afbbd11

3 files changed

Lines changed: 81 additions & 3 deletions

File tree

benchmark/scripts/download_log_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
import boto3
77

8-
LIVE_LAMBDAS = ["typescript", "rust"]
8+
LIVE_LAMBDAS = ["typescript", "rust", "ruby"]
99

1010

1111
class Row(TypedDict):

benchmark/scripts/run_load_test.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from enum import Enum, auto
2+
from typing import TypedDict
3+
from uuid import uuid4
4+
import json
5+
import boto3
6+
7+
MAX_BATCH_SIZE = 10 # 10 is the limit on the SQS SendMessageBatch API
8+
EVENTS_PER_LAMBDA = 2000
9+
10+
11+
class LiveLambdas(Enum):
12+
typescript = auto()
13+
rust = auto()
14+
ruby = auto()
15+
16+
17+
class User(TypedDict):
18+
id: str
19+
sessionId: str
20+
deviceId: str
21+
22+
23+
class Event(TypedDict):
24+
eventId: str
25+
action: str
26+
emitterCode: int
27+
user: User
28+
29+
30+
class SQSMessage(TypedDict):
31+
Id: str
32+
MessageBody: str
33+
34+
35+
def get_queue(client, language: LiveLambdas) -> str:
36+
return client.get_queue_by_name(
37+
QueueName=f"benchmark_lambda_{language.name}_queue",
38+
)
39+
40+
41+
def generate_id() -> str:
42+
return str(uuid4())
43+
44+
45+
def generate_event():
46+
return Event(
47+
eventId=generate_id(),
48+
action="sign_in",
49+
emitterCode=1,
50+
user=User(id=generate_id(), sessionId=generate_id(), deviceId=generate_id()),
51+
)
52+
53+
54+
def generate_message() -> SQSMessage:
55+
return SQSMessage(
56+
Id=generate_id(),
57+
MessageBody=json.dumps(generate_event()),
58+
)
59+
60+
61+
def send_events_to_queue(queue, num_events: int) -> None:
62+
events = [generate_message() for _ in range(num_events)]
63+
chunks = [
64+
events[i : i + MAX_BATCH_SIZE] for i in range(0, num_events, MAX_BATCH_SIZE)
65+
]
66+
for chunk in chunks:
67+
queue.send_messages(Entries=chunk)
68+
69+
70+
if __name__ == "__main__":
71+
sqs = boto3.resource("sqs")
72+
73+
for language in LiveLambdas:
74+
print(f"Running for {language.name}")
75+
queue = get_queue(client=sqs, language=language)
76+
print("Got queue resource. Sending events")
77+
send_events_to_queue(queue=queue, num_events=EVENTS_PER_LAMBDA)
78+
print("Sent events")

infra/modules/lambda/sqs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
resource "aws_sqs_queue" "queue" {
2-
name_prefix = "benchmark_lambda_${var.language_name}_queue"
3-
tags = var.default_tags
2+
name = "benchmark_lambda_${var.language_name}_queue"
3+
tags = var.default_tags
44
}

0 commit comments

Comments
 (0)