a http load testing tool in go
Go 1.16+
go get github.com/wosai/ultron/v2
package main
import (
"net/http"
"time"
"github.com/wosai/ultron/v2"
)
func main() {
task := ultron.NewTask()
attacker := ultron.NewHTTPAttacker("google")
attacker.Apply(
ultron.WithPrepareFunc(func() (*http.Request, error) { // 压测事务逻辑实现
return http.NewRequest(http.MethodGet, "https://www.google.com/ncr", nil)
}),
ultron.WithCheckFuncs(ultron.CheckHTTPStatusCode),
)
task.Add(attacker, 1)
plan := ultron.NewPlan("google homepage")
plan.AddStages(
&ultron.V1StageConfig{
Duration: 10 * time.Minute,
ConcurrentUsers: 200,
RampUpPeriod: 10,
}
)
runner := ultron.NewLocalRunner()
runner.Assign(task)
if err := runner.Launch(); err != nil {
panic(err)
}
if err := runner.StartPlan(plan); err != nil {
panic(err)
}
block := make(chan struct{}, 1)
<-block
}
package main
import (
"net/http"
"github.com/wosai/ultron/v2"
"google.golang.org/grpc"
)
func main() {
task := ultron.NewTask()
attacker := ultron.NewHTTPAttacker("google")
attacker.Apply(
ultron.WithPrepareFunc(func() (*http.Request, error) { // 压测事务逻辑实现
return http.NewRequest(http.MethodGet, "https://www.google.com/ncr", nil)
}),
ultron.WithCheckFuncs(ultron.CheckHTTPStatusCode),
)
task.Add(attacker, 1)
// 启动runner
runner := ultron.NewSlaveRunner()
runner.Assign(task)
runner.SubscribeResult(nil) // 订阅单次压测结果
if err := runner.Connect(":2021", grpc.WithInsecure()); err != nil { // 连接master的grpc服务
panic(err)
}
// 阻塞当前goroutine,避免程序推出
block := make(chan struct{}, 1)
<-block
}
ultron
{
"first_attack": "2021-11-02T03:09:08.419359417Z",
"last_attack": "2021-11-02T03:09:21.209236204Z",
"total_requests": 139450,
"total_tps": 10903.15429322517,
"full_history": true,
"reports": {
"benchmark": {
"name": "benchmark",
"requests": 139450,
"min": 10000253,
"max": 40510983,
"median": 10000000,
"average": 11869156,
"tps": 10903.15429322517,
"distributions": {
"0.50": 10000000,
"0.60": 10000000,
"0.70": 10000000,
"0.80": 10000000,
"0.90": 20000000,
"0.95": 21000000,
"0.97": 26000000,
"0.98": 29000000,
"0.99": 30000000,
"1.00": 40510983
},
"full_history": true,
"first_attack": "2021-11-02T03:09:08.419359417Z",
"last_attack": "2021-11-02T03:09:21.209236204Z"
}
},
"extras": {
"plan": "benchmark test"
}
}
scripts/grafana/dashboard.json
Module | Description |
---|---|
github.com/wosai/ultron/attacker/fastattacker/v2 |
Another http attacker implemented by fasthttp |
github.com/wosai/ultron/attacker/jsonrpc/v2 |
A attacker used for jsonrpc protocol |
github.com/wosai/ultron/handler/influxdbv1/v2 |
A handler that save attack result and report in InfluxDB v1 |
github.com/wosai/ultron/attacker/mqtt/v2 |
A attacker used for MQTT protocol v3.3 |
Made with contrib.rocks.