File tree Expand file tree Collapse file tree 5 files changed +144
-0
lines changed
Expand file tree Collapse file tree 5 files changed +144
-0
lines changed Original file line number Diff line number Diff line change 1+ # Benchmark Client
2+
3+ This test client provides simulation of various workloads when communicating with the go-control-plane management server.
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "log"
5+ "os"
6+ "runtime"
7+ "time"
8+
9+ "github.com/envoyproxy/go-control-plane/benchmarks/client/xds"
10+ "github.com/urfave/cli/v2"
11+ )
12+
13+ func main () {
14+ // Statically set the max procs
15+ runtime .GOMAXPROCS (runtime .NumCPU ())
16+
17+ app := & cli.App {
18+ Name : "xds-benchmark" ,
19+ Usage : "xds benchmarking tool that simulates client workload" ,
20+ Commands : []* cli.Command {
21+ {
22+ Name : "run" ,
23+ Aliases : []string {"r" },
24+ Usage : "run the benchmark with the provided duration" ,
25+ Action : func (c * cli.Context ) error {
26+ arg := c .Args ().First ()
27+ dur , err := time .ParseDuration (arg )
28+ if err != nil {
29+ return err
30+ }
31+
32+ sess , err := xds .NewSession ("localhost:50000" )
33+ if err != nil {
34+ return err
35+ }
36+
37+ return sess .Simulate (dur )
38+ },
39+ },
40+ },
41+ }
42+
43+ err := app .Run (os .Args )
44+ if err != nil {
45+ log .Fatal (err )
46+ }
47+ }
Original file line number Diff line number Diff line change 1+ package xds
2+
3+ // Options are configuration settings for the discovery object
4+ type Options struct {
5+ NodeID string
6+ Zone string
7+ Cluster string
8+ ResourceNames []string // List of Envoy resource names to subscribe to
9+ ResourceType string // ex: type.googleapis.com/envoy.api.v2.ClusterLoadAssignment
10+ }
11+
12+ // Option follows the functional opts pattern
13+ type Option func (* Options )
14+
15+ // WithNode will inject the node id into the configuration object
16+ func WithNode (id string ) Option {
17+ return func (o * Options ) {
18+ o .NodeID = id
19+ }
20+ }
21+
22+ // WithZone will specificy which zone to use in the xDS discovery request
23+ func WithZone (zone string ) Option {
24+ return func (o * Options ) {
25+ o .Zone = zone
26+ }
27+ }
28+
29+ // WithCluster will specificy which cluster the request is announcing as
30+ func WithCluster (cluster string ) Option {
31+ return func (o * Options ) {
32+ o .Cluster = cluster
33+ }
34+ }
35+
36+ // WithResourceNames will inject a list of resources the user wants to place watches on
37+ func WithResourceNames (names []string ) Option {
38+ return func (o * Options ) {
39+ o .ResourceNames = names
40+ }
41+ }
42+
43+ // WithResourceType will inject the specific resource type that a user wants to stream
44+ func WithResourceType (resource string ) Option {
45+ return func (o * Options ) {
46+ o .ResourceType = resource
47+ }
48+ }
Original file line number Diff line number Diff line change 1+ package xds
2+
3+ import (
4+ "time"
5+
6+ "google.golang.org/grpc"
7+ )
8+
9+ // Sess holds a grpc connection as well as config options to use during the simulation
10+ type Sess struct {
11+ Session * grpc.ClientConn
12+ Opts Options
13+ }
14+
15+ // NewSession will dial a new benchmarking session with the configured options
16+ func NewSession (url string , opts ... Option ) (* Sess , error ) {
17+ var options Options
18+ for _ , o := range opts {
19+ o (& options )
20+ }
21+
22+ conn , err := grpc .Dial (url , grpc .WithBlock (), grpc .WithInsecure ())
23+ if err != nil {
24+ return nil , err
25+ }
26+
27+ return & Sess {
28+ Session : conn ,
29+ Opts : options ,
30+ }, nil
31+ }
32+
33+ // Simulate will start an xDS stream which provides simulatest clients communicating with an xDS server
34+ func (s * Sess ) Simulate (target time.Duration ) error {
35+ // Create a loop that will continually do work until the elapsed time as passed
36+ for timeout := time .After (target ); ; {
37+ select {
38+ case <- timeout :
39+ return nil
40+ default :
41+ // Do some work
42+
43+ }
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ package xds
You can’t perform that action at this time.
0 commit comments