Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Reuse the same http.Transport for better connection pooling.

Burcu Dogan84d1d3814b5c
diff --git a/boomer/run.go b/boomer/run.go
index a6cb1c5..c15d270 100644
--- a/boomer/run.go
+++ b/boomer/run.go
@@ -23,6 +23,10 @@ import (
"time"
)
+// client is the http.Client that will be used to make all requests
+// to the destination.
+var client *http.Client
+
// Run makes all the requests, prints the summary. It blocks until
// all work is done.
func (b *Boomer) Run() {
@@ -42,18 +46,6 @@ func (b *Boomer) Run() {
}
func (b *Boomer) worker(wg *sync.WaitGroup, ch chan *http.Request, readAll bool) {
- tr := &http.Transport{
- TLSClientConfig: &tls.Config{
- InsecureSkipVerify: b.AllowInsecure,
- },
- DisableCompression: b.DisableCompression,
- DisableKeepAlives: b.DisableKeepAlives,
- // TODO(jbd): Add dial timeout.
- TLSHandshakeTimeout: time.Duration(b.Timeout) * time.Millisecond,
- Proxy: http.ProxyURL(b.ProxyAddr),
- }
-
- client := &http.Client{Transport: tr}
for req := range ch {
s := time.Now()
@@ -86,6 +78,18 @@ func (b *Boomer) worker(wg *sync.WaitGroup, ch chan *http.Request, readAll bool)
}
func (b *Boomer) run() {
+ tr := &http.Transport{
+ TLSClientConfig: &tls.Config{
+ InsecureSkipVerify: b.AllowInsecure,
+ },
+ DisableCompression: b.DisableCompression,
+ DisableKeepAlives: b.DisableKeepAlives,
+ // TODO(jbd): Add dial timeout.
+ TLSHandshakeTimeout: time.Duration(b.Timeout) * time.Millisecond,
+ Proxy: http.ProxyURL(b.ProxyAddr),
+ }
+ client = &http.Client{Transport: tr}
+
var wg sync.WaitGroup
wg.Add(b.N)