Ejemplo n.º 1
0
func main() {
	flag.StringVar(&url, "u", "", "URL to load test (required)")
	flag.StringVar(&method, "m", "GET", "HTTP method")
	flag.UintVar(&concurrency, "c", 10, "number of concurrent requests")
	flag.UintVar(&requests, "n", 1000, "number of total requests to make")
	flag.UintVar(&timeout, "t", 15, "request timeout in seconds")
	flag.StringVar(&regions, "r", "us-east-1,eu-west-1,ap-northeast-1", "AWS regions to run in (comma separated, no spaces)")
	flag.Parse()

	if url == "" {
		flag.Usage()
		os.Exit(0)
	}

	test, testerr := goad.NewTest(&goad.TestConfig{
		URL:            url,
		Concurrency:    concurrency,
		TotalRequests:  requests,
		RequestTimeout: time.Duration(timeout) * time.Second,
		Regions:        strings.Split(regions, ","),
		Method:         method,
	})
	if testerr != nil {
		fmt.Println(testerr)
		os.Exit(1)
	}

	var finalResult queue.RegionsAggData
	defer printSummary(&finalResult)

	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) // but interrupts from kbd are blocked by termbox

	start(test, &finalResult, sigChan)
}
Ejemplo n.º 2
0
func serveResults(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/goad" {
		http.Error(w, "Not found", 404)
		return
	}
	if r.Method != "GET" {
		http.Error(w, "Method not allowed", 405)
		return
	}
	w.Header().Set("Content-Type", "application/json; charset=utf-8")

	url := r.URL.Query().Get("url")
	if len(url) == 0 {
		http.Error(w, "Missing URL", 400)
		return
	}

	// Commented out param handling, we have hard coded limits for the website testing
	//
	// concurrencyStr := r.URL.Query().Get("c")
	// concurrency, cerr := strconv.Atoi(concurrencyStr)
	// if cerr != nil {
	// 	http.Error(w, "Invalid concurrency", 400)
	// 	return
	// }
	//
	// totStr := r.URL.Query().Get("tot")
	// tot, toterr := strconv.Atoi(totStr)
	// if toterr != nil {
	// 	http.Error(w, "Invalid total", 400)
	// 	return
	// }
	//
	// timeoutStr := r.URL.Query().Get("timeout")
	// timeout, timeouterr := strconv.Atoi(timeoutStr)
	// if timeouterr != nil {
	// 	http.Error(w, "Invalid timeout", 400)
	// 	return
	// }

	c, err := upgrader.Upgrade(w, r, nil)
	if err != nil {
		log.Print("Websocket upgrade:", err)
		return
	}
	defer c.Close()

	config := goad.TestConfig{
		URL:            url,
		Concurrency:    5,
		TotalRequests:  1000,
		RequestTimeout: time.Duration(5 * time.Second),
		Regions:        []string{"us-east-1", "eu-west-1"},
		Method:         "GET",
	}

	test, testerr := goad.NewTest(&config)
	if testerr != nil {
		fmt.Println(testerr)
		return
	}
	resultChan := test.Start()

	for result := range resultChan {
		message, jsonerr := jsonFromRegionsAggData(result)
		if jsonerr != nil {
			log.Println(jsonerr)
			break
		}
		go readLoop(c)
		err = c.WriteMessage(websocket.TextMessage, []byte(message))
		if err != nil {
			log.Println("write:", err)
			break
		}
	}
}