Skip to content

Commit 8f384ff

Browse files
authored
Merge pull request #676 from loadimpact/feature/disable-keep-alive-vu
Adding no-vu-connection-reuse option
2 parents d2f207b + c4489c7 commit 8f384ff

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

cmd/options.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func optionFlagSet() *pflag.FlagSet {
5959
flags.String("http-debug", "", "log all HTTP requests and responses. Excludes body by default. To include body use '---http-debug=full'")
6060
flags.Lookup("http-debug").NoOptDefVal = "headers"
6161
flags.Bool("insecure-skip-tls-verify", false, "skip verification of TLS certificates")
62-
flags.Bool("no-connection-reuse", false, "don't reuse connections between iterations")
62+
flags.Bool("no-connection-reuse", false, "disable keep-alive connections")
63+
flags.Bool("no-vu-connection-reuse", false, "don't reuse connections between iterations")
6364
flags.BoolP("throw", "w", false, "throw warnings (like failed http requests) as errors")
6465
flags.StringSlice("blacklist-ip", nil, "blacklist an `ip range` from being called")
6566
flags.StringSlice("summary-trend-stats", nil, "define `stats` for trend metrics (response times), one or more as 'avg,p(95),...'")
@@ -83,6 +84,7 @@ func getOptions(flags *pflag.FlagSet) (lib.Options, error) {
8384
HttpDebug: getNullString(flags, "http-debug"),
8485
InsecureSkipTLSVerify: getNullBool(flags, "insecure-skip-tls-verify"),
8586
NoConnectionReuse: getNullBool(flags, "no-connection-reuse"),
87+
NoVUConnectionReuse: getNullBool(flags, "no-vu-connection-reuse"),
8688
Throw: getNullBool(flags, "throw"),
8789

8890
// Default values for options without CLI flags:

core/engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ func TestSentReceivedMetrics(t *testing.T) {
557557
VUsMax: null.IntFrom(tc.VUs),
558558
Hosts: tb.Dialer.Hosts,
559559
InsecureSkipTLSVerify: null.BoolFrom(true),
560-
NoConnectionReuse: null.BoolFrom(noConnReuse),
560+
NoVUConnectionReuse: null.BoolFrom(noConnReuse),
561561
}
562562

563563
r.SetOptions(options)

js/runner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func (r *Runner) newVU() (*VU, error) {
161161
TLSClientConfig: tlsConfig,
162162
DialContext: dialer.DialContext,
163163
DisableCompression: true,
164+
DisableKeepAlives: r.Bundle.Options.NoConnectionReuse.Bool,
164165
}
165166
_ = http2.ConfigureTransport(transport)
166167

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

384-
if u.Runner.Bundle.Options.NoConnectionReuse.Bool {
385+
if u.Runner.Bundle.Options.NoVUConnectionReuse.Bool {
385386
u.HTTPTransport.CloseIdleConnections()
386387
}
387388

lib/options.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,13 @@ type Options struct {
234234
// Hosts overrides dns entries for given hosts
235235
Hosts map[string]net.IP `json:"hosts" envconfig:"hosts"`
236236

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

242245
// These values are for third party collectors' benefit.
243246
// Can't be set through env vars.
@@ -336,6 +339,9 @@ func (o Options) Apply(opts Options) Options {
336339
if opts.NoConnectionReuse.Valid {
337340
o.NoConnectionReuse = opts.NoConnectionReuse
338341
}
342+
if opts.NoVUConnectionReuse.Valid {
343+
o.NoVUConnectionReuse = opts.NoVUConnectionReuse
344+
}
339345
if opts.External != nil {
340346
o.External = opts.External
341347
}

lib/options_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,11 @@ func TestOptions(t *testing.T) {
267267
assert.True(t, opts.NoConnectionReuse.Valid)
268268
assert.True(t, opts.NoConnectionReuse.Bool)
269269
})
270-
270+
t.Run("NoVUConnectionReuse", func(t *testing.T) {
271+
opts := Options{}.Apply(Options{NoVUConnectionReuse: null.BoolFrom(true)})
272+
assert.True(t, opts.NoVUConnectionReuse.Valid)
273+
assert.True(t, opts.NoVUConnectionReuse.Bool)
274+
})
271275
t.Run("BlacklistIPs", func(t *testing.T) {
272276
opts := Options{}.Apply(Options{
273277
BlacklistIPs: []*net.IPNet{{
@@ -413,6 +417,11 @@ func TestOptionsEnv(t *testing.T) {
413417
"true": null.BoolFrom(true),
414418
"false": null.BoolFrom(false),
415419
},
420+
{"NoVUConnectionReuse", "K6_NO_VU_CONNECTION_REUSE"}: {
421+
"": null.Bool{},
422+
"true": null.BoolFrom(true),
423+
"false": null.BoolFrom(false),
424+
},
416425
{"UserAgent", "K6_USER_AGENT"}: {
417426
"": null.String{},
418427
"Hi!": null.StringFrom("Hi!"),

release notes/upcoming.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ TODO: Intro
22

33
## New Features!
44

5+
* New option `--no-vu-connection-reuse` that let's users close the connections between iterations of a VU. (#676)
6+
57
### Category: Title (#533)
68

79
Description of feature.
@@ -13,4 +15,7 @@ Description of feature.
1315

1416
## Bugs fixed!
1517

16-
* Category: description of bug. (#PR)
18+
* Category: description of bug. (#PR)
19+
20+
## Breaking Changes
21+
* 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)

0 commit comments

Comments
 (0)