HTTP load generator, ApacheBench (ab) replacement
Go
Add request offset to csv (#126)
Erwin van Eyk3dd84216e7b3
diff --git a/requester/print.go b/requester/print.goindex 7bf6535..4a32e4d 100644--- a/requester/print.go+++ b/requester/print.go@@ -12,6 +12,26 @@// See the License for the specific language governing permissions and// limitations under the License.+/*+Hey supports two output formats: summary and CSV++The summary output presents a number of statistics about the requests in a+human-readable format, including:+- general statistics: requests/second, total runtime, and average, fastest, and slowest requests.+- a response time histogram.+- a percentile latency distribution.+- statistics (average, fastest, slowest) on the stages of the requests.++The comma-separated CSV format is proceeded by a header, and consists of the following columns:+1. response-time: Total time taken for request (in seconds)+2. DNS+dialup: Time taken to establish the TCP connection (in seconds)+3. DNS: Time taken to do the DNS lookup (in seconds)+4. Request-write: Time taken to write full request (in seconds)+5. Response-delay: Time taken to first byte received (in seconds)+6. Response-read: Time taken to read full response (in seconds)+7. status-code: HTTP status code of the response (e.g. 200)+8. offset: The time since the start of the benchmark when the request was started. (in seconds)+*/package requesterimport (@@ -103,7 +123,6 @@ Status code distribution:{{ range $code, $num := .StatusCodeDist }}{{ if gt (len .ErrorDist) 0 }}Error distribution:{{ range $err, $num := .ErrorDist }}[{{ $num }}] {{ $err }}{{ end }}{{ end }}`- csvTmpl = `{{ $connLats := .ConnLats }}{{ $dnsLats := .DnsLats }}{{ $dnsLats := .DnsLats }}{{ $reqLats := .ReqLats }}{{ $delayLats := .DelayLats }}{{ $resLats := .ResLats }}{{ $statusCodeLats := .StatusCodes }}-response-time,DNS+dialup,DNS,Request-write,Response-delay,Response-read,status-code{{ range $i, $v := .Lats }}-{{ formatNumber $v }},{{ formatNumber (index $connLats $i) }},{{ formatNumber (index $dnsLats $i) }},{{ formatNumber (index $reqLats $i) }},{{ formatNumber (index $delayLats $i) }},{{ formatNumber (index $resLats $i) }},{{ formatNumberInt (index $statusCodeLats $i) }}{{ end }}`+ csvTmpl = `{{ $connLats := .ConnLats }}{{ $dnsLats := .DnsLats }}{{ $dnsLats := .DnsLats }}{{ $reqLats := .ReqLats }}{{ $delayLats := .DelayLats }}{{ $resLats := .ResLats }}{{ $statusCodeLats := .StatusCodes }}{{ $offsets := .Offsets}}response-time,DNS+dialup,DNS,Request-write,Response-delay,Response-read,status-code,offset{{ range $i, $v := .Lats }}+{{ formatNumber $v }},{{ formatNumber (index $connLats $i) }},{{ formatNumber (index $dnsLats $i) }},{{ formatNumber (index $reqLats $i) }},{{ formatNumber (index $delayLats $i) }},{{ formatNumber (index $resLats $i) }},{{ formatNumberInt (index $statusCodeLats $i) }},{{ formatNumber (index $offsets $i) }}{{ end }}`)diff --git a/requester/report.go b/requester/report.goindex b310477..d281054 100644--- a/requester/report.go+++ b/requester/report.go@@ -47,6 +47,7 @@ type report struct {reqLats []float64resLats []float64delayLats []float64+ offsets []float64statusCodes []intresults chan *result@@ -101,6 +102,7 @@ func runReporter(r *report) {r.delayLats = append(r.delayLats, res.delayDuration.Seconds())r.resLats = append(r.resLats, res.resDuration.Seconds())r.statusCodes = append(r.statusCodes, res.statusCode)+ r.offsets = append(r.offsets, res.offset.Seconds())}if res.contentLength > 0 {r.sizeTotal += res.contentLength@@ -158,6 +160,7 @@ func (r *report) snapshot() Report {ReqLats: make([]float64, len(r.lats)),ResLats: make([]float64, len(r.lats)),DelayLats: make([]float64, len(r.lats)),+ Offsets: make([]float64, len(r.lats)),StatusCodes: make([]int, len(r.lats)),}@@ -174,6 +177,7 @@ func (r *report) snapshot() Report {copy(snapshot.ResLats, r.resLats)copy(snapshot.DelayLats, r.delayLats)copy(snapshot.StatusCodes, r.statusCodes)+ copy(snapshot.Offsets, r.offsets)sort.Float64s(r.lats)r.fastest = r.lats[0]@@ -292,6 +296,7 @@ type Report struct {ReqLats []float64ResLats []float64DelayLats []float64+ Offsets []float64StatusCodes []intTotal time.Durationdiff --git a/requester/requester.go b/requester/requester.goindex b60fd1d..6e6e0e9 100644--- a/requester/requester.go+++ b/requester/requester.go@@ -37,6 +37,7 @@ const maxIdleConn = 500type result struct {err errorstatusCode int+ offset time.Durationduration time.DurationconnDuration time.Duration // connection setup(DNS lookup + Dial up) durationdnsDuration time.Duration // dns lookup duration@@ -183,6 +184,7 @@ func (b *Work) makeRequest(c *http.Client) {resDuration = t - resStartfinish := t - sb.results <- &result{+ offset: s,statusCode: code,duration: finish,err: err,