diff --git a/.gitignore b/.gitignore index 7aebfc0..342c536 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,4 @@ bin/ # vendor/ # Go workspace file -go.work - -temp/ -cmd/kperf/commands/virtualcluster \ No newline at end of file +go.work \ No newline at end of file diff --git a/api/types/load_traffic.go b/api/types/load_traffic.go index 4abf8e8..628d6aa 100644 --- a/api/types/load_traffic.go +++ b/api/types/load_traffic.go @@ -20,6 +20,8 @@ type LoadProfileSpec struct { Total int `json:"total" yaml:"total"` // Conns defines total number of long connections used for traffic. Conns int `json:"conns" yaml:"conns"` + // Client defines total number of HTTP clients. + Client int `json:"client" yaml:"client"` // Requests defines the different kinds of requests with weights. // The executor should randomly pick by weight. Requests []*WeightedRequest diff --git a/cmd/kperf/commands/runner/runner.go b/cmd/kperf/commands/runner/runner.go index 00f741d..a675f1c 100644 --- a/cmd/kperf/commands/runner/runner.go +++ b/cmd/kperf/commands/runner/runner.go @@ -76,13 +76,12 @@ var runCommand = cli.Command{ userAgent := cliCtx.String("user-agent") conns := profileCfg.Spec.Conns - client := profileCfg.Spec.Conns rate := profileCfg.Spec.Rate restClis, err := request.NewClients(kubeCfgPath, conns, userAgent, rate, contentType) if err != nil { return err } - stats, err := request.Schedule(context.TODO(), client, &profileCfg.Spec, restClis) + stats, err := request.Schedule(context.TODO(), &profileCfg.Spec, restClis) if err != nil { return err @@ -114,6 +113,9 @@ func loadConfig(cliCtx *cli.Context) (*types.LoadProfile, error) { if v := "conns"; cliCtx.IsSet(v) || profileCfg.Spec.Conns == 0 { profileCfg.Spec.Conns = cliCtx.Int(v) } + if v := "client"; cliCtx.IsSet(v) || profileCfg.Spec.Client == 0 { + profileCfg.Spec.Client = cliCtx.Int(v) + } if v := "total"; cliCtx.IsSet(v) || profileCfg.Spec.Total == 0 { profileCfg.Spec.Total = cliCtx.Int(v) } diff --git a/request/client.go b/request/client.go index cab0618..54218ff 100644 --- a/request/client.go +++ b/request/client.go @@ -13,12 +13,9 @@ import ( // // FIXME(weifu): // -// 1. Is it possible to build one http2 client with multiple connections? // 2. How to monitor HTTP2 GOAWAY frame? -// 3. Support Protobuf as accepted content func NewClients(kubeCfgPath string, ConnsNum int, userAgent string, qps int, contentType string) ([]rest.Interface, error) { restCfg, err := clientcmd.BuildConfigFromFlags("", kubeCfgPath) - if err != nil { return nil, err } @@ -26,12 +23,10 @@ func NewClients(kubeCfgPath string, ConnsNum int, userAgent string, qps int, con if qps == 0 { qps = math.MaxInt32 } - restCfg.QPS = float32(qps) restCfg.NegotiatedSerializer = scheme.Codecs.WithoutConversion() restCfg.UserAgent = userAgent - if restCfg.UserAgent == "" { restCfg.UserAgent = rest.DefaultKubernetesUserAgent() } @@ -52,7 +47,6 @@ func NewClients(kubeCfgPath string, ConnsNum int, userAgent string, qps int, con restCli, err := rest.UnversionedRESTClientFor(&cfgShallowCopy) if err != nil { - fmt.Printf("Failed to create rest client: %v\n", err) return nil, err } restClients = append(restClients, restCli) diff --git a/request/schedule.go b/request/schedule.go index c94e307..f73b773 100644 --- a/request/schedule.go +++ b/request/schedule.go @@ -17,7 +17,7 @@ import ( const defaultTimeout = 60 * time.Second // Schedule files requests to apiserver based on LoadProfileSpec. -func Schedule(ctx context.Context, clientNum int, spec *types.LoadProfileSpec, restCli []rest.Interface) (*types.ResponseStats, error) { +func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.Interface) (*types.ResponseStats, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -36,8 +36,8 @@ func Schedule(ctx context.Context, clientNum int, spec *types.LoadProfileSpec, r var wg sync.WaitGroup respMetric := metrics.NewResponseMetric() - for i := 0; i < clientNum; i++ { - //reuse connection if client > conns + for i := 0; i < spec.Client; i++ { + // reuse connection if clients > conns cli := restCli[i%len(restCli)] wg.Add(1) go func(cli rest.Interface) {