Skip to content

Commit

Permalink
Add a flag to disable the end-of-test summary (#807)
Browse files Browse the repository at this point in the history
This, when used in conjunction with --no-thresholds, should reduce the k6 memory usage for long-running tests. This is something like an all-or-nothing approach to #764 - even though it's not the best solution, it's pretty easy to implement and support and we can always extend it later.
  • Loading branch information
na-- authored Oct 16, 2018
1 parent a9b7585 commit a482dea
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
6 changes: 6 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func configFlagSet() *pflag.FlagSet {
flags.BoolP("linger", "l", false, "keep the API server alive past test end")
flags.Bool("no-usage-report", false, "don't send anonymous stats to the developers")
flags.Bool("no-thresholds", false, "don't run thresholds")
flags.Bool("no-summary", false, "don't show the summary at the end of the test")
flags.AddFlagSet(configFileFlagSet())
return flags
}
Expand All @@ -67,6 +68,7 @@ type Config struct {
Linger null.Bool `json:"linger" envconfig:"linger"`
NoUsageReport null.Bool `json:"noUsageReport" envconfig:"no_usage_report"`
NoThresholds null.Bool `json:"noThresholds" envconfig:"no_thresholds"`
NoSummary null.Bool `json:"noSummary" envconfig:"no_summary"`

Collectors struct {
InfluxDB influxdb.Config `json:"influxdb"`
Expand All @@ -89,6 +91,9 @@ func (c Config) Apply(cfg Config) Config {
if cfg.NoThresholds.Valid {
c.NoThresholds = cfg.NoThresholds
}
if cfg.NoSummary.Valid {
c.NoSummary = cfg.NoSummary
}
c.Collectors.InfluxDB = c.Collectors.InfluxDB.Apply(cfg.Collectors.InfluxDB)
c.Collectors.Cloud = c.Collectors.Cloud.Apply(cfg.Collectors.Cloud)
c.Collectors.Kafka = c.Collectors.Kafka.Apply(cfg.Collectors.Kafka)
Expand All @@ -111,6 +116,7 @@ func getConfig(flags *pflag.FlagSet) (Config, error) {
Linger: getNullBool(flags, "linger"),
NoUsageReport: getNullBool(flags, "no-usage-report"),
NoThresholds: getNullBool(flags, "no-thresholds"),
NoSummary: getNullBool(flags, "no-summary"),
}, nil
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ a commandline interface for interacting with it.`,
if conf.NoThresholds.Valid {
engine.NoThresholds = conf.NoThresholds.Bool
}
if conf.NoSummary.Valid {
engine.NoSummary = conf.NoSummary.Bool
}

// Create a collector and assign it to the engine if requested.
fprintf(stdout, "%s collector\r", initBar.String())
Expand Down Expand Up @@ -409,7 +412,7 @@ a commandline interface for interacting with it.`,
}

// Print the end-of-test summary.
if !quiet {
if !quiet && !conf.NoSummary.Bool {
fprintf(stdout, "\n")
ui.Summarize(stdout, "", ui.SummaryData{
Opts: conf.Options,
Expand Down
26 changes: 18 additions & 8 deletions core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Engine struct {
Options lib.Options
Collectors []lib.Collector
NoThresholds bool
NoSummary bool

logger *log.Logger

Expand Down Expand Up @@ -343,14 +344,7 @@ func (e *Engine) processThresholds(abort func()) {
}
}

func (e *Engine) processSamples(sampleCointainers []stats.SampleContainer) {
if len(sampleCointainers) == 0 {
return
}

e.MetricsLock.Lock()
defer e.MetricsLock.Unlock()

func (e *Engine) processSamplesForMetrics(sampleCointainers []stats.SampleContainer) {
for _, sampleCointainer := range sampleCointainers {
samples := sampleCointainer.GetSamples()

Expand Down Expand Up @@ -383,6 +377,22 @@ func (e *Engine) processSamples(sampleCointainers []stats.SampleContainer) {
}
}
}
}

func (e *Engine) processSamples(sampleCointainers []stats.SampleContainer) {
if len(sampleCointainers) == 0 {
return
}

// TODO: optimize this...
e.MetricsLock.Lock()
defer e.MetricsLock.Unlock()

// TODO: run this and the below code in goroutines?
if !(e.NoSummary && e.NoThresholds) {
e.processSamplesForMetrics(sampleCointainers)
}

if len(e.Collectors) > 0 {
for _, collector := range e.Collectors {
collector.Collect(sampleCointainers)
Expand Down
4 changes: 4 additions & 0 deletions release notes/upcoming.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export default function () {

Thanks to @AndriiChuzhynov for implementing this! (#766)

### New option to disable the summary at the end of a test (#729)

A new option that disables the end-of-test summary has been added. That summary is often superfluous when k6 tests are run in a distributed execution mode, or when the generated metrics are piped to an external output like InfluxDB or Load Impact Insights. The option can be enabled with the `--no-summary` CLI flag or the `K6_NO_SUMMARY` environment variable. When both it and the and the `--no-thresholds` option are enabled, k6 won't store any generated metrics in-memory, making the test execution a bit more efficient.

## UX

* Added a warning when the maximum number of VUs is more than the total number of iterations (#802)
Expand Down

0 comments on commit a482dea

Please sign in to comment.