Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iris): serialize testcase judging and limit output size #2258

Merged
merged 7 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/infra/production/codedang/codedang_service_client.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions apps/infra/production/codedang/codedang_service_iris.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -75,12 +75,12 @@ module "iris" {
ecs_service = {
name = "Codedang-Iris-Service"
cluster_arn = module.codedang_iris.ecs_cluster.arn
desired_count = 2
desired_count = 6
}

appautoscaling_target = {
min_capacity = 2
max_capacity = 8
min_capacity = 6
max_capacity = 6
resource_id = {
cluster_name = module.codedang_iris.ecs_cluster.name
}
Expand Down
2 changes: 2 additions & 0 deletions apps/iris/src/common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ const (
EXCHANGE = "judger-exchange"
RESULT_KEY = "result"
)

const MAX_OUTPUT = 1048576 // 1MB
15 changes: 7 additions & 8 deletions apps/iris/src/handler/judge-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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

Expand All @@ -351,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
Expand All @@ -376,5 +376,4 @@ Send:
// j.logger.Log(logger.DEBUG, string(marshaledRes))
out <- JudgeResultMessage{marshaledRes, ParseError(res)}
}
cnt <- 1
}
Loading