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

ジャッジのメモリに関する不具合修正 #129

Merged
merged 1 commit into from
Dec 3, 2023
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
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
}