lstats

package module
v0.0.0-...-8c2817f Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2017 License: MIT Imports: 8 Imported by: 0

README

lstats

A golang load tests package

Requirements

  • github.com/gosuri/uiprogress package

Installation

Get the package using go get :

go get -v github.com/seblegall/lstats

Usage

Example of usage :

package main

import (
	"io/ioutil"
	"log"
	"net/http"
	"strings"

	"github.com/seblegall/lstats"
)

func main() {

	content, _ := ioutil.ReadFile("urls.txt")
	urls := strings.Split(string(content), "\n")

	var reqs []*http.Request

	for _, url := range urls {
		if url != "" {
			req, err := http.NewRequest("GET", url, nil)
			if err != nil {
				log.Printf("Error when creatin request for url : %s", url)
			}
			req.SetBasicAuth("test", "test")

			reqs = append(reqs, req)
		}
	}

	//25 is the total parallel workers desired.
	//This way, lstat will do the calls on 25 differents go routine.
	test := lstats.NewLoadStats(reqs, 25)
	test.Launch()
	test.Print()
}

note : The NewLoadStats() function is expecting a slice of *http.Request. This let you create custom request and add headers, auth, or anything you need to actualy to the request. The second parameters is the count of parrallel workers desired.

Now, let's create an urls.txt file containing a list of url to test with one url by line :

http://example.com/test/123/tests
http://example.com/test/456/tests
http://example.com/test/789/tests
http://example.com/test/101/tests
http://example.com/test/121/tests
http://example.com/test/314/tests
http://example.com/test/151/tests

and finaly, we can launch the test using :

$ go run main.go

This will output something similar to :

Starting load test...
  23s [===================================================================>] 100%

AVG Response Time       Total Calls in error
0.578685                0

TODO

  • Add unit tests
  • Add possibiity to set the number of concurrent workers
  • Add a random wait time between requests in order to simulate more realistic user calls

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FailureLog

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

FailureLog represents the response send by the tested url when status code is >= 300.

type LoadStats

type LoadStats struct {
	Reqs []*http.Request

	CallsResponseTime   []float64
	AverageResponseTime float64
	FailureCount        int
	FailuresLogs        []FailureLog
	// contains filtered or unexported fields
}

LoadStats represents a load test configuration and the load test result.

func NewLoadStats

func NewLoadStats(reqs []*http.Request, workers int) LoadStats

NewLoadStats init a new load test.

func (*LoadStats) Launch

func (ls *LoadStats) Launch()

Launch actualy execute the load test using workers as set in the LoadStats This function print a progress bar to follow the test current status.

func (*LoadStats) Print

func (ls *LoadStats) Print()

Print show the load test result using tab writer.

Jump to

Keyboard shortcuts

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