Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

feat: h2 - make HTTP2 request

xuqingfeng1812960bd730
diff --git a/boom.go b/boom.go
index b7465a8..5b840fd 100644
--- a/boom.go
+++ b/boom.go
@@ -54,10 +54,13 @@ var (
output = flag.String("o", "", "")
- c = flag.Int("c", 50, "")
- n = flag.Int("n", 200, "")
- q = flag.Int("q", 0, "")
- t = flag.Int("t", 0, "")
+ c = flag.Int("c", 50, "")
+ n = flag.Int("n", 200, "")
+ q = flag.Int("q", 0, "")
+ t = flag.Int("t", 0, "")
+
+ h2 = flag.Bool("h2", false, "")
+
cpus = flag.Int("cpus", runtime.GOMAXPROCS(-1), "")
disableCompression = flag.Bool("disable-compression", false, "")
@@ -86,6 +89,8 @@ Options:
-a Basic authentication, username:password.
-x HTTP Proxy address as host:port.
+ -h2 Make HTTP2 request.
+
-disable-compression Disable compression.
-disable-keepalive Disable keep-alive, prevents re-use of TCP
connections between different HTTP requests.
@@ -178,6 +183,7 @@ func main() {
Timeout: *t,
DisableCompression: *disableCompression,
DisableKeepAlives: *disableKeepAlives,
+ H2: *h2,
ProxyAddr: proxyURL,
Output: *output,
}).Run()
diff --git a/boomer/boomer.go b/boomer/boomer.go
index c5972d4..57448c5 100644
--- a/boomer/boomer.go
+++ b/boomer/boomer.go
@@ -17,6 +17,7 @@ package boomer
import (
"crypto/tls"
+ "golang.org/x/net/http2"
"io"
"io/ioutil"
"net/http"
@@ -47,6 +48,9 @@ type Boomer struct {
// C is the concurrency level, the number of concurrent workers to run.
C int
+ // H2 is an option to make HTTP2 requests
+ H2 bool
+
// Timeout in seconds.
Timeout int
@@ -127,6 +131,9 @@ func (b *Boomer) runWorker(n int) {
TLSHandshakeTimeout: time.Duration(b.Timeout) * time.Millisecond,
Proxy: http.ProxyURL(b.ProxyAddr),
}
+ if b.H2 {
+ http2.ConfigureTransport(tr)
+ }
client := &http.Client{Transport: tr}
for i := 0; i < n; i++ {
if b.Qps > 0 {