Skip to content

Commit

Permalink
bombardier: add option to disable keep-alive connections
Browse files Browse the repository at this point in the history
There's no explicit knob for fasthttp, so users will have to resort to
setting the header manually.
  • Loading branch information
codesenberg committed Oct 4, 2020
1 parent 5e387c2 commit c19a3b4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 43 deletions.
76 changes: 41 additions & 35 deletions args_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ type kingpinParser struct {

url string

numReqs *nullableUint64
duration *nullableDuration
headers *headersList
numConns uint64
timeout time.Duration
latencies bool
insecure bool
method string
body string
bodyFilePath string
stream bool
certPath string
keyPath string
rate *nullableUint64
clientType clientTyp
numReqs *nullableUint64
duration *nullableDuration
headers *headersList
numConns uint64
timeout time.Duration
latencies bool
insecure bool
disableKeepAlives bool
method string
body string
bodyFilePath string
stream bool
certPath string
keyPath string
rate *nullableUint64
clientType clientTyp

printSpec *nullableString
noPrint bool
Expand Down Expand Up @@ -108,6 +109,10 @@ func newKingpinParser() argsParser {
" chain and host name").
Short('k').
BoolVar(&kparser.insecure)
app.Flag("disableKeepAlives",
"Disable HTTP keep-alive. For fasthttp use -H 'Connection: close'").
Short('a').
BoolVar(&kparser.disableKeepAlives)

app.Flag("header", "HTTP headers to use(can be repeated)").
PlaceHolder("\"K: V\"").
Expand Down Expand Up @@ -208,26 +213,27 @@ func (k *kingpinParser) parse(args []string) (config, error) {
return emptyConf, err
}
return config{
numConns: k.numConns,
numReqs: k.numReqs.val,
duration: k.duration.val,
url: url,
headers: k.headers,
timeout: k.timeout,
method: k.method,
body: k.body,
bodyFilePath: k.bodyFilePath,
stream: k.stream,
keyPath: k.keyPath,
certPath: k.certPath,
printLatencies: k.latencies,
insecure: k.insecure,
rate: k.rate.val,
clientType: k.clientType,
printIntro: pi,
printProgress: pp,
printResult: pr,
format: format,
numConns: k.numConns,
numReqs: k.numReqs.val,
duration: k.duration.val,
url: url,
headers: k.headers,
timeout: k.timeout,
method: k.method,
body: k.body,
bodyFilePath: k.bodyFilePath,
stream: k.stream,
keyPath: k.keyPath,
certPath: k.certPath,
printLatencies: k.latencies,
insecure: k.insecure,
disableKeepAlives: k.disableKeepAlives,
rate: k.rate.val,
clientType: k.clientType,
printIntro: pi,
printProgress: pp,
printResult: pr,
format: format,
}, nil
}

Expand Down
11 changes: 6 additions & 5 deletions bombardier.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/cheggaaa/pb"
fhist "github.com/codesenberg/concurrent/float64/histogram"
uhist "github.com/codesenberg/concurrent/uint64/histogram"
"github.com/satori/go.uuid"
uuid "github.com/satori/go.uuid"
)

type bombardier struct {
Expand Down Expand Up @@ -127,10 +127,11 @@ func newBombardier(c config) (*bombardier, error) {
}

cc := &clientOpts{
HTTP2: false,
maxConns: c.numConns,
timeout: c.timeout,
tlsConfig: tlsConfig,
HTTP2: false,
maxConns: c.numConns,
timeout: c.timeout,
tlsConfig: tlsConfig,
disableKeepAlives: c.disableKeepAlives,

headers: c.headers,
url: c.url,
Expand Down
8 changes: 5 additions & 3 deletions clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ type bodyStreamProducer func() (io.ReadCloser, error)
type clientOpts struct {
HTTP2 bool

maxConns uint64
timeout time.Duration
tlsConfig *tls.Config
maxConns uint64
timeout time.Duration
tlsConfig *tls.Config
disableKeepAlives bool

headers *headersList
url, method string
Expand Down Expand Up @@ -129,6 +130,7 @@ func newHTTPClient(opts *clientOpts) client {
tr := &http.Transport{
TLSClientConfig: opts.tlsConfig,
MaxIdleConnsPerHost: int(opts.maxConns),
DisableKeepAlives: opts.disableKeepAlives,
}
tr.DialContext = httpDialContextFunc(opts.bytesRead, opts.bytesWritten)
if opts.HTTP2 {
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type config struct {
numConns uint64
numReqs *uint64
disableKeepAlives bool
duration *time.Duration
url, method, certPath, keyPath string
body, bodyFilePath string
Expand Down

0 comments on commit c19a3b4

Please sign in to comment.