Skip to content

Commit

Permalink
Update for comments from 1/2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sara Wei committed Jan 3, 2024
1 parent 9cb6b38 commit 782552c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ bin/
# vendor/

# Go workspace file
go.work

temp/
cmd/kperf/commands/virtualcluster
go.work
2 changes: 2 additions & 0 deletions api/types/load_traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions cmd/kperf/commands/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 0 additions & 6 deletions request/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@ 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
}

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()
}
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions request/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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) {
Expand Down

0 comments on commit 782552c

Please sign in to comment.