Skip to content

Commit

Permalink
Merge pull request #13 from aws-cloud-clubs/feat/12-jaeger
Browse files Browse the repository at this point in the history
#12: 로그 트레이싱을 위한 Jaeger 설정 및 성능 테스트 코드 정리
  • Loading branch information
Coldot authored Aug 8, 2024
2 parents fd82ecd + f7e5ff1 commit d2438c3
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 77 deletions.
24 changes: 15 additions & 9 deletions .aws/ecs-task-definition-chat.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"taskDefinitionArn": "arn:aws:ecs:ap-northeast-2:008971651785:task-definition/cloud6-chat-server:13",
"taskDefinitionArn": "arn:aws:ecs:ap-northeast-2:008971651785:task-definition/cloud6-chat-server",
"containerDefinitions": [
{
"name": "cloud6-chat",
"image": "008971651785.dkr.ecr.ap-northeast-2.amazonaws.com/cloud6-chat:938df75d3687680cabd6c3fb4e6137181bd25aa7",
"image": "008971651785.dkr.ecr.ap-northeast-2.amazonaws.com/cloud6-chat:230145b40161b7fb205158b3330a8805ed60d692",
"cpu": 0,
"portMappings": [
{
Expand All @@ -15,7 +15,16 @@
}
],
"essential": true,
"environment": [],
"environment": [
{
"name": "JAEGER_PORT",
"value": "6831"
},
{
"name": "JAEGER_HOST",
"value": "jaeger.cloud6-chat"
}
],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
Expand All @@ -34,7 +43,6 @@
"family": "cloud6-chat-server",
"executionRoleArn": "arn:aws:iam::008971651785:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"revision": 13,
"volumes": [],
"status": "ACTIVE",
"requiresAttributes": [
Expand Down Expand Up @@ -71,13 +79,11 @@
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "4096",
"memory": "8192",
"cpu": "1024",
"memory": "2048",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"registeredAt": "2024-08-02T23:46:22.568Z",
"registeredBy": "arn:aws:iam::008971651785:user/chaeri9813",
"tags": []
}
}
1 change: 1 addition & 0 deletions chat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.4'
implementation platform('software.amazon.awssdk:bom:2.20.85')
implementation 'software.amazon.awssdk:dynamodb-enhanced'
implementation 'io.opentracing.contrib:opentracing-spring-jaeger-web-starter:3.3.1'
compileOnly 'org.projectlombok:lombok'
// developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
5 changes: 5 additions & 0 deletions chat/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ aws.accessKeyId=${AWS_ACCESS_KEY_ID}
aws.secretAccessKey=${AWS_SECRET_ACCESS_KEY}
aws.region=ap-northeast-2

### Jaeger ###
opentracing.jaeger.service-name=chat
opentracing.jaeger.udp-sender.host=${JAEGER_HOST}
opentracing.jaeger.udp-sender.port=${JAEGER_PORT}

server.servlet.session.timeout=10m
14 changes: 14 additions & 0 deletions performance_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.12-slim
RUN ln -snf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
RUN echo Asia/Seoul > /etc/timezone

WORKDIR /locust

COPY src/ ./src/
COPY pyproject.toml ./

RUN pip install poetry
RUN poetry install

EXPOSE 8089
ENTRYPOINT ["poetry", "run", "locust", "-f", "src/load/locustfile.py", "--host", "http://0.0.0.0:8089"]
114 changes: 67 additions & 47 deletions performance_test/src/common/stomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@


class StompClient:
def __init__(self, host, port, endpoint) -> None:
self.__ws_uri = f"ws://{host}:{port}/{endpoint}"
def __init__(self, host, endpoint) -> None:
self.__ws_uri = f"ws://{host}/{endpoint}"
self.__ws = websocket.WebSocket()

def __del__(self):
self.close()
Expand All @@ -18,76 +19,95 @@ def close(self):
def connect(self):
start_time = time.time()

try:
self.__ws = websocket.create_connection(self.__ws_uri)
self.__ws.send(stomper.connect())
# self.__ws.recv()
self.__ws.connect(self.__ws_uri, timeout=100000)
self.__ws.send("CONNECT\naccept-version:1.0,1.1,2.0\n\n\x00\n")
self.__ws.recv()

except Exception as e:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="connect", response_time=total_time, exception=e)
# try:
# # self.__ws = websocket.create_connection(self.__ws_uri)
# self.__ws.connect(self.__ws_uri, timeout=100000)
# self.__ws.send("CONNECT\naccept-version:1.0,1.1,2.0\n\n\x00\n")
# # self.__ws.send(stomper.connect())
# self.__ws.recv()

# except Exception as e:
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="connect", response_time=total_time, exception=e)

else:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="connect", response_time=total_time)
# else:
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="connect", response_time=total_time)

def subscribe(self, destination, id):
start_time = time.time()

try:
self.__ws.send(stomper.subscribe(destination, id))
# self.__ws.recv()
self.__ws.send(stomper.subscribe(destination, id))

# try:
# self.__ws.send(stomper.subscribe(destination, id))
# # self.__ws.recv()

except Exception as e:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="subscribe", response_time=total_time, exception=e)
# except Exception as e:
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="subscribe", response_time=total_time, exception=e)

else:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="subscribe", response_time=total_time)
# else:
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="subscribe", response_time=total_time)

def send(self, destination, message):
start_time = time.time()

try:
self.__ws.send(stomper.send(destination, message))
# self.__ws.recv()
self.__ws.send(stomper.send(destination, message, content_type="application/json"))

# try:
# self.__ws.send(stomper.send(destination, message, content_type="application/json"))
# # self.__ws.recv()

except Exception as e:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="send", response_time=total_time, exception=e)
# except Exception as e:
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="send", response_time=total_time, exception=e)

else:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="send", response_time=total_time)
# else:
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="send", response_time=total_time)

def receive(self):
start_time = time.time()
message = ""

try:
message = self.__ws.recv()
message = self.__ws.recv()

except Exception as e:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="receive", response_time=total_time, exception=e)
# try:
# # print("try...")
# message = self.__ws.recv()

# except Exception as e:
# print("except:", e)
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="receive", response_time=total_time, exception=e)

else:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="receive", response_time=total_time, response_length=len(message))
# else:
# print('else...')
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="receive", response_time=total_time, response_length=len(message))

# print("Received message:", message)
return message

def disconnect(self):
start_time = time.time()

try:
self.__ws.send(stomper.disconnect())
# self.__ws.recv()
self.__ws.send(stomper.disconnect())

# try:
# self.__ws.send(stomper.disconnect())
# # self.__ws.recv()

except Exception as e:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="disconnect", response_time=total_time, exception=e)
# except Exception as e:
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="disconnect", response_time=total_time, exception=e)

else:
total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="disconnect", response_time=total_time)
# else:
# total_time = int((time.time() - start_time) * 1000)
# events.request.fire(request_type="STOMP", name="disconnect", response_time=total_time)
47 changes: 26 additions & 21 deletions performance_test/src/load/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@


class ChatLoadTestUser(User):
host = "localhost"
port = 8080
endpoint = "chat"
host = "cloud6-lb-997344652.ap-northeast-2.elb.amazonaws.com"
endpoint = "ws"

vuser = 6

Expand All @@ -25,29 +24,35 @@ def on_start(self):

self.__stomp_clients: list[StompClient] = []
for i in range(self.vuser):
self.__stomp_clients.append(StompClient(self.host, self.port, self.endpoint))
self.__stomp_clients.append(StompClient(self.host, self.endpoint))
self.__stomp_clients[i].connect()
self.__stomp_clients[i].subscribe(f"/topic/chat/{self.room_id}", f"user{i}")
self.__stomp_clients[i].subscribe(f"/topic/{self.room_id}", f"user{i}")

def on_stop(self):
for i in range(self.vuser):
self.__stomp_clients[i].disconnect()

@task
def send_receive_hello(self):
start_time = time.time()

payload = json.dumps({
"chatRoomId": self.room_id,
"type": "MESSAGE",
"createdBy": "user0",
"text": "Hello, world!",
"createdAt": datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
})
self.__stomp_clients[0].send("/topic/chat", payload)

for i in range(1, self.vuser):
msg = self.__stomp_clients[i].receive()

total_time = int((time.time() - start_time) * 1000)
self.environment.events.request.fire(request_type="STOMP", name="send_receive_hello", response_time=total_time, response_length=len(msg))
try:
start_time = time.time()

payload = json.dumps({
"roomId": self.room_id,
"memberId": f"00000",
"type": "MESSAGE",
"createdBy": "user0",
"comment": "Hello, world!",
"createdAt": datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
})
self.__stomp_clients[0].send(f"/app/chat/{self.room_id}", payload)

for i in range(self.vuser):
msg = self.__stomp_clients[i].receive()

total_time = int((time.time() - start_time) * 1000)

except Exception as e:
self.environment.events.request.fire(request_type="STOMP", name="send_receive_hello", response_time=total_time, response_length=0, exception=e)
else:
self.environment.events.request.fire(request_type="STOMP", name="send_receive_hello", response_time=total_time, response_length=len(msg))

0 comments on commit d2438c3

Please sign in to comment.