Example #1
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 #2
0
type Benchmark func(client crowdsound.CrowdSoundClient) (name string, results metrics.Histogram, err error)

var benchmarks = []Benchmark{
	func(c crowdsound.CrowdSoundClient) (name string, results metrics.Histogram, err error) {
		name = "Get Session Data"
		results, err = bench.RunGetSessionDataBench(c, *iterations)
		return
	},
	func(c crowdsound.CrowdSoundClient) (name string, results metrics.Histogram, err error) {
		name = "Get Queue"
		results, err = bench.RunGetQueueBench(c, *iterations)
		return
	},
	func(c crowdsound.CrowdSoundClient) (name string, results metrics.Histogram, err error) {
		name = "List Trending Artists"
		results, err = bench.RunListTrendingArtists(c, *iterations)
		return
	},
	func(c crowdsound.CrowdSoundClient) (name string, results metrics.Histogram, err error) {
		name = "Post Songs"
		results, err = bench.RunPostSongsBench(c, *iterations/(*songsToPost / *iterations), *songsToPost)
		return
	},
	func(c crowdsound.CrowdSoundClient) (name string, results metrics.Histogram, err error) {
		name = "Vote Song"
		results, err = bench.RunVoteSongsBench(c, *iterations)
		return
	},
}