Documentation
¶
Overview ¶
Package driver generates and submits the load a scenario describes.
Index ¶
- Constants
- Variables
- func BuildTemplate(jc scenario.JobClass, jobName string, cmd scenario.Command) ([]byte, error)
- type ActionRecord
- type Actions
- type ActionsOption
- type Chooser
- type DialFunc
- type JobLedger
- type Metrics
- type Pacer
- type SubmittedJob
- type Submitter
- type SubmitterOption
- type UIClients
- type UIOption
- type WSStream
Constants ¶
const ( EndpointJobsList = "jobs-list" EndpointJobDetail = "job-detail" EndpointTaskList = "task-list" EndpointWorkersList = "workers-list" )
Names of the REST endpoints a poller can hit; scenario.PollSpec.Endpoints lists them.
const ( SubJobs = ws.SubjectJobs SubWorkers = ws.SubjectWorkers SubOwnJobTasks = "own-job-tasks" SubOwnTaskLogs = "own-task-logs" )
Subscriptions a WebSocket client can ask for in scenario.WSSpec.Subscribe. SubJobs and SubWorkers are subscribed as the hub subjects of the same name.
const ActionCancelJobs = "cancel_jobs"
ActionCancelJobs is the ActionRecord.Kind of a cancel_jobs action.
const StatusUndecodable = -1
StatusUndecodable is the status key of a submission the server answered 2xx but whose body could not be read as a job id. The job may exist on the server, but the harness cannot name it, so it is not in the ledger's accepted set; the ledger and the metrics both carry this key rather than the 2xx.
Variables ¶
var StandardEndpoints = []string{EndpointJobsList, EndpointJobDetail, EndpointTaskList, EndpointWorkersList}
StandardEndpoints are the REST endpoints a poller supports.
Functions ¶
func BuildTemplate ¶
BuildTemplate returns the OpenJD YAML for one job of class jc. Step i+1 depends on step i, every step's onRun ends with scenario.KeyArg naming the task and scenario.ClassArg naming jc, and each step expands to exactly jc.TasksPerStep tasks: sqi caps a task parameter at 1024 values, so a large step splits into a Frame range and a Block range whose product is the task count.
Types ¶
type ActionRecord ¶
type ActionRecord struct {
// Kind is cancel_jobs, retry_failed, pause_queue, resume_queue or
// disable_workers.
Kind string
// At is the action's offset in the scenario; Started is when it began.
At time.Duration
Started time.Time
// Targeted is how many REST calls it set out to make, Succeeded how many
// the server accepted, and Failed how many it refused or that errored.
Targeted, Succeeded, Failed int
// Detail names the queue, or the first error.
Detail string
// JobIDs are the jobs a cancel_jobs action set out to cancel, whether or
// not the server accepted the call: one that errored may still have landed.
JobIDs []string
}
ActionRecord is what one step of a timed action did.
type Actions ¶
type Actions struct {
// contains filtered or unexported fields
}
Actions fires the scenario's timed events at their offsets from the run's start: it cancels a fraction of the jobs submitted so far, retries failed jobs, pauses or resumes a queue, disables a fraction of the workers. Each step is recorded; a call the server refuses is counted in the record, not fatal. A queue left paused is resumed by ResumePaused.
func NewActions ¶
func NewActions(c *client.Client, t target.Target, acts []scenario.Action, jobs *JobLedger, fleet *simworker.Fleet, opts ...ActionsOption) *Actions
NewActions returns Actions for acts against t. fleet may be nil; when set, disable_workers hits only workers the fleet runs.
func (*Actions) Records ¶
func (a *Actions) Records() []ActionRecord
Records returns what the actions did so far, in the order they finished.
func (*Actions) ResumePaused ¶
ResumePaused resumes every queue a pause_queue action paused and no later resume_queue action resumed, and returns their names. The runner calls it once submissions stop, before it waits for the jobs to finish: a paused queue leases nothing, so its jobs would otherwise sit until the drain timeout and read as stranded by the server.
type ActionsOption ¶
type ActionsOption func(*Actions)
ActionsOption configures NewActions.
func WithActionsRand ¶
func WithActionsRand(r *rand.Rand) ActionsOption
WithActionsRand seeds the random choice of which jobs and workers an action hits; without it a fixed seed is used.
type JobLedger ¶
type JobLedger struct {
// contains filtered or unexported fields
}
JobLedger records every submission attempt of a run, rejected ones too. It is safe for concurrent use.
func (*JobLedger) Accepted ¶
func (l *JobLedger) Accepted() []SubmittedJob
Accepted returns the accepted jobs in the order they were recorded.
func (*JobLedger) AcceptedCount ¶
AcceptedCount returns how many jobs the server accepted.
func (*JobLedger) Pick ¶
func (l *JobLedger) Pick(r Chooser) (SubmittedJob, bool)
Pick returns a uniformly chosen accepted job, or false when there is none.
func (*JobLedger) Recent ¶
func (l *JobLedger) Recent(n int) []SubmittedJob
Recent returns up to n of the most recently accepted jobs, oldest first.
func (*JobLedger) Rejected ¶
func (l *JobLedger) Rejected() []SubmittedJob
Rejected returns the attempts the server did not accept (an error status, a timeout, a dropped connection) in the order they were recorded. Each keeps its Name and Class, so a job the server created anyway can be matched to it by name.
type Metrics ¶
type Metrics struct {
// SubmitLatency is the HTTP round trip of each job submission.
SubmitLatency *measure.Histogram
// SubmitLag is how late each paced submission left the generator, measured
// against its due time. Bursts (total) have no schedule and record none.
SubmitLag *measure.Histogram
// FirstLease, TaskE2E, TerminalIngest and JobE2E are filled by the
// runner from the worker ledger and the server's task and job lists; the
// driver only declares them.
FirstLease, TaskE2E, TerminalIngest, JobE2E *measure.Histogram
// WSLag is receive time minus the event time the push payload carries.
// A push stamped after it was received (clock skew between hosts) is not
// recorded; it is counted in WSLagNegative instead.
WSLag *measure.Histogram
// WSLagNegative counts pushes whose event time was later than their
// arrival.
WSLagNegative atomic.Int64
// REST is the latency of each poller endpoint's successful calls, keyed by
// endpoint name. The set of keys is fixed by NewMetrics.
REST map[string]*measure.Histogram
// WSDrops is the number of pushes the server's sequence numbers show a
// client missed. WSEvents is every push received.
WSDrops, WSEvents atomic.Int64
// WSErrors counts failed WebSocket dials, subscriptions and broken
// connections; RESTErrors counts failed poller calls.
WSErrors, RESTErrors atomic.Int64
// contains filtered or unexported fields
}
Metrics is what the driver measures. The histograms and counters are safe for concurrent use. Use it through a pointer: it holds locks and atomics.
func NewMetrics ¶
NewMetrics returns Metrics with a latency histogram for each of endpoints and for every standard endpoint.
func (*Metrics) Status ¶
Status returns the counter of submissions answered with HTTP status code, creating it on first use.
func (*Metrics) StatusCounts ¶
StatusCounts returns a snapshot of the per-status counts.
type Pacer ¶
type Pacer struct {
// contains filtered or unexported fields
}
Pacer hands out the due times of an open-loop schedule: the n-th call to Next returns start + n/rate, whatever the clock says and however late the caller is. It never skips a slot and never sleeps, so a caller that falls behind sees due times in the past, acts at once, and records the gap as lag, so a slow server cannot lower the offered load.
A Pacer is safe for concurrent use.
type SubmittedJob ¶
type SubmittedJob struct {
// ID is the server's job id, empty when the submission was rejected.
ID string
// Name is the job's name in its template.
Name string
// Class is the scenario job class.
Class string
// SubmittedAt is when the request left the generator; AcceptedAt is when
// the 2xx answer arrived, and the zero time for a rejection.
SubmittedAt, AcceptedAt time.Time
// Status is the HTTP status, 0 for a transport error.
Status int
}
SubmittedJob is one submission attempt.
func (SubmittedJob) Accepted ¶
func (j SubmittedJob) Accepted() bool
Accepted reports whether the server took the job.
type Submitter ¶
type Submitter struct {
// contains filtered or unexported fields
}
Submitter submits the scenario's jobs to the server and records what the server answers. Every attempt lands in the ledger and in Metrics.StatusCounts: a rejection (422, 429, 503) or a transport failure is counted, never retried and never hidden.
Each job class runs on its own: a class with a rate is paced open-loop, and a class with a total is submitted as fast as the server accepts, with a bounded number in flight, until total attempts have been made, rejected ones included.
func NewSubmitter ¶
func NewSubmitter(c *client.Client, t target.Target, sc *scenario.Scenario, l *JobLedger, m *Metrics, r *rand.Rand, opts ...SubmitterOption) *Submitter
NewSubmitter returns a Submitter for sc against t. r seeds every random choice (which earlier job a dependent job waits on); a nil r uses a fixed seed.
func (*Submitter) Run ¶
Run submits until ctx ends or, for a class with a total, until that many attempts are made. It waits for every submission already sent. A rejected submission is not an error; Run fails only when the harness cannot build a template or a class names a queue the target does not have.
type SubmitterOption ¶
type SubmitterOption func(*Submitter)
SubmitterOption configures NewSubmitter.
func WithConcurrency ¶
func WithConcurrency(n int) SubmitterOption
WithConcurrency sets how many submissions a burst class keeps in flight (default 32).
func WithNamePrefix ¶
func WithNamePrefix(prefix string) SubmitterOption
WithNamePrefix puts prefix and a dash in front of every job name, so several submitters (shards) never collide: "<prefix>-<class>-<seq>".
type UIClients ¶
type UIClients struct {
// contains filtered or unexported fields
}
UIClients is the read-side load: WebSocket subscribers and REST pollers, the way browsers and scripts watch a farm. WebSocket clients speak the real protocol, drain their connection continuously, measure the lag between a push's own timestamp and its arrival, and count holes in the server's per-subject sequence numbers as drops. Failures are counted in Metrics.WSErrors and Metrics.RESTErrors, never hidden.
func NewUIClients ¶
func NewUIClients(c *client.Client, t target.Target, spec scenario.ClientsSpec, jobs *JobLedger, m *Metrics, opts ...UIOption) *UIClients
NewUIClients returns UI clients watching t's farm. The pollers and the own-job lookups call through c without its retries, because a poller's throttled call is an error it counts; the WebSocket dial reuses c's HTTP client, so it trusts the same CA.
type UIOption ¶
type UIOption func(*UIClients)
UIOption configures NewUIClients.
func WithUIRand ¶
WithUIRand seeds the clients' random choices; without it a fixed seed is used.