Ejemplo n.º 1
0
func hiveIDFromPeers(addr string, paddrs []string) uint64 {
	if len(paddrs) == 0 {
		return 1
	}

	ch := make(chan uint64, len(paddrs))
	for _, paddr := range paddrs {
		glog.Infof("requesting hive ID from %v", paddr)
		go func(paddr string) {
			c, err := newRPCClient(paddr)
			if err != nil {
				glog.Error(err)
				return
			}
			defer c.stop()

			id, err := c.sendCmd(cmd{Data: cmdNewHiveID{}})
			if err != nil {
				glog.Error(err)
				return
			}

			if id == Nil {
				glog.Fatalf("invalid ID from peer")
			}

			_, err = c.sendCmd(cmd{
				Data: cmdAddHive{
					Hive: HiveInfo{
						ID:   id.(uint64),
						Addr: addr,
					},
				},
			})
			if err != nil {
				glog.Error(err)
				return
			}
			ch <- id.(uint64)
		}(paddr)
		select {
		case id := <-ch:
			return id
		case <-time.After(1 * time.Second):
			glog.Infof("cannot get id from %v", paddr)
			continue
		}
	}

	glog.Fatalf("cannot get a new hive ID from peers")
	return 1
}
Ejemplo n.º 2
0
func main() {
	if !flag.Parsed() {
		flag.Parse()
	}

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			glog.Error("cannot register cpu profile: %v", err)
			os.Exit(-1)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	var clients []*client.Client
	servers := strings.Split(*servers, ",")
	for w := 0; w < *workers; w++ {
		c, err := client.New(servers[w%len(servers)])
		if err != nil {
			glog.Fatalf("cannot create client: %v", err)
		}
		clients = append(clients, c)
	}
	defer closeClients(clients)

	fmt.Printf("warming up... ")
	warmup(clients, *workers, *queues, *size, *shared, *enqOnly)
	fmt.Printf("[ok]\n")

	n := 2
	var lastTput uint64
	for {
		fmt.Printf("trying %d ", n)
		res := run(clients, *workers, *queues, n, *size, 30*time.Second, *shared,
			*enqOnly)
		_, _, tput, _ := metrics(res)
		if converged(lastTput, tput) {
			fmt.Println("[no]")
			break
		}

		fmt.Println("[ok]")
		n *= 2
		lastTput = tput
	}

	n /= 2
	var tputs []uint64
	var lats []uint64
	for i := 0; i < 16; i++ {
		res := run(clients, *workers, *queues, n, *size, 30*time.Second, *shared,
			*enqOnly)
		_, _, tput, lat := metrics(res)
		tputs = append(tputs, tput)
		lats = append(lats, lat...)
	}

	sort.Sort(byval(tputs))
	sort.Sort(byval(lats))

	fmt.Printf("throughput avg=%v median=%v max=%v min=%v\n", avg(tputs),
		prc(tputs, 50), tputs[len(tputs)-1], tputs[0])
	fmt.Printf("latency avg=%v median=%v max=%v min=%v\n",
		time.Duration(avg(lats)), time.Duration(prc(lats, 50)),
		time.Duration(lats[len(lats)-1]), time.Duration(lats[0]))
}