Skip to content

Commit

Permalink
Add a duration parameter z. If specified hey sends requests until giv… (
Browse files Browse the repository at this point in the history
rakyll#75)

* Add a duration parameter z. If specified hey sends requests until given time period is passed, then stops and exits.

* Change expectations, Currently q is only upper limit and per worker.

* Update readme with new parameters.
  • Loading branch information
mdakin authored Dec 26, 2017
1 parent aae8135 commit 0e59549
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ Options:
-n Number of requests to run. Default is 200.
-c Number of requests to run concurrently. Total number of requests cannot
be smaller than the concurrency level. Default is 50.
-q Rate limit, in seconds (QPS).
-q Rate limit, in queries per second (QPS). Default is no rate limit.
-z Duration of application to send requests. When duration is reached,
application stops and exits. If duration is specified, n is ignored.
Examples: -z 10s -z 3m.
-o Output type. If none provided, a summary is printed.
"csv" is the only supported alternative. Dumps the response
metrics in comma-separated values format.
Expand All @@ -48,6 +51,7 @@ Options:
-disable-compression Disable compression.
-disable-keepalive Disable keep-alive, prevents re-use of TCP
connections between different HTTP requests.
-disable-redirects Disable following of HTTP redirects
-cpus Number of used cpu cores.
(default for current machine is 8 cores)
```
Expand Down
30 changes: 25 additions & 5 deletions hey.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"strings"

"github.com/rakyll/hey/requester"
"math"
"time"
)

const (
Expand All @@ -51,6 +53,7 @@ var (
n = flag.Int("n", 200, "")
q = flag.Float64("q", 0, "")
t = flag.Int("t", 20, "")
z = flag.Duration("z", 0, "")

h2 = flag.Bool("h2", false, "")
cpus = flag.Int("cpus", runtime.GOMAXPROCS(-1), "")
Expand All @@ -68,6 +71,9 @@ Options:
-c Number of requests to run concurrently. Total number of requests cannot
be smaller than the concurrency level. Default is 50.
-q Rate limit, in queries per second (QPS). Default is no rate limit.
-z Duration of application to send requests. When duration is reached,
application stops and exits. If duration is specified, n is ignored.
Examples: -z 10s -z 3m.
-o Output type. If none provided, a summary is printed.
"csv" is the only supported alternative. Dumps the response
metrics in comma-separated values format.
Expand Down Expand Up @@ -111,13 +117,21 @@ func main() {
num := *n
conc := *c
q := *q
dur := *z

if num <= 0 || conc <= 0 {
usageAndExit("-n and -c cannot be smaller than 1.")
}
if dur > 0 {
num = math.MaxInt32
if conc <= 0 {
usageAndExit("-c cannot be smaller than 1.")
}
} else {
if num <= 0 || conc <= 0 {
usageAndExit("-n and -c cannot be smaller than 1.")
}

if num < conc {
usageAndExit("-n cannot be less than -c.")
if num < conc {
usageAndExit("-n cannot be less than -c.")
}
}

url := flag.Args()[0]
Expand Down Expand Up @@ -214,6 +228,12 @@ func main() {
<-c
w.Stop()
}()
if dur > 0 {
go func() {
time.Sleep(dur)
w.Stop()
}()
}
w.Run()
}

Expand Down
6 changes: 3 additions & 3 deletions requester/requester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestN(t *testing.T) {
}
w.Run()
if count != 20 {
t.Errorf("Expected to boom 20 times, found %v", count)
t.Errorf("Expected to send 20 requests, found %v", count)
}
}

Expand All @@ -63,8 +63,8 @@ func TestQps(t *testing.T) {
}
wg.Add(1)
time.AfterFunc(time.Second, func() {
if count > 1 {
t.Errorf("Expected to work 1 times, found %v", count)
if count > 2 {
t.Errorf("Expected to work at most 2 times, found %v", count)
}
wg.Done()
})
Expand Down

0 comments on commit 0e59549

Please sign in to comment.