(caller rpcCallFunc, start startFunc, stop stopFunc, bf stats.Features, s *stats.Stats, mode string)
| 549 | } |
| 550 | |
| 551 | func runBenchmark(caller rpcCallFunc, start startFunc, stop stopFunc, bf stats.Features, s *stats.Stats, mode string) { |
| 552 | // if SleepBetweenRPCs > 0 we skip the warmup because otherwise |
| 553 | // we are going to send a set of simultaneous requests on every connection, |
| 554 | // which is something we are trying to avoid when using SleepBetweenRPCs. |
| 555 | if bf.SleepBetweenRPCs == 0 { |
| 556 | // Warm up connections. |
| 557 | for i := 0; i < warmupCallCount; i++ { |
| 558 | for cn := 0; cn < bf.Connections; cn++ { |
| 559 | caller(cn, 0) |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | // Run benchmark. |
| 565 | start(mode, bf) |
| 566 | var wg sync.WaitGroup |
| 567 | wg.Add(bf.Connections * bf.MaxConcurrentCalls) |
| 568 | bmEnd := time.Now().Add(bf.BenchTime) |
| 569 | maxSleep := int(bf.SleepBetweenRPCs) |
| 570 | var count uint64 |
| 571 | for cn := 0; cn < bf.Connections; cn++ { |
| 572 | for pos := 0; pos < bf.MaxConcurrentCalls; pos++ { |
| 573 | go func(cn, pos int) { |
| 574 | defer wg.Done() |
| 575 | for { |
| 576 | if maxSleep > 0 { |
| 577 | time.Sleep(time.Duration(rand.IntN(maxSleep))) |
| 578 | } |
| 579 | t := time.Now() |
| 580 | if t.After(bmEnd) { |
| 581 | return |
| 582 | } |
| 583 | start := time.Now() |
| 584 | caller(cn, pos) |
| 585 | elapse := time.Since(start) |
| 586 | atomic.AddUint64(&count, 1) |
| 587 | s.AddDuration(elapse) |
| 588 | } |
| 589 | }(cn, pos) |
| 590 | } |
| 591 | } |
| 592 | wg.Wait() |
| 593 | stop(count) |
| 594 | } |
| 595 | |
| 596 | // benchOpts represents all configurable options available while running this |
| 597 | // benchmark. This is built from the values passed as flags. |
no test coverage detected