示例#1
0
文件: main.go 项目: mogren/accload
func main() {

	var config tomlConfig
	if _, err := toml.DecodeFile("example.toml", &config); err != nil {
		fmt.Println("No config file, using default settings.")
		config.Name = "Default"
	}
	fmt.Printf("Title: %s\n", config.Name)

	rate := uint64(100) // per second
	duration := 4 * time.Second
	targeter := vegeta.NewStaticTargeter(vegeta.Target{
		Method: "GET",
		URL:    "http://localhost:8080/",
	})
	attacker := vegeta.NewAttacker()

	var metrics vegeta.Metrics
	for res := range attacker.Attack(targeter, rate, duration) {
		metrics.Add(res)
	}
	metrics.Close()

	fmt.Printf("%d results\n", metrics.Requests)
	fmt.Printf("99th percentile: %s\n", metrics.Latencies.P99)
}
func loadTest(appUri string, rate uint64) (*vegeta.Attacker, <-chan *vegeta.Result) {
	targeter := vegeta.NewStaticTargeter(vegeta.Target{
		Method: "GET",
		URL:    appUri,
	})

	attacker := vegeta.NewAttacker(vegeta.KeepAlive(vegetaKeepAlive))
	res := attacker.Attack(targeter, rate, vegetaRunForever)

	return attacker, res
}
示例#3
0
func startVegetaAttack(targetURLs []string, rate uint64) chan *vegeta.Metrics {
	targets := make([]*vegeta.Target, 0, len(targetURLs))
	for _, url := range targetURLs {
		targets = append(targets, &vegeta.Target{
			Method: "GET",
			URL:    url,
		})
	}
	targeter := vegeta.NewStaticTargeter(targets...)
	metricsChan := make(chan *vegeta.Metrics, 1)
	go vegetaAttack(targeter, rate, metricsChan)
	return metricsChan
}
示例#4
0
func startVegetaLoad(targetURL string) *vegeta.Attacker {
	attacker := vegeta.NewAttacker()
	targetter := vegeta.NewStaticTargeter(&vegeta.Target{Method: "GET", URL: targetURL})
	resCh := attacker.Attack(targetter, 50, time.Minute)

	// Consume and discard results.  Without this, all the workers will block sending
	// to the channel - https://github.com/tsenart/vegeta/blob/v5.4.0/lib/attack.go#L143
	go func() {
		for range resCh {
			//discard
		}
	}()
	return attacker
}
示例#5
0
文件: loader.go 项目: raggi/contrib
func main() {
	flag.Parse()

	var serviceIP string
	ips, err := net.LookupIP(*host)
	if err != nil {
		fmt.Printf("Error looking up %s: %v\n", *host, err)
		os.Exit(2)
	}
	for _, ip := range ips {
		ipv4 := ip.To4()
		if ipv4 != nil {
			serviceIP = ipv4.String()
			break
		}
	}
	if len(serviceIP) == 0 {
		fmt.Printf("Failed to find suitable IP address: %v", ips)
		os.Exit(2)
	}

	host := serviceIP
	if *port != 80 {
		host = fmt.Sprintf("%s:%d", host, port)
	}
	var targets []vegeta.Target
	for _, path := range strings.Split(*paths, ",") {
		path = strings.TrimPrefix(path, "/")
		targets = append(targets, vegeta.Target{
			Method: "GET",
			URL:    fmt.Sprintf("http://%s/%s", host, path),
		})
	}
	targeter := vegeta.NewStaticTargeter(targets...)
	attacker := vegeta.NewAttacker(vegeta.Workers(uint64(*workers)))

	reporter := &HTTPReporter{}
	go http.ListenAndServe(*addr, reporter)

	for {
		metrics := &vegeta.Metrics{}
		for res := range attacker.Attack(targeter, uint64(*rate), *duration) {
			metrics.Add(res)
		}
		metrics.Close()
		reporter.SetMetrics(metrics)
	}
}
示例#6
0
func main() {
	rate := uint64(10000) // per second
	duration := 20 * time.Second
	targeter := vegeta.NewStaticTargeter(vegeta.Target{
		Method: "GET",
		URL:    "http://localhost:3001/get_stuff",
	})
	attacker := vegeta.NewAttacker()

	var metrics vegeta.Metrics
	for res := range attacker.Attack(targeter, rate, duration) {
		metrics.Add(res)
	}
	metrics.Close()

	fmt.Printf("99th percentile: %s\n", metrics.Latencies.P99)
}
示例#7
0
文件: loader.go 项目: resouer/contrib
func main() {
	flag.Parse()

	var serviceIP string
	ips, err := net.LookupIP(*host)
	if err != nil {
		fmt.Printf("Error looking up %s: %v\n", *host, err)
		os.Exit(2)
	}
	for _, ip := range ips {
		ipv4 := ip.To4()
		if ipv4 != nil {
			serviceIP = ipv4.String()
			break
		}
	}
	if len(serviceIP) == 0 {
		fmt.Printf("Failed to find suitable IP address: %v", ips)
		os.Exit(2)
	}

	targeter := vegeta.NewStaticTargeter(vegeta.Target{
		Method: "GET",
		URL:    "http://" + serviceIP + "/",
	})
	attacker := vegeta.NewAttacker(vegeta.Workers(uint64(*workers)))

	reporter := &HTTPReporter{}
	go http.ListenAndServe(*addr, reporter)

	for {
		metrics := &vegeta.Metrics{}
		for res := range attacker.Attack(targeter, uint64(*rate), *duration) {
			metrics.Add(res)
		}
		metrics.Close()
		reporter.SetMetrics(metrics)
	}
}