feat: add benchmark for ContainerRun{Pool}
This commit is contained in:
parent
6956fe4ee1
commit
f284e452d1
42
internal/service/runner/container_test.go
Normal file
42
internal/service/runner/container_test.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package runner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkContainerRun(b *testing.B) {
|
||||||
|
srv := GetService(false).(*service)
|
||||||
|
|
||||||
|
args := &RunArgs{
|
||||||
|
Program: ProgramArgs{Args: []string{"sh", "-c", "echo hello world"}},
|
||||||
|
Runtime: RuntimeArgs{Image: ContainerImageRun},
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_, err := srv.ContainerRun(args)
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkContainerRunPool(b *testing.B) {
|
||||||
|
srv := GetService(false).(*service)
|
||||||
|
|
||||||
|
args := &RunArgs{
|
||||||
|
Program: ProgramArgs{Args: []string{"sh", "-c", "echo hello world"}},
|
||||||
|
Runtime: RuntimeArgs{Image: ContainerImageRun},
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
var ids []uint64
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
id := srv.ContainerRunPool(args)
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, id := range ids {
|
||||||
|
srv.pool.WaitForTask(id)
|
||||||
|
}
|
||||||
|
}
|
35
internal/service/runner/service_test.go
Normal file
35
internal/service/runner/service_test.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package runner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.0x7f.app/WOJ/woj-server/internal/misc/config"
|
||||||
|
"git.0x7f.app/WOJ/woj-server/internal/misc/log"
|
||||||
|
"git.0x7f.app/WOJ/woj-server/internal/model"
|
||||||
|
"github.com/samber/do"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FakeConfigService struct {
|
||||||
|
conf model.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FakeConfigService) GetConfig() *model.Config {
|
||||||
|
return &s.conf
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FakeConfigService) HealthCheck() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetService(dev bool) Service {
|
||||||
|
injector := do.New()
|
||||||
|
|
||||||
|
cfg := &FakeConfigService{conf: model.Config{
|
||||||
|
Runner: model.ConfigRunner{Address: "/run/containerd/containerd.sock"},
|
||||||
|
Development: dev,
|
||||||
|
}}
|
||||||
|
|
||||||
|
do.ProvideValue[config.Service](injector, cfg)
|
||||||
|
do.Provide(injector, log.NewService)
|
||||||
|
do.Provide(injector, NewService)
|
||||||
|
|
||||||
|
return do.MustInvoke[Service](injector)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user