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 8 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
21 changes: 18 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
module github.com/rakyll/hey

// github.com/quic-go/quic-go v0.25.0
require (
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb
golang.org/x/text v0.3.2 // indirect
golang.org/x/net v0.28.0
github.com/quic-go/quic-go v0.48.2
)

go 1.13
require (
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
)

go 1.22
66 changes: 58 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,58 @@
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb h1:TR699M2v0qoKTOHxeLgp6zPqaQNs74f01a/ob9W0qko=
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
github.com/quic-go/quic-go v0.48.2 h1:wsKXZPeGWpMpCGSWqOcqpW2wZYic/8T3aqiOID0/KWE=
github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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
55 changes: 40 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/quic-go/quic-go"
"github.com/quic-go/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,43 @@ 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)
quicConf := &quic.Config{
EnableDatagrams: true}

if !b.DisableKeepAlives {
quicConf.KeepAlivePeriod = time.Duration(b.Timeout) * time.Second
}

var client *http.Client
if b.H3 {
client = &http.Client{
Transport: &http3.Transport{
TLSClientConfig: tlsConf,
QUICConfig: quicConf,
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.

Loading