Beispiel #1
0
func connect(servers ...string) (clients []*client.Client, err error) {
	for _, s := range servers {
		c, err := client.New(s)
		if err != nil {
			return nil, err
		}
		clients = append(clients, c)
	}
	return
}
Beispiel #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]))
}