From aae813562e0efd8bd4ce0302cef54a6ecc1f9e90 Mon Sep 17 00:00:00 2001 From: mdakin Date: Tue, 26 Dec 2017 15:21:40 +0100 Subject: [PATCH] Minor shuffle. Throttle only if we are sending somthing, remove message. (#77) --- hey.go | 1 - requester/requester.go | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/hey.go b/hey.go index 377066f0..6b0b9a8e 100644 --- a/hey.go +++ b/hey.go @@ -212,7 +212,6 @@ func main() { signal.Notify(c, os.Interrupt) go func() { <-c - fmt.Fprintf(os.Stderr, "\nInterrupted, stopping workers.") w.Stop() }() w.Run() diff --git a/requester/requester.go b/requester/requester.go index 4df558f8..0a7265bf 100644 --- a/requester/requester.go +++ b/requester/requester.go @@ -197,7 +197,7 @@ func (b *Work) makeRequest(c *http.Client) { func (b *Work) runWorker(client *http.Client, n int) { var throttle <-chan time.Time - if b.QPS > 0.0 { + if b.QPS > 0 { throttle = time.Tick(time.Duration(1e6/(b.QPS)) * time.Microsecond) } @@ -207,14 +207,14 @@ func (b *Work) runWorker(client *http.Client, n int) { } } for i := 0; i < n; i++ { - if b.QPS > 0 { - <-throttle - } // Check if application is stopped. Do not send into a closed channel. select { case <-b.stopCh: return default: + if b.QPS > 0 { + <-throttle + } b.makeRequest(client) } }