Skip to content

Commit 9b2544d

Browse files
Add benchmark
Add Count() for GradeResultCache
1 parent be4c8b8 commit 9b2544d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

backend/internal/core/cache.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ func (c *GradeResultCache) Add(key string, val types.GradeResult) {
3232
}()
3333
}
3434

35+
func (c *GradeResultCache) Count() int {
36+
c.Lock.RLock()
37+
defer c.Lock.RUnlock()
38+
return len(c.Data)
39+
}
40+
3541
func (c *GradeResultCache) Del(key string) {
3642
c.Lock.Lock()
3743
defer c.Lock.Unlock()

backend/internal/core/core_controller_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package core_test
22

33
import (
4+
"fmt"
45
"runtime"
56
"testing"
67

@@ -28,3 +29,21 @@ func TestCoreController(t *testing.T) {
2829
runtime.Gosched()
2930
}
3031
}
32+
33+
func BenchmarkCoreController(b *testing.B) {
34+
threads := 20
35+
cc := core.NewCoreController(threads)
36+
for i := 0; i < b.N; i++ {
37+
cc.GradeQueue <- types.GradeRequest{
38+
Id: "test" + fmt.Sprint(i),
39+
TestCaseName: "example-1",
40+
UserCode: "int main() { cout << \"Hello\" << endl; }",
41+
}
42+
}
43+
for {
44+
if cc.Cache.Count() == b.N {
45+
return
46+
}
47+
runtime.Gosched()
48+
}
49+
}

backend/internal/grader/compile_user_code.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func CompileUserCode(ctx context.Context, gr types.GradeRequest, tmpDir string)
6666
Resources: container.Resources{
6767
Memory: CompilationMemoryLimit,
6868
MemorySwap: CompilationMemoryLimit,
69+
CPUQuota: 10000,
6970
},
7071
}, nil, nil, "")
7172

0 commit comments

Comments
 (0)