Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTTP/3 (QUIC) #272

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
bin/
bin/
vendor/
.idea/

hey
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tool at [tarekziade/boom](https://github.com/tarekziade/boom). Using the same na
where binary name conflicts created confusion.
To preserve the name for its original owner, we renamed this project to hey.

## Installation
## ~~Installation~~ Build it on your own if you want to use this fork

* Linux 64-bit: https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
* Mac 64-bit: https://hey-release.s3.us-east-2.amazonaws.com/hey_darwin_amd64
Expand All @@ -24,7 +24,8 @@ macOS:

hey runs provided number of requests in the provided concurrency level and prints stats.

It also supports HTTP2 endpoints.
~~It also supports HTTP2 endpoints.~~
**It now supports HTTP/3 (QUIC) endpoints**

```
Usage: hey [options...] <url>
Expand Down Expand Up @@ -52,6 +53,7 @@ Options:
-a Basic authentication, username:password.
-x HTTP Proxy address as host:port.
-h2 Enable HTTP/2.
-h3 Enable HTTP/3 (QUIC).

-host HTTP Host header.

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/rakyll/hey

require (
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb
golang.org/x/text v0.3.2 // indirect
github.com/lucas-clemente/quic-go v0.25.0
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
)

go 1.13
284 changes: 281 additions & 3 deletions go.sum

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions hey.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var (
z = flag.Duration("z", 0, "")

h2 = flag.Bool("h2", false, "")
h3 = flag.Bool("h3", false, "")
cpus = flag.Int("cpus", runtime.GOMAXPROCS(-1), "")

disableCompression = flag.Bool("disable-compression", false, "")
Expand Down Expand Up @@ -92,6 +93,7 @@ Options:
-a Basic authentication, username:password.
-x HTTP Proxy address as host:port.
-h2 Enable HTTP/2.
-h3 Enable HTTP/3 (QUIC).

-host HTTP Host header.

Expand Down Expand Up @@ -232,6 +234,7 @@ func main() {
DisableKeepAlives: *disableKeepAlives,
DisableRedirects: *disableRedirects,
H2: *h2,
H3: *h3,
ProxyAddr: proxyURL,
Output: *output,
}
Expand Down
17 changes: 15 additions & 2 deletions requester/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"math"
"strings"
"text/template"
)
Expand All @@ -58,6 +59,16 @@ var tmplFuncMap = template.FuncMap{
"formatNumberInt": formatNumberInt,
"histogram": histogram,
"jsonify": jsonify,
"formatBytes": formatBytes,
}

// Convert size in bytes to B/KB/MB/GB/TB
func formatBytes(sizeByte int64) string {
units := []string{"B", "KB", "MB", "GB", "TB"}
unitIdx := math.Floor(math.Log(float64(sizeByte)) / math.Log(1024))
size := float64(sizeByte) / math.Pow(1024, unitIdx)
unit := units[int64(unitIdx)]
return fmt.Sprintf("%v %v", formatNumber(size), unit)
}

func jsonify(v interface{}) string {
Expand Down Expand Up @@ -101,8 +112,10 @@ Summary:
Average: {{ formatNumber .Average }} secs
Requests/sec: {{ formatNumber .Rps }}
{{ if gt .SizeTotal 0 }}
Total data: {{ .SizeTotal }} bytes
Size/request: {{ .SizeReq }} bytes{{ end }}
Total data: {{ .SizeTotal }} bytes ({{ formatBytes .SizeTotal }})
Size/request: {{ .SizeReq }} bytes ({{ formatBytes .SizeReq }})
Size/sec: {{ .SizeSec }} bytes ({{ formatBytes .SizeSec }})
{{ end }}

Response time histogram:
{{ histogram .Histogram }}
Expand Down
2 changes: 2 additions & 0 deletions requester/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (r *report) snapshot() Report {
}

snapshot.SizeReq = r.sizeTotal / int64(len(r.lats))
snapshot.SizeSec = int64(float64(r.sizeTotal) / r.total.Seconds())

copy(snapshot.Lats, r.lats)
copy(snapshot.ConnLats, r.connLats)
Expand Down Expand Up @@ -306,6 +307,7 @@ type Report struct {
SizeTotal int64
SizeReq int64
NumRes int64
SizeSec int64 // size per second

LatencyDistribution []LatencyDistribution
Histogram []Bucket
Expand Down
49 changes: 34 additions & 15 deletions requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"sync"
"time"

"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"golang.org/x/net/http2"
)

Expand Down Expand Up @@ -66,6 +68,9 @@ type Work struct {
// H2 is an option to make HTTP/2 requests
H2 bool

// H3 is an option to make HTTP/3 (QUIC) requests
H3 bool

// Timeout in seconds.
Timeout int

Expand Down Expand Up @@ -184,9 +189,8 @@ func (b *Work) makeRequest(c *http.Client) {
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
resp, err := c.Do(req)
if err == nil {
size = resp.ContentLength
code = resp.StatusCode
io.Copy(ioutil.Discard, resp.Body)
size, _ = io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}
t := now()
Expand Down Expand Up @@ -235,22 +239,37 @@ func (b *Work) runWorkers() {
var wg sync.WaitGroup
wg.Add(b.C)

tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
ServerName: b.Request.Host,
},
MaxIdleConnsPerHost: min(b.C, maxIdleConn),
DisableCompression: b.DisableCompression,
DisableKeepAlives: b.DisableKeepAlives,
Proxy: http.ProxyURL(b.ProxyAddr),
tlsConf := &tls.Config{
InsecureSkipVerify: true,
ServerName: b.Request.Host,
}
if b.H2 {
http2.ConfigureTransport(tr)

var client *http.Client
if b.H3 {
client = &http.Client{
Transport: &http3.RoundTripper{
TLSClientConfig: tlsConf,
QuicConfig: &quic.Config{KeepAlive: !b.DisableKeepAlives},
DisableCompression: b.DisableCompression,
},
Timeout: time.Duration(b.Timeout) * time.Second,
}

} else {
tr.TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper)
tr := &http.Transport{
TLSClientConfig: tlsConf,
MaxIdleConnsPerHost: min(b.C, maxIdleConn),
DisableCompression: b.DisableCompression,
DisableKeepAlives: b.DisableKeepAlives,
Proxy: http.ProxyURL(b.ProxyAddr),
}
if b.H2 {
http2.ConfigureTransport(tr)
} else {
tr.TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper)
}
client = &http.Client{Transport: tr, Timeout: time.Duration(b.Timeout) * time.Second}
}
client := &http.Client{Transport: tr, Timeout: time.Duration(b.Timeout) * time.Second}

// Ignore the case where b.N % b.C != 0.
for i := 0; i < b.C; i++ {
Expand Down
3 changes: 0 additions & 3 deletions vendor/golang.org/x/net/AUTHORS

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/golang.org/x/net/CONTRIBUTORS

This file was deleted.

27 changes: 0 additions & 27 deletions vendor/golang.org/x/net/LICENSE

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/golang.org/x/net/PATENTS

This file was deleted.

50 changes: 0 additions & 50 deletions vendor/golang.org/x/net/http/httpguts/guts.go

This file was deleted.

Loading