Example #1
0
func main() {
	flag.Parse()

	conn, err := grpc.Dial(fmt.Sprintf("%v:%v", *host, *port),
		grpc.WithInsecure(),
		grpc.WithTimeout(3*time.Second),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	client := crowdsound.NewCrowdSoundClient(conn)

	for _, b := range benchmarks {
		benchName, results, err := b(client)
		if err != nil {
			log.Fatal("Failed to run benchmark:", err)
		}

		log.Printf("Benchmark results: %v", benchName)
		log.Printf("--------------------------------")
		log.Printf("Min: \t%v μs", results.Min()/1000)
		log.Printf("Max: \t%v μs", results.Max()/1000)
		log.Printf("Mean: \t%v μs", results.Mean()/1000)
		log.Printf("Std: \t%v μs", results.StdDev()/1000)
		log.Print("")
	}
}
Example #2
0
func main() {
	flag.Parse()

	// Run the PostSongs bench with a bunch of clients
	var wg sync.WaitGroup
	wg.Add(*numClients)
	for i := 0; i < *numClients; i++ {
		go func() {
			defer wg.Done()

			conn, err := grpc.Dial(fmt.Sprintf("%v:%v", *host, *port),
				grpc.WithInsecure(),
				grpc.WithTimeout(5*time.Second),
			)
			if err != nil {
				log.Fatal(err)
			}
			defer conn.Close()

			client := crowdsound.NewCrowdSoundClient(conn)
			_, err = bench.RunPostSongsBench(client, 1, *songsToPost)
			if err != nil {
				log.Fatal(err)
			}

			// Now just periodically get the queue
			log.Println("Just pollin things")
			for {
				wait := time.Duration(10+rand.Intn(10)) * time.Second
				time.Sleep(wait)

				var count int
				stream, err := client.GetQueue(context.Background(), &crowdsound.GetQueueRequest{})
				for {
					_, err = stream.Recv()
					if err == io.EOF {
						break
					} else if err != nil {
						log.Fatal(err)
					}

					count++
				}

				fmt.Printf("Received queue of %v items", count)
			}

		}()
	}

	wg.Wait()
}
Example #3
0
func main() {
	flag.Parse()

	conn, err := grpc.Dial(
		fmt.Sprintf("%v:%v", *host, *port),
		grpc.WithInsecure(),
		grpc.WithTimeout(10*time.Second),
	)

	if err != nil {
		log.Fatalf("unable to connect: %v", err)
	}
	defer conn.Close()

	c := crowdsound.NewCrowdSoundClient(conn)

	switch *command {
	case "ping":
		ping(c)
		break
	case "playing":
		printPlaying(c)
		break
	case "queue":
		printQueue(c)
		break
	case "post":
		postSongs(c)
		break
	case "vote":
		vote(c)
		break
	case "voteSkip":
		voteSkip(c)
	case "meta":
		printMeta(c)
		break
	default:
		log.Println("Unrecognized command:", *command)
	}
}