Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Make n requests with c concurrency.

Burcu Dogane1ed87001e5f
diff --git a/commands/run.go b/commands/run.go
index 97bcbfd..7f37fc4 100644
--- a/commands/run.go
+++ b/commands/run.go
@@ -32,18 +32,29 @@ func (b *Boom) teardown() {
}
func (b *Boom) run() {
- var wg sync.WaitGroup
- wg.Add(b.N)
-
- for i := 0; i < b.N; i++ {
- go func() {
- b.runOneReq()
- b.bar.Increment()
- wg.Done()
- }()
- }
+ remaining := b.N
+ for {
+ if remaining < 1 {
+ break
+ }
+
+ c := b.C
+ if remaining < b.C {
+ c = remaining
+ }
- wg.Wait()
+ var wg sync.WaitGroup
+ wg.Add(c)
+ for i := 0; i < c; i++ {
+ go func() {
+ b.runOneReq()
+ b.bar.Increment()
+ wg.Done()
+ }()
+ }
+ wg.Wait()
+ remaining = remaining - c
+ }
}
func (b *Boom) runOneReq() {