forked from vdobler/ht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perf.go
69 lines (60 loc) · 1.58 KB
/
perf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2014 Volker Dobler. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"log"
"time"
"github.com/vdobler/ht/ht"
)
var cmdPerf = &Command{
RunSuites: runPerf,
Usage: "perf [flags] <suite>...",
Description: "run a performance/load test",
Flag: flag.NewFlagSet("run", flag.ContinueOnError),
Help: `
Perf performs a load test
`,
}
func init() {
cmdPerf.Flag.Float64Var(&rateFlag, "rate", 20,
"set average `rate` of requests per second")
cmdPerf.Flag.IntVar(&countFlag, "count", 1000,
"perform `num` requests")
cmdPerf.Flag.DurationVar(&timeoutFlag, "timeout", 5*time.Minute,
"set `maximum` duration to to run the load test")
cmdPerf.Flag.BoolVar(&uniformFlag, "uniform", true,
"use uniformly distributed requests instead of exponentialy distributed")
cmdPerf.Flag.BoolVar(&concFlag, "conc", false,
"do a concurrency test instead of a throughput test")
addOnlyFlag(cmdPerf.Flag)
addSkipFlag(cmdPerf.Flag)
addTestFlags(cmdPerf.Flag)
}
var (
rateFlag float64
timeoutFlag time.Duration
countFlag int
uniformFlag bool
concFlag bool
)
func runPerf(cmd *Command, suites []*ht.Suite) {
opts := ht.LoadTestOptions{
Type: "throughput",
Rate: rateFlag,
Count: countFlag,
Timeout: timeoutFlag,
Uniform: uniformFlag,
}
if concFlag {
opts.Type = "concurrency"
}
results, err := ht.PerformanceLoadTest(suites, opts)
if err != nil {
log.Fatal(err.Error())
}
ltr := ht.AnalyseLoadtest(results)
fmt.Printf("%s\n", ltr)
}