예제 #1
0
func main() {

	flag.Parse()

	if *flNumber < *flConcurrent {
		log.Fatalf(
			"Total number of requests %d should be greater than number of concurrent connections %s",
			*flNumber, *flConcurrent)
		os.Exit(1)
	}

	flag.Usage = func() {
		flag.PrintDefaults()
		return
	}

	log.SetLevel(log.InfoLevel)

	u := url.URL{Scheme: "ws", Host: *flAddress, Path: "/"}

	chResponses := make(chan *Response, *flNumber)
	chRequests := make(chan stats.MessageRequest, *flNumber)

	var wg sync.WaitGroup
	wg.Add(*flNumber)

	for i := 0; i < *flConcurrent; i++ {
		go startClient(&u, &wg, chRequests, chResponses, i)
	}

	log.Info("Launched all goroutines!")

	var mreq stats.MessageRequest
	mreq.StatType = stats.ALL
	mreq.Type = stats.STATALL

	start := time.Now()
	for i := 0; i < *flNumber; i++ {
		chRequests <- stats.MessageRequest{
			StatType: stats.ALL,
			Type:     stats.STATALL,
		}
	}

	log.Info("Launched all requests!")

	close(chRequests)

	log.Info("In progress ...")

	wg.Wait()

	printSummary(chResponses, time.Since(start))
}
예제 #2
0
func main() {
	flag.Parse()

	log.SetLevel(log.InfoLevel)

	u := url.URL{Scheme: "ws", Host: *flAddress, Path: "/"}

	dialer := websocket.Dialer{}

	conn, _, err := dialer.Dial(u.String(), nil)
	if err != nil {
		log.Fatal("Failed to establish connection with server: ", err)
	}

	defer conn.Close()

	now := time.Now()

	go func() {
		defer conn.Close()
		for {
			var mresp stats.MessageResponse

			if err := conn.ReadJSON(&mresp); err != nil {
				log.Error("Error reading json response: ", err)
				break
			} else {
				log.Info("Received response from node: ", mresp.Host)
				log.Info("Duration:", time.Since(now))
				PrintStats(&mresp)
			}
		}

	}()

	for {
		var mreq stats.MessageRequest
		mreq.StatType = stats.ALL
		mreq.Type = stats.STATALL

		if err := conn.WriteJSON(&mreq); err != nil {
			log.Error("Failed to send req: ", err)
		} else {
			now = time.Now()
			log.Debug("Sent req: ", mreq)
		}

		time.Sleep(time.Duration(*flDuration) * time.Second)
	}
}