Skip to content

Commit

Permalink
tools: refactor API Bench and support HTTP server (tikv#7692)
Browse files Browse the repository at this point in the history
ref tikv#6922

Signed-off-by: Cabinfever_B <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
CabinfeverB and ti-chi-bot[bot] authored Jan 15, 2024
1 parent 91bca92 commit 3c4950d
Show file tree
Hide file tree
Showing 4 changed files with 543 additions and 203 deletions.
106 changes: 73 additions & 33 deletions tools/pd-api-bench/cases/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,61 @@ func InitCluster(ctx context.Context, cli pd.Client, httpCli pdHttp.Client) erro
return nil
}

// Config is the configuration for the case.
type Config struct {
QPS int64 `toml:"qps" json:"qps"`
Burst int64 `toml:"burst" json:"burst"`
}

func newConfig() *Config {
return &Config{
Burst: 1,
}
}

// Clone returns a cloned configuration.
func (c *Config) Clone() *Config {
cfg := *c
return &cfg
}

// Case is the interface for all cases.
type Case interface {
Name() string
SetQPS(int64)
GetQPS() int64
SetBurst(int64)
GetBurst() int64
GetConfig() *Config
}

type baseCase struct {
name string
qps int64
burst int64
name string
cfg *Config
}

func (c *baseCase) Name() string {
return c.name
}

func (c *baseCase) SetQPS(qps int64) {
c.qps = qps
c.cfg.QPS = qps
}

func (c *baseCase) GetQPS() int64 {
return c.qps
return c.cfg.QPS
}

func (c *baseCase) SetBurst(burst int64) {
c.burst = burst
c.cfg.Burst = burst
}

func (c *baseCase) GetBurst() int64 {
return c.burst
return c.cfg.Burst
}

func (c *baseCase) GetConfig() *Config {
return c.cfg.Clone()
}

// GRPCCase is the interface for all gRPC cases.
Expand All @@ -100,11 +122,12 @@ type GRPCCraeteFn func() GRPCCase

// GRPCCaseFnMap is the map for all gRPC case creation function.
var GRPCCaseFnMap = map[string]GRPCCraeteFn{
"GetRegion": newGetRegion(),
"GetStore": newGetStore(),
"GetStores": newGetStores(),
"ScanRegions": newScanRegions(),
"Tso": newTso(),
"GetRegion": newGetRegion(),
"GetRegionEnableFollower": newGetRegionEnableFollower(),
"GetStore": newGetStore(),
"GetStores": newGetStores(),
"ScanRegions": newScanRegions(),
"Tso": newTso(),
}

// GRPCCaseMap is the map for all gRPC case creation function.
Expand Down Expand Up @@ -136,9 +159,8 @@ func newMinResolvedTS() func() HTTPCase {
return func() HTTPCase {
return &minResolvedTS{
baseCase: &baseCase{
name: "GetMinResolvedTS",
qps: 1000,
burst: 1,
name: "GetMinResolvedTS",
cfg: newConfig(),
},
}
}
Expand All @@ -164,9 +186,8 @@ func newRegionStats() func() HTTPCase {
return func() HTTPCase {
return &regionsStats{
baseCase: &baseCase{
name: "GetRegionStatus",
qps: 100,
burst: 1,
name: "GetRegionStatus",
cfg: newConfig(),
},
regionSample: 1000,
}
Expand Down Expand Up @@ -200,9 +221,8 @@ func newGetRegion() func() GRPCCase {
return func() GRPCCase {
return &getRegion{
baseCase: &baseCase{
name: "GetRegion",
qps: 10000,
burst: 1,
name: "GetRegion",
cfg: newConfig(),
},
}
}
Expand All @@ -217,6 +237,30 @@ func (c *getRegion) Unary(ctx context.Context, cli pd.Client) error {
return nil
}

type getRegionEnableFollower struct {
*baseCase
}

func newGetRegionEnableFollower() func() GRPCCase {
return func() GRPCCase {
return &getRegionEnableFollower{
baseCase: &baseCase{
name: "GetRegionEnableFollower",
cfg: newConfig(),
},
}
}
}

func (c *getRegionEnableFollower) Unary(ctx context.Context, cli pd.Client) error {
id := rand.Intn(totalRegion)*4 + 1
_, err := cli.GetRegion(ctx, generateKeyForSimulator(id, 56), pd.WithAllowFollowerHandle())
if err != nil {
return err
}
return nil
}

type scanRegions struct {
*baseCase
regionSample int
Expand All @@ -226,9 +270,8 @@ func newScanRegions() func() GRPCCase {
return func() GRPCCase {
return &scanRegions{
baseCase: &baseCase{
name: "ScanRegions",
qps: 10000,
burst: 1,
name: "ScanRegions",
cfg: newConfig(),
},
regionSample: 10000,
}
Expand All @@ -255,9 +298,8 @@ func newTso() func() GRPCCase {
return func() GRPCCase {
return &tso{
baseCase: &baseCase{
name: "Tso",
qps: 10000,
burst: 1,
name: "Tso",
cfg: newConfig(),
},
}
}
Expand All @@ -279,9 +321,8 @@ func newGetStore() func() GRPCCase {
return func() GRPCCase {
return &getStore{
baseCase: &baseCase{
name: "GetStore",
qps: 10000,
burst: 1,
name: "GetStore",
cfg: newConfig(),
},
}
}
Expand All @@ -304,9 +345,8 @@ func newGetStores() func() GRPCCase {
return func() GRPCCase {
return &getStores{
baseCase: &baseCase{
name: "GetStores",
qps: 10000,
burst: 1,
name: "GetStores",
cfg: newConfig(),
},
}
}
Expand Down
Loading

0 comments on commit 3c4950d

Please sign in to comment.