2024-02-15 12:54:29 +08:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkContainerRun(b *testing.B) {
|
|
|
|
srv := GetService(false).(*service)
|
|
|
|
|
|
|
|
args := &RunArgs{
|
2024-03-13 20:03:12 +08:00
|
|
|
Program: ProgramArgs{Args: []string{"/bin/sh", "-c", "echo hello world"}},
|
|
|
|
Runtime: RuntimeArgs{Rootfs: RootfsRunDir, Memory: 16 * 1024 * 1024},
|
2024-02-15 12:54:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2024-03-13 20:03:12 +08:00
|
|
|
_, err := srv.JailRun(args)
|
2024-02-15 12:54:29 +08:00
|
|
|
if err != nil {
|
|
|
|
b.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkContainerRunPool(b *testing.B) {
|
|
|
|
srv := GetService(false).(*service)
|
|
|
|
|
|
|
|
args := &RunArgs{
|
2024-03-13 20:03:12 +08:00
|
|
|
Program: ProgramArgs{Args: []string{"/bin/sh", "-c", "echo hello world"}},
|
|
|
|
Runtime: RuntimeArgs{Rootfs: RootfsRunDir, Memory: 16 * 1024 * 1024},
|
2024-02-15 12:54:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
var ids []uint64
|
|
|
|
for i := 0; i < b.N; i++ {
|
2024-03-13 20:03:12 +08:00
|
|
|
id := srv.JailRunPool(args)
|
2024-02-15 12:54:29 +08:00
|
|
|
ids = append(ids, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, id := range ids {
|
2024-03-13 20:03:12 +08:00
|
|
|
buf := srv.pool.WaitForTask(id)
|
|
|
|
if buf.Error != nil {
|
|
|
|
b.Error(buf.Error)
|
|
|
|
}
|
2024-02-15 12:54:29 +08:00
|
|
|
}
|
|
|
|
}
|