feat: add benchmark for ContainerRun{Pool}

This commit is contained in:
Paul Pan 2024-02-15 12:54:29 +08:00
parent 6956fe4ee1
commit f284e452d1
Signed by: Paul
GPG Key ID: D639BDF5BA578AF4
2 changed files with 77 additions and 0 deletions

View 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)
}
}

View 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)
}