stress

package
v0.19.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	MaximumDuration: 120 * time.Second,
	MinimumDuration: 1 * time.Second,
	PrintErrLogs:    false,
	PrintLogs:       false,
	NumberOfTables:  100,
	TableNamePrefix: "stress_t",
	InsertInterval:  10 * time.Microsecond,
	DeleteInterval:  15 * time.Microsecond,
	SelectInterval:  2 * time.Microsecond,
	SelectLimit:     500,
	MaxClient:       10,
	AllowFailure:    false,
}

DefaultConfig is the default configuration used by the stresser.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaximumDuration during which each client can stress the cluster.
	MaximumDuration time.Duration

	// MinimumDuration during which each client must stress the cluster.
	MinimumDuration time.Duration

	// PrintErrLogs enables or disables the rendering of MySQL error logs.
	PrintErrLogs bool

	// PrintLogs enables or disables the rendering of Stresser logs.
	PrintLogs bool

	// NumberOfTables to create in the cluster.
	NumberOfTables int

	// TableNamePrefix defines which prefix will be used for name of the auto-generated tables.
	TableNamePrefix string

	// InsertInterval defines at which interval each insert queries should be sent.
	InsertInterval time.Duration

	// DeleteInterval defines at which interval each delete queries should be sent.
	DeleteInterval time.Duration

	// SelectInterval defines at which interval each select queries should be sent.
	SelectInterval time.Duration

	// SelectLimit defines the maximum number of row select queries can query at once.
	SelectLimit int

	// ConnParams is the mysql.ConnParams that should be use to create new clients.
	ConnParams *mysql.ConnParams

	// MaxClient is the maximum number of concurrent client stressing the cluster.
	MaxClient int

	// AllowFailure determines whether failing queries are allowed or not.
	// All queries that fail while this setting is set to true will not be counted
	// by Stresser.Stop's assertion.
	AllowFailure bool
}

Config contains all of the Stresser configuration.

type Stresser

type Stresser struct {
	// contains filtered or unexported fields
}

Stresser is responsible for stressing a Vitess cluster based on a given Config. Stressing a Vitess cluster is achieved by spawning several clients that continuously send queries to the cluster.

The Stresser uses SELECT, INSERT and DELETE statements to stress the cluster. Queries are made against tables that are generated when calling Stresser.Start(). For each query, we keep its status (failed or succeeded) and at the end of the stress, when calling Stresser.Stop() or Stresser.StopAfter(), we assert that all queries have succeeded, otherwise the Stresser will fail the test.

This behavior can be changed by the use of Stresser.AllowFailure(bool) and the AllowFailure field of Config.

Below is an a sample usage of the Stresser:

// copy the DefaultConfig and set your own mysql.ConnParams
cfg := stress.DefaultConfig
cfg.ConnParams = &mysql.ConnParams{Port: 8888, Host: "localhost", DbName: "ks"}
s := stress.New(t, cfg).Start()

// your end to end test here

s.Stop() // stop the Stresser and assert its results

func New

func New(t *testing.T, cfg Config) *Stresser

New creates a new Stresser based on the given Config.

func (*Stresser) AllowFailure

func (s *Stresser) AllowFailure(allow bool)

AllowFailure will set the AllowFailure setting to the given value. Allowing failure means that all incoming queries that fail will be counted in result's QPS and total queries, however they will not be marked as "meaningful failure". Meaningful failures represent the failures that must fail the current test.

func (*Stresser) SetConn

func (s *Stresser) SetConn(conn *mysql.ConnParams) *Stresser

SetConn allows us to change the mysql.ConnParams of a Stresser at runtime. Setting a new mysql.ConnParams will automatically create new MySQL client using the new configuration.

func (*Stresser) Start

func (s *Stresser) Start() *Stresser

Start stressing the Vitess cluster. This method will start by creating the MySQL tables in the Vitess cluster based on the maximum number of table set through Config.NumberOfTables. The method will then start a goroutine that will spawn one or more clients. These clients will be responsible for stressing the cluster until Config.MaximumDuration is reached, or until Stresser.Stop() or Stresser.StopAfter() are called.

This method returns a pointer to its Stresser to allow chained function call, like:

s := stress.New(t, cfg).Start()
s.Stop()

func (*Stresser) Stop

func (s *Stresser) Stop()

Stop the Stresser immediately once Config.MinimumDuration is reached. To override Config.MinimumDuration, one can call Stresser.StopAfter with a value of 0. Once the Stresser has stopped, the function asserts that all results are successful, and then prints them to the standard output.

func (*Stresser) StopAfter

func (s *Stresser) StopAfter(after time.Duration)

StopAfter stops the Stresser after the given duration. The function will then assert that all the results are successful, and finally prints them to the standard output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL