Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func optionFlagSet() *pflag.FlagSet {
flags.String("http-debug", "", "log all HTTP requests and responses. Excludes body by default. To include body use '---http-debug=full'")
flags.Lookup("http-debug").NoOptDefVal = "headers"
flags.Bool("insecure-skip-tls-verify", false, "skip verification of TLS certificates")
flags.Bool("no-connection-reuse", false, "don't reuse connections between iterations")
flags.Bool("no-connection-reuse", false, "disable keep-alive connections")
flags.Bool("no-vu-connection-reuse", false, "don't reuse connections between iterations")
flags.BoolP("throw", "w", false, "throw warnings (like failed http requests) as errors")
flags.StringSlice("blacklist-ip", nil, "blacklist an `ip range` from being called")
flags.StringSlice("summary-trend-stats", nil, "define `stats` for trend metrics (response times), one or more as 'avg,p(95),...'")
Expand All @@ -83,6 +84,7 @@ func getOptions(flags *pflag.FlagSet) (lib.Options, error) {
HttpDebug: getNullString(flags, "http-debug"),
InsecureSkipTLSVerify: getNullBool(flags, "insecure-skip-tls-verify"),
NoConnectionReuse: getNullBool(flags, "no-connection-reuse"),
NoVUConnectionReuse: getNullBool(flags, "no-vu-connection-reuse"),
Throw: getNullBool(flags, "throw"),

// Default values for options without CLI flags:
Expand Down
2 changes: 1 addition & 1 deletion core/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func TestSentReceivedMetrics(t *testing.T) {
VUsMax: null.IntFrom(tc.VUs),
Hosts: tb.Dialer.Hosts,
InsecureSkipTLSVerify: null.BoolFrom(true),
NoConnectionReuse: null.BoolFrom(noConnReuse),
NoVUConnectionReuse: null.BoolFrom(noConnReuse),
}

r.SetOptions(options)
Expand Down
3 changes: 2 additions & 1 deletion js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func (r *Runner) newVU() (*VU, error) {
TLSClientConfig: tlsConfig,
DialContext: dialer.DialContext,
DisableCompression: true,
DisableKeepAlives: r.Bundle.Options.NoConnectionReuse.Bool,
}
_ = http2.ConfigureTransport(transport)

Expand Down Expand Up @@ -381,7 +382,7 @@ func (u *VU) runFn(ctx context.Context, fn goja.Callable, args ...goja.Value) (g
}
sampleTags := stats.IntoSampleTags(&tags)

if u.Runner.Bundle.Options.NoConnectionReuse.Bool {
if u.Runner.Bundle.Options.NoVUConnectionReuse.Bool {
u.HTTPTransport.CloseIdleConnections()
}

Expand Down
8 changes: 7 additions & 1 deletion lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,13 @@ type Options struct {
// Hosts overrides dns entries for given hosts
Hosts map[string]net.IP `json:"hosts" envconfig:"hosts"`

// Disable keep-alive connections
NoConnectionReuse null.Bool `json:"noConnectionReuse" envconfig:"no_connection_reuse"`

// Do not reuse connections between VU iterations. This gives more realistic results (depending
// on what you're looking for), but you need to raise various kernel limits or you'll get
// errors about running out of file handles or sockets, or being unable to bind addresses.
NoConnectionReuse null.Bool `json:"noConnectionReuse" envconfig:"no_connection_reuse"`
NoVUConnectionReuse null.Bool `json:"noVUConnectionReuse" envconfig:"no_vu_connection_reuse"`

// These values are for third party collectors' benefit.
// Can't be set through env vars.
Expand Down Expand Up @@ -336,6 +339,9 @@ func (o Options) Apply(opts Options) Options {
if opts.NoConnectionReuse.Valid {
o.NoConnectionReuse = opts.NoConnectionReuse
}
if opts.NoVUConnectionReuse.Valid {
o.NoVUConnectionReuse = opts.NoVUConnectionReuse
}
if opts.External != nil {
o.External = opts.External
}
Expand Down
11 changes: 10 additions & 1 deletion lib/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ func TestOptions(t *testing.T) {
assert.True(t, opts.NoConnectionReuse.Valid)
assert.True(t, opts.NoConnectionReuse.Bool)
})

t.Run("NoVUConnectionReuse", func(t *testing.T) {
opts := Options{}.Apply(Options{NoVUConnectionReuse: null.BoolFrom(true)})
assert.True(t, opts.NoVUConnectionReuse.Valid)
assert.True(t, opts.NoVUConnectionReuse.Bool)
})
t.Run("BlacklistIPs", func(t *testing.T) {
opts := Options{}.Apply(Options{
BlacklistIPs: []*net.IPNet{{
Expand Down Expand Up @@ -413,6 +417,11 @@ func TestOptionsEnv(t *testing.T) {
"true": null.BoolFrom(true),
"false": null.BoolFrom(false),
},
{"NoVUConnectionReuse", "K6_NO_VU_CONNECTION_REUSE"}: {
"": null.Bool{},
"true": null.BoolFrom(true),
"false": null.BoolFrom(false),
},
{"UserAgent", "K6_USER_AGENT"}: {
"": null.String{},
"Hi!": null.StringFrom("Hi!"),
Expand Down
7 changes: 6 additions & 1 deletion release notes/upcoming.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ TODO: Intro

## New Features!

* New option `--no-vu-connection-reuse` that let's users close the connections between iterations of a VU. (#676)

### Category: Title (#533)

Description of feature.
Expand All @@ -13,4 +15,7 @@ Description of feature.

## Bugs fixed!

* Category: description of bug. (#PR)
* Category: description of bug. (#PR)

## Breaking Changes
* The `--no-connection-reuse` option has been re-purposed and now disables keep-alive connections globally. The newly added `--no-vu-connection-reuse` option does what was previously done by `--no-connection-reuse` - it closes any open connections between iterations of a VU, but allows for reusing them inside of a single iteration. (#676)