Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor load test #552

Merged
merged 14 commits into from
Aug 6, 2020
11 changes: 7 additions & 4 deletions cmd/tools/cli/loadtest/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ version: v0.0.0
time_zone: JST
logging:
logger: glg
level: debug
format: json
method: insert
level: info
format: raw
service: agent
operation: insert
dataset: fashion-mnist
concurrency: 100
addr: "localhost:8081"
batch_size: 10
progress_duration: 3s
addr: "localhost:8082"
client:
addrs: []
health_check_duration: 1s
Expand Down
16 changes: 5 additions & 11 deletions pkg/tools/cli/loadtest/assets/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/kpango/fuid"
"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/log"
"gonum.org/v1/hdf5"
)

Expand Down Expand Up @@ -84,39 +83,34 @@ func loadDataset(file *hdf5.File, name string, f loaderFunc) (dim int, vec inter
func Load(path string) (train, test, distances [][]float32, neighbors [][]int, dim int, err error) {
f, err := hdf5.OpenFile(path, hdf5.F_ACC_RDONLY)
if err != nil {
log.Errorf("couldn't open file %s: %s", path, err)
return nil, nil, nil, nil, 0, err
return nil, nil, nil, nil, 0, errors.Wrapf(err, "couldn't open file %s", path)
}
defer func() {
err = f.Close()
}()
trainDim, v1, err := loadDataset(f, "train", loadFloat32)
if err != nil {
log.Error("couldn't load train dataset for path %s: %s", path, err)
return nil, nil, nil, nil, 0, err
return nil, nil, nil, nil, 0, errors.Wrapf(err, "couldn't load train dataset for path %s", path)
}
train = v1.([][]float32)
dim = trainDim
testDim, v2, err := loadDataset(f, "test", loadFloat32)
if err != nil {
log.Error("couldn't load test dataset for path %s: %s", path, err)
return train, nil, nil, nil, dim, err
return train, nil, nil, nil, dim, errors.Wrapf(err, "couldn't load test dataset for path %s", path)
}
test = v2.([][]float32)
if dim != testDim {
return train, test, nil, nil, 0, errors.Errorf("test has different dimension from train")
}
distancesDim, v3, err := loadDataset(f, "distances", loadFloat32)
if err != nil {
log.Error("couldn't load distances dataset for path %s: %s", path, err)
return train, test, nil, nil, dim, err
return train, test, nil, nil, dim, errors.Wrapf(err, "couldn't load distances dataset for path %s", path)
}
distances = v3.([][]float32)

neighborsDim, v4, err := loadDataset(f, "neighbors", loadInt)
if err != nil {
log.Error("couldn't load neighbors dataset for path %s: %s", path, err)
return train, test, distances, nil, trainDim, err
return train, test, distances, nil, trainDim, errors.Wrapf(err, "couldn't load neighbors dataset for path %s", path)
}
neighbors = v4.([][]int)
if distancesDim != neighborsDim {
Expand Down
69 changes: 58 additions & 11 deletions pkg/tools/cli/loadtest/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,81 @@ import (
// GlobalConfig is type alias of config.GlobalConfig.
type GlobalConfig = config.GlobalConfig

// Operation is type of implemented load test.
// Operation is operation type of implemented load test.
type Operation uint8

// Operation method.
// Operation method definition.
const (
Unknown Operation = iota
UnknownOperation Operation = iota
Insert
StreamInsert
Search
StreamSearch
)

// OperationMethod convert string to Operation.
// OperationMethod converts string to Operation.
func OperationMethod(s string) Operation {
switch strings.ToLower(s) {
case "insert":
return Insert
case "streaminsert":
return StreamInsert
case "search":
return Search
case "streamsearch":
return StreamSearch
default:
return Unknown
return UnknownOperation
}
}

// String convert Operation to string.
// String converts Operation to string.
func (o Operation) String() string {
switch o {
case Insert:
return "insert"
return "Insert"
case StreamInsert:
return "StreamInsert"
case Search:
return "search"
return "Search"
case StreamSearch:
return "StreamSearch"
default:
return "unknown operation"
return "Unknown operation"
}
}

// Service is service type of implemented load test.
type Service uint8

// Service definitions.
const (
UnknownService Service = iota
Agent
Gateway
)

// ServiceMethod converts string to Service.
func ServiceMethod(s string) Service {
switch strings.ToLower(s) {
case "agent":
return Agent
case "gateway":
return Gateway
default:
return UnknownService
}
}

// String converts Service to string.
func (s Service) String() string {
switch s {
case Agent:
return "Agent"
case Gateway:
return "Gateway"
default:
return "Unknown service"
}
}

Expand All @@ -65,9 +109,11 @@ func (o Operation) String() string {
type Data struct {
config.GlobalConfig `json:",inline" yaml:",inline"`
Addr string `json:"addr" yaml:"addr"`
Method string `json:"method" yaml:"method"`
Service string `json:"service" yaml:"service"`
Operation string `json:"operation" yaml:"operation"`
Dataset string `json:"dataset" yaml:"dataset"`
Concurrency int `json:"concurrency" yaml:"concurrency"`
BatchSize int `json:"batch_size" yaml:"batch_size"`
ProgressDuration string `json:"progress_duration" yaml:"progress_duration"`
Client *config.GRPCClient `json:"client" yaml:"client"`
}
Expand All @@ -88,9 +134,10 @@ func NewConfig(path string) (cfg *Data, err error) {
}

cfg.Addr = config.GetActualValue(cfg.Addr)
cfg.Method = config.GetActualValue(cfg.Method)
cfg.Operation = config.GetActualValue(cfg.Operation)
cfg.Dataset = config.GetActualValue(cfg.Dataset)
cfg.ProgressDuration = config.GetActualValue(cfg.ProgressDuration)
cfg.Service = config.GetActualValue(cfg.Service)

return cfg, nil
}
133 changes: 133 additions & 0 deletions pkg/tools/cli/loadtest/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,136 @@ func TestNewConfig(t *testing.T) {
})
}
}

func TestServiceMethod(t *testing.T) {
type args struct {
s string
}
type want struct {
want Service
}
type test struct {
name string
args args
want want
checkFunc func(want, Service) error
beforeFunc func(args)
afterFunc func(args)
}
defaultCheckFunc := func(w want, got Service) error {
if !reflect.DeepEqual(got, w.want) {
return errors.Errorf("got = %v, want %v", got, w.want)
}
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
args: args {
s: "",
},
want: want{},
checkFunc: defaultCheckFunc,
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
s: "",
},
want: want{},
checkFunc: defaultCheckFunc,
}
}(),
*/
}

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
}
if test.afterFunc != nil {
defer test.afterFunc(test.args)
}
if test.checkFunc == nil {
test.checkFunc = defaultCheckFunc
}

got := ServiceMethod(test.args.s)
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}

func TestService_String(t *testing.T) {
type want struct {
want string
}
type test struct {
name string
s Service
want want
checkFunc func(want, string) error
beforeFunc func()
afterFunc func()
}
defaultCheckFunc := func(w want, got string) error {
if !reflect.DeepEqual(got, w.want) {
return errors.Errorf("got = %v, want %v", got, w.want)
}
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
want: want{},
checkFunc: defaultCheckFunc,
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
want: want{},
checkFunc: defaultCheckFunc,
}
}(),
*/
}

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc()
}
if test.afterFunc != nil {
defer test.afterFunc()
}
if test.checkFunc == nil {
test.checkFunc = defaultCheckFunc
}

got := test.s.String()
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}
Loading