Skip to content

Commit

Permalink
Minor shuffle. Throttle only if we are sending somthing, remove messa…
Browse files Browse the repository at this point in the history
…ge. (rakyll#77)
  • Loading branch information
mdakin authored Dec 26, 2017
1 parent d6f8b18 commit aae8135
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion hey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}
}
Expand Down

0 comments on commit aae8135

Please sign in to comment.