Skip to content

Commit

Permalink
[Fix] memory issue in judge system (#129)
Browse files Browse the repository at this point in the history
`judge.go`
メモリ制限を262144から1024*1024へ変更

`run.go`
`ulimit`のメモリ制限を`-m`から`-v`へ変更
終了ステータスに関わらず`TLE`、`MLE`を判定
  • Loading branch information
ocha98 authored Dec 3, 2023
1 parent 1b58d00 commit 68dfbcf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mojacoder-backend/judge-image/judge.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func judge(definition LanguageDefinition, data JudgeQueueData) error {
return fmt.Errorf(errorMessage, err)
}
stdoutWriter := strings.Builder{}
result, err := run(definition, inTestcaseFile, &stdoutWriter, nil, 2, 262144)
result, err := run(definition, inTestcaseFile, &stdoutWriter, nil, 2, 1024*1024)
if err != nil {
return fmt.Errorf(errorMessage, err)
}
Expand Down
18 changes: 9 additions & 9 deletions mojacoder-backend/judge-image/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type RunResult struct {
func run(definition LanguageDefinition, stdin io.Reader, stdout io.Writer, stderr io.Writer, timeLimit, memoryLimit int) (RunResult, error) {
var result RunResult
var err error
command := fmt.Sprintf("ulimit -u 32 -m %d && timeout --preserve-status -sSIGKILL %d %s; EXIT_CODE=$?; kill -SIGKILL -1; wait; exit $EXIT_CODE", memoryLimit, timeLimit, definition.RunCommand)
additional_memory := 5 * 1024
command := fmt.Sprintf("ulimit -u 32 -v %d && timeout --preserve-status -sSIGKILL %d %s; EXIT_CODE=$?; kill -SIGKILL -1; wait; exit $EXIT_CODE", memoryLimit+additional_memory, timeLimit, definition.RunCommand)
cmd := exec.Command("bash", "-c", command)
cmd.Env = []string{}
cmd.Dir = TEMP_DIR
Expand All @@ -47,14 +48,13 @@ func run(definition LanguageDefinition, stdin io.Reader, stdout io.Writer, stder
result.exitCode = cmd.ProcessState.ExitCode()
result.time = int((end.Sub(start)).Milliseconds())
result.memory = int(cmd.ProcessState.SysUsage().(*syscall.Rusage).Maxrss)
if !cmd.ProcessState.Success() {
if result.time > timeLimit*1000 {
result.status = RunResultStatusTimeLimitExceeded
} else if result.memory > memoryLimit {
result.status = RunResultStatusMemoryLimitExceeded
} else {
result.status = RunResultStatusRunTimeError
}

if result.time > timeLimit*1000 {
result.status = RunResultStatusTimeLimitExceeded
} else if result.memory > memoryLimit {
result.status = RunResultStatusMemoryLimitExceeded
} else if !cmd.ProcessState.Success() {
result.status = RunResultStatusRunTimeError
}
return result, nil
}

0 comments on commit 68dfbcf

Please sign in to comment.