From 449b44e1f6c663a5173efeca9b25adc160ea5154 Mon Sep 17 00:00:00 2001 From: Jaehyeon Kim <65964601+Jaehyeon1020@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:36:06 +0000 Subject: [PATCH 1/7] feat(be): submission controller for load test --- .../src/submission/submission.controller.ts | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/backend/apps/client/src/submission/submission.controller.ts b/apps/backend/apps/client/src/submission/submission.controller.ts index e71b0e74d8..058c603e42 100644 --- a/apps/backend/apps/client/src/submission/submission.controller.ts +++ b/apps/backend/apps/client/src/submission/submission.controller.ts @@ -7,7 +7,8 @@ import { Req, Query, DefaultValuePipe, - Headers + Headers, + ParseIntPipe } from '@nestjs/common' import { AuthNotNeededIfOpenSpace, AuthenticatedRequest } from '@libs/auth' import { @@ -77,12 +78,14 @@ export class SubmissionController { */ @Post('test') async submitTest( - @Req() req: AuthenticatedRequest, + // @Req() req: AuthenticatedRequest, + @Query('userId', ParseIntPipe) userId: number, // TODO: 로드테스트용, 테스트 후 삭제 @Query('problemId', new RequiredIntPipe('problemId')) problemId: number, @Body() submissionDto: CreateSubmissionDto ) { return await this.submissionService.submitTest( - req.user.id, + // req.user.id, + userId, problemId, submissionDto ) @@ -93,8 +96,9 @@ export class SubmissionController { * @returns Testcase별 결과가 담겨있는 Object */ @Get('test') - async getTestResult(@Req() req: AuthenticatedRequest) { - return await this.submissionService.getTestResult(req.user.id) + // TODO: 로드테스트용, 테스트 후 삭제 (req 사용으로 되돌리기) + async getTestResult(@Query('userId', ParseIntPipe) userId: number) { + return await this.submissionService.getTestResult(userId) } /** @@ -103,12 +107,13 @@ export class SubmissionController { */ @Post('user-test') async submitUserTest( - @Req() req: AuthenticatedRequest, + // @Req() req: AuthenticatedRequest, + @Query('userId', ParseIntPipe) userId: number, // TODO: 로드테스트용, 테스트 후 삭제 @Query('problemId', new RequiredIntPipe('problemId')) problemId: number, @Body() userTestSubmissionDto: CreateUserTestSubmissionDto ) { return await this.submissionService.submitTest( - req.user.id, + userId, problemId, userTestSubmissionDto, true @@ -120,8 +125,9 @@ export class SubmissionController { * @returns Testcase별 결과가 담겨있는 Object */ @Get('user-test') - async getUserTestResult(@Req() req: AuthenticatedRequest) { - return await this.submissionService.getTestResult(req.user.id, true) + // TODO: 로드테스트용, 테스트 후 삭제 (req 사용으로 되돌리기) + async getUserTestResult(@Query('userId', ParseIntPipe) userId: number) { + return await this.submissionService.getTestResult(userId, true) } @Get('delay-cause') From 09c4ca3fde989eb7494f5034b8acba25e2817853 Mon Sep 17 00:00:00 2001 From: Jaehyeon Kim Date: Sat, 7 Dec 2024 16:05:40 +0900 Subject: [PATCH 2/7] feat(iris): serialize testcase judging (#2255) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(be): serialize testcase judging - 병렬적으로 처리되고 있던 tc 채점을 직렬화합니다. --- apps/iris/src/handler/judge-handler.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/apps/iris/src/handler/judge-handler.go b/apps/iris/src/handler/judge-handler.go index 83c5305676..547ca24afc 100644 --- a/apps/iris/src/handler/judge-handler.go +++ b/apps/iris/src/handler/judge-handler.go @@ -284,13 +284,9 @@ func (j *JudgeHandler) Handle(id string, data []byte, hidden bool, out chan Judg } tcNum := tc.Count() - cnt := make(chan int) for i := 0; i < tcNum; i++ { - go j.judgeTestcase(i, dir, validReq, tc.Elements[i], out, cnt) - } - - for i := 0; i < tcNum; i++ { - <-cnt + j.judgeTestcase(i, dir, validReq, tc.Elements[i], out) + // j.logger.Log(logger.DEBUG, fmt.Sprintf("Testcase %d judged", i)) } } @@ -324,7 +320,7 @@ func (j *JudgeHandler) getTestcase(traceCtx context.Context, out chan<- result.C } func (j *JudgeHandler) judgeTestcase(idx int, dir string, validReq *Request, - tc loader.Element, out chan JudgeResultMessage, cnt chan int) { + tc loader.Element, out chan JudgeResultMessage) { var accepted bool @@ -376,5 +372,4 @@ Send: // j.logger.Log(logger.DEBUG, string(marshaledRes)) out <- JudgeResultMessage{marshaledRes, ParseError(res)} } - cnt <- 1 } From 9c6e9efd3a2320c9b5ee8fff7dcf6c69588be6cb Mon Sep 17 00:00:00 2001 From: donghun1214 Date: Sat, 7 Dec 2024 07:18:25 +0000 Subject: [PATCH 3/7] fix(infra): change iris spec for serialzation --- apps/infra/production/codedang/codedang_service_iris.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/infra/production/codedang/codedang_service_iris.tf b/apps/infra/production/codedang/codedang_service_iris.tf index d3fdc5cbb2..0cf2e0e60b 100644 --- a/apps/infra/production/codedang/codedang_service_iris.tf +++ b/apps/infra/production/codedang/codedang_service_iris.tf @@ -31,7 +31,7 @@ module "iris" { task_definition = { family = "Codedang-Iris-Api" cpu = 512 - memory = 1700 + memory = 512 container_definitions = jsonencode([ jsondecode(templatefile("container_definitions/iris.json", { From e92dd4dd5d5499626c2ac648aaef5b4ca2ed6836 Mon Sep 17 00:00:00 2001 From: Jaehyeon Kim Date: Sat, 7 Dec 2024 17:19:08 +0900 Subject: [PATCH 4/7] feat(iris): limit judge result output (#2256) * feat(iris): limit judge result output * feat(iris): set limit 1MB --- apps/iris/src/common/constants/constants.go | 2 ++ apps/iris/src/handler/judge-handler.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/apps/iris/src/common/constants/constants.go b/apps/iris/src/common/constants/constants.go index 0aae1ce8cc..dccb337ead 100644 --- a/apps/iris/src/common/constants/constants.go +++ b/apps/iris/src/common/constants/constants.go @@ -53,3 +53,5 @@ const ( EXCHANGE = "judger-exchange" RESULT_KEY = "result" ) + +const MAX_OUTPUT = 1048576 // 1MB diff --git a/apps/iris/src/handler/judge-handler.go b/apps/iris/src/handler/judge-handler.go index 547ca24afc..14241b1435 100644 --- a/apps/iris/src/handler/judge-handler.go +++ b/apps/iris/src/handler/judge-handler.go @@ -347,6 +347,10 @@ func (j *JudgeHandler) judgeTestcase(idx int, dir string, validReq *Request, res.SetJudgeExecResult(runResult.ExecResult) res.Output = string(runResult.Output) + if len(res.Output) > constants.MAX_OUTPUT { + res.Output = res.Output[:constants.MAX_OUTPUT] + } + if runResult.ExecResult.ResultCode != sandbox.RUN_SUCCESS { res.SetJudgeResultCode(SandboxResultCodeToJudgeResultCode(runResult.ExecResult.ResultCode)) goto Send From ca2c4bb0fe264b94a8c164187f45c34361f71cc5 Mon Sep 17 00:00:00 2001 From: Jaehyeon Kim <65964601+Jaehyeon1020@users.noreply.github.com> Date: Sat, 7 Dec 2024 09:21:54 +0000 Subject: [PATCH 5/7] Revert "feat(be): submission controller for load test" This reverts commit 449b44e1f6c663a5173efeca9b25adc160ea5154. --- .../src/submission/submission.controller.ts | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/apps/backend/apps/client/src/submission/submission.controller.ts b/apps/backend/apps/client/src/submission/submission.controller.ts index 058c603e42..e71b0e74d8 100644 --- a/apps/backend/apps/client/src/submission/submission.controller.ts +++ b/apps/backend/apps/client/src/submission/submission.controller.ts @@ -7,8 +7,7 @@ import { Req, Query, DefaultValuePipe, - Headers, - ParseIntPipe + Headers } from '@nestjs/common' import { AuthNotNeededIfOpenSpace, AuthenticatedRequest } from '@libs/auth' import { @@ -78,14 +77,12 @@ export class SubmissionController { */ @Post('test') async submitTest( - // @Req() req: AuthenticatedRequest, - @Query('userId', ParseIntPipe) userId: number, // TODO: 로드테스트용, 테스트 후 삭제 + @Req() req: AuthenticatedRequest, @Query('problemId', new RequiredIntPipe('problemId')) problemId: number, @Body() submissionDto: CreateSubmissionDto ) { return await this.submissionService.submitTest( - // req.user.id, - userId, + req.user.id, problemId, submissionDto ) @@ -96,9 +93,8 @@ export class SubmissionController { * @returns Testcase별 결과가 담겨있는 Object */ @Get('test') - // TODO: 로드테스트용, 테스트 후 삭제 (req 사용으로 되돌리기) - async getTestResult(@Query('userId', ParseIntPipe) userId: number) { - return await this.submissionService.getTestResult(userId) + async getTestResult(@Req() req: AuthenticatedRequest) { + return await this.submissionService.getTestResult(req.user.id) } /** @@ -107,13 +103,12 @@ export class SubmissionController { */ @Post('user-test') async submitUserTest( - // @Req() req: AuthenticatedRequest, - @Query('userId', ParseIntPipe) userId: number, // TODO: 로드테스트용, 테스트 후 삭제 + @Req() req: AuthenticatedRequest, @Query('problemId', new RequiredIntPipe('problemId')) problemId: number, @Body() userTestSubmissionDto: CreateUserTestSubmissionDto ) { return await this.submissionService.submitTest( - userId, + req.user.id, problemId, userTestSubmissionDto, true @@ -125,9 +120,8 @@ export class SubmissionController { * @returns Testcase별 결과가 담겨있는 Object */ @Get('user-test') - // TODO: 로드테스트용, 테스트 후 삭제 (req 사용으로 되돌리기) - async getUserTestResult(@Query('userId', ParseIntPipe) userId: number) { - return await this.submissionService.getTestResult(userId, true) + async getUserTestResult(@Req() req: AuthenticatedRequest) { + return await this.submissionService.getTestResult(req.user.id, true) } @Get('delay-cause') From 6253d410dfcac222dd65f459909c1f4e3f75b0f3 Mon Sep 17 00:00:00 2001 From: donghun1214 Date: Sat, 7 Dec 2024 09:29:53 +0000 Subject: [PATCH 6/7] fix(infra): update iris spec container after load-test --- apps/infra/production/codedang/codedang_service_client.tf | 2 +- apps/infra/production/codedang/codedang_service_iris.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/infra/production/codedang/codedang_service_client.tf b/apps/infra/production/codedang/codedang_service_client.tf index ad7e03d6d3..d9d56553c0 100644 --- a/apps/infra/production/codedang/codedang_service_client.tf +++ b/apps/infra/production/codedang/codedang_service_client.tf @@ -107,7 +107,7 @@ module "client_api" { ecs_service = { name = "Codedang-Client-Api-Service" cluster_arn = module.codedang_api.ecs_cluster.arn - desired_count = 2 + desired_count = 3 load_balancer = { container_name = "Codedang-Client-Api" container_port = 4000 diff --git a/apps/infra/production/codedang/codedang_service_iris.tf b/apps/infra/production/codedang/codedang_service_iris.tf index 0cf2e0e60b..3b8232490f 100644 --- a/apps/infra/production/codedang/codedang_service_iris.tf +++ b/apps/infra/production/codedang/codedang_service_iris.tf @@ -75,7 +75,7 @@ module "iris" { ecs_service = { name = "Codedang-Iris-Service" cluster_arn = module.codedang_iris.ecs_cluster.arn - desired_count = 2 + desired_count = 6 } appautoscaling_target = { From f2654a87b60080782f83ffedb496cf1921de21ee Mon Sep 17 00:00:00 2001 From: donghun1214 Date: Sat, 7 Dec 2024 09:36:27 +0000 Subject: [PATCH 7/7] fix(infra): change the number of iris and api container --- apps/infra/production/codedang/codedang_service_client.tf | 2 +- apps/infra/production/codedang/codedang_service_iris.tf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/infra/production/codedang/codedang_service_client.tf b/apps/infra/production/codedang/codedang_service_client.tf index d9d56553c0..f8f6c0b5b2 100644 --- a/apps/infra/production/codedang/codedang_service_client.tf +++ b/apps/infra/production/codedang/codedang_service_client.tf @@ -116,7 +116,7 @@ module "client_api" { } appautoscaling_target = { - min_capacity = 2 + min_capacity = 3 max_capacity = 8 resource_id = { cluster_name = module.codedang_api.ecs_cluster.name diff --git a/apps/infra/production/codedang/codedang_service_iris.tf b/apps/infra/production/codedang/codedang_service_iris.tf index 3b8232490f..1b68129a1b 100644 --- a/apps/infra/production/codedang/codedang_service_iris.tf +++ b/apps/infra/production/codedang/codedang_service_iris.tf @@ -79,8 +79,8 @@ module "iris" { } appautoscaling_target = { - min_capacity = 2 - max_capacity = 8 + min_capacity = 6 + max_capacity = 6 resource_id = { cluster_name = module.codedang_iris.ecs_cluster.name }