Replacement of ApacheBench(ab), support for transactional requests, support for command line and package references to HTTP stress testing tool.

stress

Build Status GoDoc

stress is an HTTP stress testing tool. Through this tool, you can do a stress test on the HTTP service and get detailed test results. It is inspired by hey.

Installation

go get -u github.com/wenjiax/stress

Features

  • Transactional task support
  • Support duration and total number of requests
  • Support package reference
  • Support custom event
  • Support customizable

Usage

stress contains two usage, either via the command line or used as a package.

1.Use command line.

Usage: stress [options...] <url> || stress [options...] -enable-tran <urls...>

Options:
  -n  Number of requests to run. Default value is 100.
      If set to -1, the request has been sent, but the report will 
      not be output by default.
  -c  Number of requests to run concurrently. 
      Total number of requests cannot smaller than the concurrency level. 
      Default value is 0.
  -d  Duration of requests to run. Default value is 0 sec.
  -o  Output file path. For example: /home/user or ./files.
  
  -h  Custom HTTP header. For example: 
      -h "Accept: text/html" -h "Content-Type: application/xml".
  -m  HTTP method, any of GET, POST, PUT, DELETE, HEAD, OPTIONS.
  -t  Timeout for each request in seconds. Default value is 20, 
      use 0 for infinite.
  -b  HTTP request body.
  -B  HTTP request body from file. For example:
      /home/user/file.txt or ./file.txt.
  -x  HTTP Proxy address as host:port.

  -h2 	 Enable HTTP/2.
  -host	 Set HTTP Host header.
  
  -think-time           Time to think after request. Default value is 0 sec.
  -disable-compression  Disable compression.
  -disable-keepalive    Disable keep-alive, prevents re-use of TCP
                    	connections between different HTTP requests.
  -disable-redirects    Disable following of HTTP redirects.
  -enable-tran          Enable transactional requests. Multiple urls 
                        form a transactional requests. 
                        For example: "stress [options...] -enable-tran 
                        http://localhost:8080,m:post,b:hi,x:http://127.0.0.1:8888 
                        http://localhost:8888,m:post,B:/home/file.txt,thinkTime:2 
                        [urls...]".

For example: run a task.

stress -n 1000 -c 10 -m GET http://localhost:8080

For example: run a transactional request composed of multiple URL.

stress -n 1000 -c 10 -enable-tran http://localhost:8080,m:post,b:hi,x:http://127.0.0.1:8888 http://localhost:8888,m:post,B:/home/file.txt,thinkTime:2 

2.Use package.

For example: run a task.

package main

import (
	"fmt"

	stress "github.com/wenjiax/stress/stress"
)

func main() {
	task := &stress.Task{
		Duration:   10, // Continuous request for 10 seconds
		Concurrent: 10,
		ReportHandler: func(results []*stress.Result, totalTime time.Duration) {
			// Processing result reporting function.
			// If the function is passed in, the incoming function is used to process the report,
			// otherwise the default function is used to process the report.
		},
	}
	err := task.Run(&stress.RequestConfig{
		URLStr: "http://localhost:8080/api/test",
		Method: "GET",
	})
	if err != nil {
		fmt.Println(err)
	}
}

For example: run a transactional request composed of multiple URL.

package main

import (
	"fmt"

	stress "github.com/wenjiax/stress/stress"
)

func main() {
	task := &stress.Task{
		Number:     1000,
		Concurrent: 10,
	}
	var configs []*stress.RequestConfig
	configs = append(configs, &stress.RequestConfig{
		URLStr: "http://localhost:8080/api/test",
		Method: "GET",
	})
	configs = append(configs, &stress.RequestConfig{
		URLStr: "http://localhost:8080/api/hello",
		Method: "POST",
	})
	err := task.RunTran(configs...)
	if err != nil {
		fmt.Println(err)
	}
}

Add event handling. Make some extra processing before each request, such as setting a different header or request body at a time.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"net/http"

	stress "github.com/wenjiax/stress/stress"
)

func main() {
	task := &stress.Task{
		Number:     1000,
		Concurrent: 10,
	}
	events := &stress.Events{
		// Share is a container that is shared in the current transaction,
		// you can access the required content.
		RequestBefore: func(req *stress.Request, share stress.Share) {
			req.Req.Header.Set("Content-Type", "text/html")
			req.Req.Body = ioutil.NopCloser(bytes.NewReader([]byte("Hello Body")))
			share["name"] = "wenjiax"
		},
		ResponseAfter: func(res *http.Response, share stress.Share) {
			name := share["name"] // name="wenjiax"
			fmt.Println(name)
		},
	}
	err := task.Run(&stress.RequestConfig{
		URLStr: "http://localhost:8080/api/test",
		Method: "GET",
		Events: events,
	})
	if err != nil {
		fmt.Println(err)
	}
}

License

stress source code is licensed under the Apache Licence, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html).

Similar Resources

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

fasthttp Fast HTTP implementation for Go. Currently fasthttp is successfully used by VertaMedia in a production serving up to 200K rps from more than

Jan 2, 2023

Simple HTTP package that wraps net/http

Simple HTTP package that wraps net/http

Jan 17, 2022

Go Supertest is minimalize HTTP Client Testing only for Gin Framework

Go Supertest is minimalize HTTP Client Testing only for Gin Framework, inspired by Supertest package library HTTP Client Testing for Express.js Framework.

May 22, 2022

A Go "clone" of the great and famous Requests library

GRequests A Go "clone" of the great and famous Requests library License GRequests is licensed under the Apache License, Version 2.0. See LICENSE for t

Dec 23, 2022

🏠 An HTTP-based command runner for home automation.

🏠 An HTTP-based command runner for home automation.

Badges Reporting Issues If you are facing a problem with this package or found any bug, please open an issue on GitHub. License The MIT License (MIT).

Oct 29, 2022

retryablehttp package provides a familiar HTTP client interface with automatic retries and exponential backoff.

retryablehttp package provides a familiar HTTP client interface with automatic retries and exponential backoff.

Jan 4, 2023

goql is a GraphQL client package written in Go. with built-in two-way marshaling support via struct tags.

goql is a GraphQL client package written in Go. with built-in two-way marshaling support via struct tags.

Dec 1, 2022

Speak HTTP like a local. (the simple, intuitive HTTP console, golang version)

http-gonsole This is the Go port of the http-console. Speak HTTP like a local Talking to an HTTP server with curl can be fun, but most of the time it'

Jul 14, 2021

Http client call for golang http api calls

httpclient-call-go This library is used to make http calls to different API services Install Package go get

Oct 7, 2022
Related tags
This is a simple single-host reverse proxy that intercept and save HTTP requests and responses
This is a simple single-host reverse proxy that intercept and save HTTP requests and responses

HTTP Telescope Debug HTTP requests using a reverse proxy. Description This is a simple single-host reverse proxy that intercept and save HTTP requests

Mar 20, 2022
A Go HTTP client library for creating and sending API requests
A Go HTTP client library for creating and sending API requests

Sling Sling is a Go HTTP client library for creating and sending API requests. Slings store HTTP Request properties to simplify sending requests and d

Jan 7, 2023
httpreq is an http request library written with Golang to make requests and handle responses easily.

httpreq is an http request library written with Golang to make requests and handle responses easily. Install go get github.com/binalyze/http

Feb 10, 2022
Gourl: Performs (multiple) HTTP requests and gathers stats

Gourl: Performs (multiple) HTTP requests and gathers stats

Mar 9, 2022
Nap is a file-based framework for automating the execution of config-driven HTTP requests and scripts.

Nap Nap is a file-based framework for automating the execution of config-driven HTTP requests and scripts. Installation Options Using go get $ go inst

Nov 17, 2022
HTTP Load Testing And Benchmarking Tool

GBench HTTP Load Testing And Benchmarking Tool inspired by Apache Benchmark and Siege. Requirements You need Golang installed and ready on your system

Jan 2, 2020
HTTP/HTTPS load testing and benchmarking tool

Introduction I wrote that code because: (the obvious reason::I love to write code in Go) We are working so hard to optimize our servers - why shouldn'

Dec 5, 2022
go http api to handle phishing resources requests

go http api to handle phishing resources requests (auth check, prometheus metrics, pushing to rabbit, logging to elasticsearch)

Oct 8, 2021
This project aims for printing HTTP requests from outside simply

HTTP Debug Server This project aims for printing HTTP requests from outside simp

Jan 29, 2022
An HTTP performance testing tool written in GoLang

Gonce A HTTP API performance testing tool written in GoLang Description Installation Usage Description A performance testing tool written in GoLang. S

Jan 28, 2022