HTTP load generator, ApacheBench (ab) replacement
Go
Merge branch 'master' into progressBar
Ronak Jain0bbf003875dc
diff --cc requester/requester.goindex 34e2b8c,10f821e..d1adc7d--- a/requester/requester.go+++ b/requester/requester.go@@@ -16,8 -16,8 +16,9 @@@package requesterimport (+ "bytes""crypto/tls"+ "fmt""io""io/ioutil""net/http"@@@ -25,9 -25,7 +26,8 @@@"net/url""os""os/signal"- "strings""sync"+ "sync/atomic""time""golang.org/x/net/http2"@@@ -89,34 -84,21 +89,44 @@@ type Work structresults chan *result}+//Displays the progress bar and counter+func (b *Work) displayProgress(stop chan int) {+ for {+ select {+ case <-stop:+ count := int(atomic.LoadInt32(&b.progressCounter))+ fmt.Printf("\rRequests: %d/%d [%-40s]\n", count, b.N, strings.Repeat(barChar, (count*40)/b.N))+ stop <- 1+ return+ case <-time.After(time.Second / 2):+ count := int(atomic.LoadInt32(&b.progressCounter))+ fmt.Printf("\rRequests: %d/%d [%-40s]", count, b.N, strings.Repeat(barChar, (count*40)/b.N))+ }+ }+}++ const heyUA = "hey/0.0.1"+// Run makes all the requests, prints the summary. It blocks until// all work is done.func (b *Work) Run() {+ stopProgressChan := make(chan int)+ stopProgress := func() {+ stopProgressChan <- 1+ <-stopProgressChan+ }+ go b.displayProgress(stopProgressChan)+b.results = make(chan *result, b.N)+ // append hey's user agent+ ua := b.Request.UserAgent()+ if ua == "" {+ ua = heyUA+ } else {+ ua += " " + heyUA+ }+start := time.Now()c := make(chan os.Signal, 1)signal.Notify(c, os.Interrupt)