fperf

package module
v0.0.0-...-55f1cb7 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

README

Framework of performance testing

Build Status Go Report Card

fperf is a powerful and flexible framework which allows you to develop your own benchmark tools so much easy. You create the client and send requests, fperf do the concurrency and statistics, then give you a report about qps and latency. Any one can create powerful performance benchmark tools by fperf with only some knowledge about how to send a request.

Build fperf with the builtin clients

go install ./bin/fperf 

or use fperf-build

go install ./bin/fperf-build

fperf-build ./clients/*

Quick Start

If you can not wait to run fperf to see how it works, follow the quickstart here.

Customize client

You can build your own client based on fperf framework. A client in fact is a client that implement the fperf.Client or to say more precisely fperf.UnaryClient or fperf.StreamClient.

An unary client is a client to send requests. It works in request-reply model. For example, HTTP benchmark client is an unary client. See http client.

type Client interface {
        Dial(addr string) error
}
type UnaryClient interface {
        Client
        Request() error
}

A stream client is a client to send and receive data by stream or datagram. TCP and UDP nomarlly can be implemented as stream client. Google's grpc has a stream mode and can be used as a stream client. See grpc_testing

type StreamClient interface {
	Client
	CreateStream(ctx context.Context) (Stream, error)
}
type Stream interface {
	DoSend() error
	DoRecv() error
}
Three steps to create your own client

1.Create the "NewClient" function

package demo

import (
	"fmt"
	"github.com/shafreeck/fperf"
	"time"
)

type demoClient struct{}

func newDemoClient(flag *fperf.FlagSet) fperf.Client {
	return &demoClient{}
}

2.Implement the UnaryClient or StreamClient

func (c *demoClient) Dial(addr string) error {
	fmt.Println("Dial to", addr)
	return nil
}

func (c *demoClient) Request() error {
	time.Sleep(100 * time.Millisecond)
	return nil
}

3.Register to fperf

func init() {
	fperf.Register("demo", dewDemoClient, "This is a demo client discription")
}
Building custom clients

You client should be in the same workspace(same $GOPATH) with fperf.

Using fperf-build

fperf-build is a tool to build custom clients. It accepts a path of your package and create file autoimport.go which imports all your clients when build fperf, then cleanup the generated files after buiding.

Installing from source

go install ./bin/fperf-build

or installing from github

go get github.com/shafreeck/fperf/bin/fperf-build
fperf-build [packages]

packages can be go importpath(see go help importpath) or absolute path to your package

For example, build all clients alang with fperf(using relative importpath)

fperf-build ./clients/* 

Run benchmark

Options
  • -N : number of the requests issued per goroutine

  • -async=false: send and recv in seperate goroutines
    Only used in stream mode. Use two groutine per stream, one for sending and another for recving. defualt is false.

  • -burst=0: burst a number of request, use with

  • -async=true
    Used with -async option. use birst to limit the counts of request the sending goroutine issued. default is unlimited.

  • -connection=1: number of connection
    Set the number of connection will be created.

  • -cpu=0: set the GOMAXPROCS, use go default if 0
    Set the GOMAXPROCS, default is 0, which means use the golang default option.

  • -goroutine=1: number of goroutines per stream
    Set the number of goroutines, should only be used when testing is unary mode or streaming mode with only 1 stream. This is because the stream is not thread-safty

  • -influxdb="": writing stats to influxdb, specify the address in this option
    Set the influxdb address, fperf will automatic create a fperf table and inserting into the qps and lantency metrics.

  • -delay=0: wait time before send the next request
    Set the time to wait before send a request

  • -recv=true: perform recv action
    Only used in stream mode. Just enable the recving goroutine.

  • -send=true: perform send action Only used in stream mode. Just enable the sending goroutine.

  • -server="127.0.0.1:8804": address of the remote server
    Set the address of the target server

  • -stream=1: number of streams per connection
    Set the number of stream will be created. Only being used in stream mode.

  • -tick=2s: interval between statistics
    Set the interval time between output the qps and latency metrics

  • -type="auto": set the call type:unary, stream or auto. default is auto
    Set the type of your testcase. This option can be used when your testcase implement unary and stream client at the same time and in this case fperf can not judge the type automaticlly

Draw live graph with grafana

TODO export data into influxdb and draw graph with grafana

Documentation

Overview

fperf allows you to build your performace tools easily

Three steps to create your own testcase

1. Create the "NewClient" function

package demo

import (
	"fmt"
	"github.com/shafreeck/fperf"
	"time"
)

type DemoClient struct{}

func NewDemoClient(flag *fperf.FlagSet) fperf.Client {
	return &DemoClient{}
}

2. Implement the UnaryClient or StreamClient

func (c *DemoClient) Dial(addr string) error {
	fmt.Println("Dial to", addr)
	return nil
}

func (c *DemoClient) Request() error {
	time.Sleep(100 * time.Millisecond)
	return nil
}

3. Register to fperf

func init() {
	fperf.Register("demo", NewDemoClient, "This is a demo client discription")
}

Run the buildin testcase

http is a simple builtin testcase to benchmark http servers

fperf -cpu 8 -connection 10 http http://example.com

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllClients

func AllClients() map[string]string

AllClients return the client name and its description

func Main

func Main()

func Register

func Register(name string, f NewClientFunc, desc ...string)

Register attatch a client to fperf

Types

type Client

type Client interface {
	Dial(addr string) error
}

Client use Dial to connect to the server

func NewClient

func NewClient(name string) Client

NewClient create a client by the name it registered

type FlagSet

type FlagSet struct {
	*flag.FlagSet
}

FlagSet combines the standard flag.FlagSet, this can be used to parse args by the client

func (*FlagSet) Parse

func (f *FlagSet) Parse()

Parse the command line args

type NewClientFunc

type NewClientFunc func(*FlagSet) Client

NewClientFunc defines the function type a client should implement

type Stream

type Stream interface {
	DoSend() error
	DoRecv() error
}

Stream use DoSend/DoRecv to send/recv data or message

type StreamClient

type StreamClient interface {
	Client
	CreateStream(ctx context.Context) (Stream, error)
}

StreamClient used to create a stream

type UnaryClient

type UnaryClient interface {
	Client
	Request() error
}

UnaryClient defines the request-reply access model

Directories

Path Synopsis
bin
clients
redis
This is an example about how to build a redis benchmark to using fperf A fperf testcase in fact is an implementation of fperf.UnaryClient.
This is an example about how to build a redis benchmark to using fperf A fperf testcase in fact is an implementation of fperf.UnaryClient.
example

Jump to

Keyboard shortcuts

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