Skip to content

Commit

Permalink
Add time limit language wise (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajami1331 authored May 9, 2024
1 parent dd67b1f commit 904b164
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions sojj/Dtos/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public class Language

[JsonPropertyName("execute")]
public string[]? Execute { get; set; }

[JsonPropertyName("cpuLimit")]
public long? CpuLimit { get; set; }
}
5 changes: 3 additions & 2 deletions sojj/Services/SandBoxService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public async Task<CompileResult> CompileAsync(string sourceCode, string runId, s
}

logger.LogInformation("Language {language} found", language);
long timeLimitInNs = (languageInfo.CpuLimit ?? this.cpuLimitForRuns) * Constants.NanoSecondInSecond;
var request = new SandboxRunRequest
{
Commands =
Expand All @@ -107,8 +108,8 @@ public async Task<CompileResult> CompileAsync(string sourceCode, string runId, s
Max = this.outputLimitForRuns * Constants.ByteInKiloByte,
},
],
CpuLimit = this.cpuLimitForRuns * Constants.NanoSecondInSecond,
ClockLimit = (this.cpuLimitForRuns * Constants.NanoSecondInSecond) * 3,
CpuLimit = timeLimitInNs,
ClockLimit = timeLimitInNs * 3,
MemoryLimit = this.memoryLimitForRuns * Constants.ByteInMegaByte,
ProcessLimit = this.processLimitForRuns,
CopyIn = new Dictionary<string, SandboxFile>
Expand Down
3 changes: 2 additions & 1 deletion sojj/languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"compile": ["kotlinc", "foo.kt", "-include-runtime", "-d", "foo.jar"],
"codeFile": "foo.kt",
"outputFile": "foo.jar",
"execute": ["java", "-jar", "foo.jar"]
"execute": ["java", "-jar", "foo.jar"],
"cpuLimit": 25
}
}

0 comments on commit 904b164

Please sign in to comment.