Skip to content

Commit

Permalink
tools: support more concurrency for API bench (#7867)
Browse files Browse the repository at this point in the history
ref #7703

Signed-off-by: Cabinfever_B <[email protected]>
  • Loading branch information
CabinfeverB authored Mar 4, 2024
1 parent 1833ce2 commit 2851db2
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions tools/pd-api-bench/cases/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,25 @@ func (c *httpController) run() {
c.wg.Add(1)
go func(hCli pdHttp.Client) {
defer c.wg.Done()
var ticker = time.NewTicker(tt)
defer ticker.Stop()
for {
select {
case <-ticker.C:
for i := int64(0); i < burst; i++ {
err := c.Do(c.ctx, hCli)
if err != nil {
log.Error("meet error when doing HTTP request", zap.String("case", c.Name()), zap.Error(err))
c.wg.Add(int(burst))
for i := int64(0); i < burst; i++ {
go func() {
defer c.wg.Done()
var ticker = time.NewTicker(tt)
defer ticker.Stop()
for {
select {
case <-ticker.C:
err := c.Do(c.ctx, hCli)
if err != nil {
log.Error("meet erorr when doing HTTP request", zap.String("case", c.Name()), zap.Error(err))
}
case <-c.ctx.Done():
log.Info("Got signal to exit running HTTP case")
return
}
}
case <-c.ctx.Done():
log.Info("Got signal to exit running HTTP case")
return
}
}()
}
}(hCli)
}
Expand Down Expand Up @@ -285,21 +289,25 @@ func (c *gRPCController) run() {
c.wg.Add(1)
go func(cli pd.Client) {
defer c.wg.Done()
var ticker = time.NewTicker(tt)
defer ticker.Stop()
for {
select {
case <-ticker.C:
for i := int64(0); i < burst; i++ {
err := c.Unary(c.ctx, cli)
if err != nil {
log.Error("meet error when doing gRPC request", zap.String("case", c.Name()), zap.Error(err))
c.wg.Add(int(burst))
for i := int64(0); i < burst; i++ {
go func() {
defer c.wg.Done()
var ticker = time.NewTicker(tt)
defer ticker.Stop()
for {
select {
case <-ticker.C:
err := c.Unary(c.ctx, cli)
if err != nil {
log.Error("meet erorr when doing gRPC request", zap.String("case", c.Name()), zap.Error(err))
}
case <-c.ctx.Done():
log.Info("Got signal to exit running gRPC case")
return
}
}
case <-c.ctx.Done():
log.Info("Got signal to exit running gRPC case")
return
}
}()
}
}(cli)
}
Expand Down Expand Up @@ -355,21 +363,25 @@ func (c *etcdController) run() {
c.wg.Add(1)
go func(cli *clientv3.Client) {
defer c.wg.Done()
var ticker = time.NewTicker(tt)
defer ticker.Stop()
for {
select {
case <-ticker.C:
for i := int64(0); i < burst; i++ {
err := c.Unary(c.ctx, cli)
if err != nil {
log.Error("meet error when doing etcd request", zap.String("case", c.Name()), zap.Error(err))
c.wg.Add(int(burst))
for i := int64(0); i < burst; i++ {
go func() {
defer c.wg.Done()
var ticker = time.NewTicker(tt)
defer ticker.Stop()
for {
select {
case <-ticker.C:
err := c.Unary(c.ctx, cli)
if err != nil {
log.Error("meet erorr when doing etcd request", zap.String("case", c.Name()), zap.Error(err))
}
case <-c.ctx.Done():
log.Info("Got signal to exit running etcd case")
return
}
}
case <-c.ctx.Done():
log.Info("Got signal to exit running etcd case")
return
}
}()
}
}(cli)
}
Expand Down

0 comments on commit 2851db2

Please sign in to comment.