-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alec Holmes <[email protected]>
- Loading branch information
1 parent
6cfa5af
commit bce9cd9
Showing
7 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Benchmark Client | ||
|
||
This test client provides simulation of various workloads when communicating with the go-control-plane management server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"runtime" | ||
"time" | ||
|
||
"github.com/envoyproxy/go-control-plane/benchmarks/client/xds" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func main() { | ||
// Statically set the max procs | ||
runtime.GOMAXPROCS(runtime.NumCPU()) | ||
|
||
app := &cli.App{ | ||
Name: "xds-benchmark", | ||
Usage: "xds benchmarking tool that simulates client workload", | ||
Commands: []*cli.Command{ | ||
{ | ||
Name: "run", | ||
Aliases: []string{"r"}, | ||
Usage: "run the benchmark with the provided duration", | ||
Action: func(c *cli.Context) error { | ||
arg := c.Args().First() | ||
dur, err := time.ParseDuration(arg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sess, err := xds.NewSession("localhost:50000") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return sess.Simulate(dur) | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package xds | ||
|
||
// Options are configuration settings for the discovery object | ||
type Options struct { | ||
NodeID string | ||
Zone string | ||
Cluster string | ||
ResourceNames []string // List of Envoy resource names to subscribe to | ||
ResourceType string // ex: type.googleapis.com/envoy.api.v2.ClusterLoadAssignment | ||
} | ||
|
||
// Option follows the functional opts pattern | ||
type Option func(*Options) | ||
|
||
// WithNode will inject the node id into the configuration object | ||
func WithNode(id string) Option { | ||
return func(o *Options) { | ||
o.NodeID = id | ||
} | ||
} | ||
|
||
// WithZone will specificy which zone to use in the xDS discovery request | ||
func WithZone(zone string) Option { | ||
return func(o *Options) { | ||
o.Zone = zone | ||
} | ||
} | ||
|
||
// WithCluster will specificy which cluster the request is announcing as | ||
func WithCluster(cluster string) Option { | ||
return func(o *Options) { | ||
o.Cluster = cluster | ||
} | ||
} | ||
|
||
// WithResourceNames will inject a list of resources the user wants to place watches on | ||
func WithResourceNames(names []string) Option { | ||
return func(o *Options) { | ||
o.ResourceNames = names | ||
} | ||
} | ||
|
||
// WithResourceType will inject the specific resource type that a user wants to stream | ||
func WithResourceType(resource string) Option { | ||
return func(o *Options) { | ||
o.ResourceType = resource | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package xds | ||
|
||
import ( | ||
"time" | ||
|
||
"google.golang.org/grpc" | ||
) | ||
|
||
// Sess holds a grpc connection as well as config options to use during the simulation | ||
type Sess struct { | ||
Session *grpc.ClientConn | ||
Opts Options | ||
} | ||
|
||
// NewSession will dial a new benchmarking session with the configured options | ||
func NewSession(url string, opts ...Option) (*Sess, error) { | ||
var options Options | ||
for _, o := range opts { | ||
o(&options) | ||
} | ||
|
||
conn, err := grpc.Dial(url, grpc.WithBlock(), grpc.WithInsecure()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Sess{ | ||
Session: conn, | ||
Opts: options, | ||
}, nil | ||
} | ||
|
||
// Simulate will start an xDS stream which provides simulatest clients communicating with an xDS server | ||
func (s *Sess) Simulate(target time.Duration) error { | ||
// Create a loop that will continually do work until the elapsed time as passed | ||
for timeout := time.After(target); ; { | ||
select { | ||
case <-timeout: | ||
return nil | ||
default: | ||
// Do some work | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package xds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters