Skip to content

Commit

Permalink
Fix performance impacting bug.
Browse files Browse the repository at this point in the history
The http request body wasn't being fully read nor correctly
closed. Performance increased markedly after change.
  • Loading branch information
youngkin committed Sep 16, 2020
1 parent cdc8113 commit f1fb8f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions internal/requestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"bytes"
"context"
"crypto/tls"
"io"
"io/ioutil"
"net/http"
"net/http/httptrace"
"net/url"
Expand Down Expand Up @@ -94,9 +96,6 @@ func (r Requestor) ProcessRqst(ep api.Endpoint, numRqsts int, rqstRate int) {
for i := 0; i < numRqsts; i++ {
start := time.Now()
resp, err := client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
switch e := err.(type) {
case *url.Error:
Expand All @@ -108,6 +107,10 @@ func (r Requestor) ProcessRqst(ep api.Endpoint, numRqsts int, rqstRate int) {
return
}
}

io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()

select {
case <-r.Ctx.Done():
log.Debug().Msg("Requestor cancelled or the run duration expired, exiting")
Expand Down
8 changes: 4 additions & 4 deletions testdata/threeEPs33Pct.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"RqstRate": 1000,
"MaxConcurrentRqsts": 200,
"RunDuration": "10s",
"NumRequests": 0,
"RqstRate": 0,
"MaxConcurrentRqsts": 50,
"RunDuration": "0s",
"NumRequests": 2000,
"OutputType": "JSON",
"Endpoints": [
{
Expand Down

0 comments on commit f1fb8f7

Please sign in to comment.