Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

refactored trace implementation and add -more flag

Ronak Jain86bc95e12416
diff --git a/hey.go b/hey.go
index ff3f384..faaac42 100644
--- a/hey.go
+++ b/hey.go
@@ -67,8 +67,9 @@ var (
disableCompression = flag.Bool("disable-compression", false, "")
disableKeepAlives = flag.Bool("disable-keepalive", false, "")
- enableTrace = flag.Bool("http-trace", false, "")
proxyAddr = flag.String("x", "", "")
+
+ enableTrace = flag.Bool("more", false, "")
)
var usage = `Usage: hey [options...] <url>
@@ -100,7 +101,7 @@ Options:
-cpus Number of used cpu cores.
(default for current machine is %d cores)
-host HTTP Host header.
- -http-trace Enable http trace detailed info on various events during request (Experimental)
+ -more Provides information on DNS lookup, dialup, request and response timings.
`
func main() {
diff --git a/requester/print.go b/requester/print.go
index 5fd9e3f..3e9af38 100644
--- a/requester/print.go
+++ b/requester/print.go
@@ -32,6 +32,7 @@ type report struct {
average float64
rps float64
+ trace bool //if trace is set, the following fields will be filled
avgConn float64
avgDns float64
avgReq float64
@@ -40,7 +41,6 @@ type report struct {
results chan *result
total time.Duration
- trace bool
errorDist map[string]int
statusCodeDist map[int]int
diff --git a/requester/requester.go b/requester/requester.go
index ee60658..7bdea65 100644
--- a/requester/requester.go
+++ b/requester/requester.go
@@ -108,33 +108,31 @@ func (b *Work) makeRequest(c *http.Client) {
s := time.Now()
var size int64
var code int
- var dnsDuration, connDuration, resDuration, reqDuration, delayTime time.Duration
+ var dnsStart, connStart, resStart, reqStart, delayStart time.Time
+ var dnsDuration, connDuration, resDuration, reqDuration, delayDuration time.Duration
req := cloneRequest(b.Request, b.RequestBody)
if b.EnableTrace {
trace := &httptrace.ClientTrace{
DNSStart: func(info httptrace.DNSStartInfo) {
- dnsDuration = time.Now().Sub(s)
+ dnsStart = time.Now()
},
DNSDone: func(dnsInfo httptrace.DNSDoneInfo) {
- t := time.Now().Sub(s)
- dnsDuration = time.Duration(t.Nanoseconds() - dnsDuration.Nanoseconds())
+ dnsDuration = time.Now().Sub(dnsStart)
},
GetConn: func(h string) {
- connDuration = time.Now().Sub(s)
+ connStart = time.Now()
},
GotConn: func(connInfo httptrace.GotConnInfo) {
- t := time.Now().Sub(s)
- reqDuration = t
- connDuration = time.Duration(t.Nanoseconds() - connDuration.Nanoseconds())
+ connDuration = time.Now().Sub(connStart)
+ reqStart = time.Now()
},
WroteRequest: func(w httptrace.WroteRequestInfo) {
- t := time.Now().Sub(s)
- delayTime = t
- reqDuration = time.Duration(t.Nanoseconds() - reqDuration.Nanoseconds())
+ reqDuration = time.Now().Sub(reqStart)
+ delayStart = time.Now()
},
GotFirstResponseByte: func() {
- resDuration = time.Now().Sub(s)
- delayTime = time.Duration(resDuration.Nanoseconds() - delayTime.Nanoseconds())
+ delayDuration = time.Now().Sub(delayStart)
+ resStart = time.Now()
},
}
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
@@ -146,8 +144,11 @@ func (b *Work) makeRequest(c *http.Client) {
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}
- finish := time.Now().Sub(s)
- resDuration = time.Duration(finish.Nanoseconds() - resDuration.Nanoseconds())
+ t := time.Now()
+ if b.EnableTrace {
+ resDuration = t.Sub(resStart)
+ }
+ finish := t.Sub(s)
b.results <- &result{
statusCode: code,
duration: finish,
@@ -157,7 +158,7 @@ func (b *Work) makeRequest(c *http.Client) {
dnsDuration: dnsDuration,
reqDuration: reqDuration,
resDuration: resDuration,
- delayDuration: delayTime,
+ delayDuration: delayDuration,
}
}