Git Product home page Git Product logo

go-locust's Introduction

go-locust

Build Status Go Report Card License: MIT

Description

go-locust is a library to control a locust load generation and get statistics written in golang. This is client allows to start,stop a locust load test and ramp up load. This uses locust endpoints to cummunicate with locust.

Currently, go-locust requires Go version 1.13 or greater and Locust 0.14 or higher. I will try my best to test with older versions of Go and Locust, but due time constraints, I haven't tested with older versions.

This does not process client stats and presents information as it is.

Usage

check example folder


package main

import (
	"log"
	lc "github.com/amila-ku/go-locust"
)

const (
	 hostURL = "http://localhost:8089"
	 users   = 5
	 hatchRate = 1
)

func main(){
	client, err := lc.New(hostURL)
	if err != nil {
		log.Fatal(err)
	}
	_, err = client.GenerateLoad(users, hatchRate)
	if err != nil {
		log.Fatal(err)
	}

}

  • hostUrl : locust endpoiint to connect to, ex : http://locust.loadenv.io:8089

  • users : Number of users to simulate

  • hatchRate : How many users to be added per second

complete example:

package main 

import (
    lc "github.com/amila-ku/go-locust"
)

const (
	 hostURL = "http://localhost:8089"
	 users   = 5
	 hatchRate = 1
)

func main(){
	client, err := lc.New(hostURL)
	if err != nil {
		log.Fatal(err)
	}

	// start load generation
	_, err = client.GenerateLoad(users, hatchRate)
	if err != nil {
		log.Fatal(err)
	}

    	// stop load generation
	_, err = client.stopLoad()
	if err != nil {
		log.Fatal(err)
	}

    	// get loadtest status
	_, err = client.getStatus()
	if err != nil {
		log.Fatal(err)
	}
}

Authentication

Library go-locust will not directly handle authentication since locust does not require authentication. If you have implemented authetication mechanism handle it accordingly. As an example if Oauth2 is used when creating http client configure http.Client to handle authentication for you. Check https://github.com/golang/oauth2 for implementation

Run Locust

install locust


pip3 install locust

and configure loadtest file as described here https://docs.locust.io/en/stable/quickstart.html


locust -f locust_files/my_locust_file.py

Contributing

If you are using the client and willing to add new functionality to it, you are welcome.

Also check out locust-operator which makes running locust in a distributed setup makes easy.

License

Open source licensed under the MIT license (see LICENSE file for details).

go-locust's People

Contributors

amila-ku avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

rich-pomrenke

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.