Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Add a duration parameter z. If specified hey sends requests until giv… (#75)

mdakin0e5954951659
diff --git a/README.md b/README.md
index 311c2b2..917c903 100644
--- a/README.md
+++ b/README.md
@@ -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.
@@ -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)
```
diff --git a/hey.go b/hey.go
index 6b0b9a8..a065b6b 100644
--- a/hey.go
+++ b/hey.go
@@ -28,6 +28,8 @@ import (
"strings"
"github.com/rakyll/hey/requester"
+ "math"
+ "time"
)
const (
@@ -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), "")
@@ -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.
@@ -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]
@@ -214,6 +228,12 @@ func main() {
<-c
w.Stop()
}()
+ if dur > 0 {
+ go func() {
+ time.Sleep(dur)
+ w.Stop()
+ }()
+ }
w.Run()
}
diff --git a/requester/requester_test.go b/requester/requester_test.go
index d071bf4..c57647e 100644
--- a/requester/requester_test.go
+++ b/requester/requester_test.go
@@ -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)
}
}
@@ -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()
})