ghz: Index | Examples | Files

package runner

import ""



Package Files

call_template_data.go data.go options.go reason.go reporter.go requester.go run.go stats_handler.go worker.go


const (
    // ReasonNormalEnd indicates a normal end to the run
    ReasonNormalEnd = StopReason("normal")

    // ReasonCancel indicates end due to cancellation
    ReasonCancel = StopReason("cancel")

    // ReasonTimeout indicates run ended due to Z parameter timeout
    ReasonTimeout = StopReason("timeout")

type Bucket Uses

type Bucket struct {
    // The Mark for histogram bucket in seconds
    Mark float64 `json:"mark"`

    // The count in the bucket
    Count int `json:"count"`

    // The frequency of results in the bucket as a decimal percentage
    Frequency float64 `json:"frequency"`

Bucket holds histogram data

type LatencyDistribution Uses

type LatencyDistribution struct {
    Percentage int           `json:"percentage"`
    Latency    time.Duration `json:"latency"`

LatencyDistribution holds latency distribution data

type Option Uses

type Option func(*RunConfig) error

Option controls some aspect of run

func WithAuthority Uses

func WithAuthority(authority string) Option

WithAuthority specifies the value to be used as the :authority pseudo-header. This only works with WithInsecure option.

func WithBinaryData Uses

func WithBinaryData(data []byte) Option

WithBinaryData specifies the binary data

msg := &helloworld.HelloRequest{}
msg.Name = "bob"
binData, _ := proto.Marshal(msg)

func WithBinaryDataFromFile Uses

func WithBinaryDataFromFile(path string) Option

WithBinaryDataFromFile specifies the binary data


func WithCPUs Uses

func WithCPUs(c uint) Option

WithCPUs specifies the number of CPU's to be used


func WithCertificate Uses

func WithCertificate(cert, key string) Option

WithCertificate specifies the certificate options for the run

WithCertificate("client.crt", "client.key")

func WithConcurrency Uses

func WithConcurrency(c uint) Option

WithConcurrency specifies the C (number of concurrent requests) option


func WithConnections Uses

func WithConnections(c uint) Option

WithConnections specifies the number of gRPC connections to use


func WithData Uses

func WithData(data interface{}) Option

WithData specifies data as generic data that can be serailized to JSON

func WithDataFromFile Uses

func WithDataFromFile(path string) Option

WithDataFromFile loads JSON data from file


func WithDataFromJSON Uses

func WithDataFromJSON(data string) Option

WithDataFromJSON loads JSON data from string


func WithDataFromReader Uses

func WithDataFromReader(r io.Reader) Option

WithDataFromReader loads JSON data from reader

file, _ := os.Open("data.json")

func WithDialTimeout Uses

func WithDialTimeout(dt time.Duration) Option

WithDialTimeout specifies the initial connection dial timeout


func WithInsecure Uses

func WithInsecure(insec bool) Option

WithInsecure specifies that this run should be done using insecure mode


func WithKeepalive Uses

func WithKeepalive(k time.Duration) Option

WithKeepalive specifies the keepalive timeout


func WithMetadata Uses

func WithMetadata(md *map[string]string) Option

WithMetadata specifies the metadata to be used as a map

md := make(map[string]string)
md["token"] = "foobar"
md["request-id"] = "123"

func WithMetadataFromFile Uses

func WithMetadataFromFile(path string) Option

WithMetadataFromFile loads JSON metadata from file


func WithMetadataFromJSON Uses

func WithMetadataFromJSON(md string) Option

WithMetadataFromJSON specifies the metadata to be read from JSON string


func WithName Uses

func WithName(name string) Option

WithName sets the name of the test run

WithName("greeter service test")

func WithProtoFile Uses

func WithProtoFile(proto string, importPaths []string) Option

WithProtoFile specified proto file path and optionally import paths We will automatically add the proto file path's directory and the current directory

WithProtoFile("greeter.proto", []string{"/home/protos"})

func WithProtoset Uses

func WithProtoset(protoset string) Option

WithProtoset specified protoset file path


func WithQPS Uses

func WithQPS(qps uint) Option

WithQPS specifies the QPS (queries per second) limit option


func WithReflectionMetadata Uses

func WithReflectionMetadata(md *map[string]string) Option

WithReflectionMetadata specifies the metadata to be used as a map

md := make(map[string]string)
md["token"] = "foobar"
md["request-id"] = "123"

func WithRootCertificate Uses

func WithRootCertificate(cert string) Option

WithRootCertificate specifies the root certificate options for the run


func WithRunDuration Uses

func WithRunDuration(z time.Duration) Option

WithRunDuration specifies the Z (total test duration) option


func WithServerNameOverride Uses

func WithServerNameOverride(cname string) Option

WithServerNameOverride specifies the certificate options for the run

func WithSkipTLSVerify Uses

func WithSkipTLSVerify(skip bool) Option

WithSkipTLSVerify skip client side TLS verification of server certificate

func WithStreamInterval Uses

func WithStreamInterval(d time.Duration) Option

WithStreamInterval sets the stream interval

func WithTags Uses

func WithTags(tags *map[string]string) Option

WithTags specifies the user defined tags as a map

tags := make(map[string]string)
tags["env"] = "staging"
tags["created by"] = "joe developer"

func WithTimeout Uses

func WithTimeout(timeout time.Duration) Option

WithTimeout specifies the timeout for each request


func WithTotalRequests Uses

func WithTotalRequests(n uint) Option

WithTotalRequests specifies the N (number of total requests) setting


type Options Uses

type Options struct {
    Host          string        `json:"host,omitempty"`
    Proto         string        `json:"proto,omitempty"`
    Protoset      string        `json:"protoset,omitempty"`
    ImportPaths   []string      `json:"import-paths,omitempty"`
    Call          string        `json:"call,omitempty"`
    CACert        string        `json:"cacert,omitempty"`
    Cert          string        `json:"cert,omitempty"`
    Key           string        `json:"key,omitempty"`
    SkipTLS       bool          `json:"skipTLS,omitempty"`
    CName         string        `json:"cname,omitempty"`
    Authority     string        `json:"authority,omitempty"`
    Insecure      bool          `json:"insecure"`
    Total         uint          `json:"total,omitempty"`
    Concurrency   uint          `json:"concurrency,omitempty"`
    QPS           uint          `json:"qps,omitempty"`
    Connections   uint          `json:"connections,omitempty"`
    Duration      time.Duration `json:"duration,omitempty"`
    Timeout       time.Duration `json:"timeout,omitempty"`
    DialTimeout   time.Duration `json:"dial-timeout,omitempty"`
    KeepaliveTime time.Duration `json:"keepalive,omitempty"`

    Data     interface{}        `json:"data,omitempty"`
    Binary   bool               `json:"binary"`
    Metadata *map[string]string `json:"metadata,omitempty"`

    CPUs int    `json:"CPUs"`
    Name string `json:"name,omitempty"`

Options represents the request options

type Report Uses

type Report struct {
    Name      string     `json:"name,omitempty"`
    EndReason StopReason `json:"endReason,omitempty"`

    Options Options   `json:"options,omitempty"`
    Date    time.Time `json:"date"`

    Count   uint64        `json:"count"`
    Total   time.Duration `json:"total"`
    Average time.Duration `json:"average"`
    Fastest time.Duration `json:"fastest"`
    Slowest time.Duration `json:"slowest"`
    Rps     float64       `json:"rps"`

    ErrorDist      map[string]int `json:"errorDistribution"`
    StatusCodeDist map[string]int `json:"statusCodeDistribution"`

    LatencyDistribution []LatencyDistribution `json:"latencyDistribution"`
    Histogram           []Bucket              `json:"histogram"`
    Details             []ResultDetail        `json:"details"`

    Tags map[string]string `json:"tags,omitempty"`

Report holds the data for the full test

func Run Uses

func Run(call, host string, options ...Option) (*Report, error)

Run executes the test

report, err := runner.Run(
	WithProtoFile("greeter.proto", []string{}),

ExampleRun demonstrates how to use runner package to perform a gRPC load test programmatically. We use the printer package to print the report in pretty JSON format.


report, err := runner.Run(
    runner.WithProtoFile("greeter.proto", []string{}),

if err != nil {

printer := printer.ReportPrinter{
    Out:    os.Stdout,
    Report: report,


func (Report) MarshalJSON Uses

func (r Report) MarshalJSON() ([]byte, error)

MarshalJSON is custom marshal for report to properly format the date

type Reporter Uses

type Reporter struct {
    // contains filtered or unexported fields

Reporter gathers all the results

func (*Reporter) Finalize Uses

func (r *Reporter) Finalize(stopReason StopReason, total time.Duration) *Report

Finalize all the gathered data into a final report

func (*Reporter) Run Uses

func (r *Reporter) Run()

Run runs the reporter

type Requester Uses

type Requester struct {
    // contains filtered or unexported fields

Requester is used for doing the requests

func (*Requester) Finish Uses

func (b *Requester) Finish() *Report

Finish finishes the test run

func (*Requester) Run Uses

func (b *Requester) Run() (*Report, error)

Run makes all the requests and returns a report of results It blocks until all work is done.

func (*Requester) Stop Uses

func (b *Requester) Stop(reason StopReason)

Stop stops the test

type ResultDetail Uses

type ResultDetail struct {
    Timestamp time.Time     `json:"timestamp"`
    Latency   time.Duration `json:"latency"`
    Error     string        `json:"error"`
    Status    string        `json:"status"`

ResultDetail data for each result

type RunConfig Uses

type RunConfig struct {
    // contains filtered or unexported fields

RunConfig represents the request Configs

type StopReason Uses

type StopReason string

StopReason is a reason why the run ended

func ReasonFromString Uses

func ReasonFromString(str string) StopReason

ReasonFromString creates a Status from a string

func (StopReason) MarshalJSON Uses

func (s StopReason) MarshalJSON() ([]byte, error)

MarshalJSON formats a Threshold value into a JSON string

func (StopReason) String Uses

func (s StopReason) String() string

String() is the string representation of threshold

func (*StopReason) UnmarshalJSON Uses

func (s *StopReason) UnmarshalJSON(b []byte) error

UnmarshalJSON prases a Threshold value from JSON string

type Worker Uses

type Worker struct {
    // contains filtered or unexported fields

Worker is used for doing a single stream of requests in parallel

Package runner imports 35 packages (graph) and is imported by 2 packages. Updated 2019-07-25. Refresh now. Tools for package owners.