Exemple #1
0
// InitPB initializes a progress bar for the terminal
func InitPB(count int) *pb.ProgressBar {
	bar := pb.New(count)
	bar.ShowPercent = true
	bar.ShowBar = true
	bar.ShowCounters = true
	bar.ShowTimeLeft = true
	return bar
}
Exemple #2
0
func (b *Boomer) startProgress() {
	if b.Output != "" {
		return
	}
	b.bar = pb.New(b.N)
	b.bar.Format("Bom !")
	b.bar.Start()
}
Exemple #3
0
func newPb(size int) (bar *pb.ProgressBar) {
	bar = pb.New(size)
	bar.Current = barChar
	bar.BarStart = ""
	bar.BarEnd = ""
	bar.Start()
	return
}
Exemple #4
0
func newPb(size int) (bar *pb.ProgressBar) {
	bar = pb.New(size)
	bar.Format("Bom !")
	bar.Start()
	return
}
Exemple #5
0
func main() {
	var c, n int
	var url string
	flag.IntVar(&c, "c", 50, "number of connections")
	flag.IntVar(&n, "n", 200, "number of requests")
	// TODO: config the number of concurrency in each connection
	flag.StringVar(&url, "u", "127.0.0.1:12379", "etcd server endpoint")
	flag.Parse()
	if flag.NArg() < 1 {
		flag.Usage()
		os.Exit(1)
	}

	if act := flag.Args()[0]; act != "get" {
		fmt.Errorf("unsupported action %v", act)
		os.Exit(1)
	}
	var rangeEnd []byte
	key := []byte(flag.Args()[1])
	if len(flag.Args()) > 2 {
		rangeEnd = []byte(flag.Args()[2])
	}

	results := make(chan *result, n)
	bar := pb.New(n)
	bar.Format("Bom !")
	bar.Start()
	start := time.Now()
	defer func() {
		bar.Finish()
		printReport(n, results, time.Now().Sub(start))
	}()

	var wg sync.WaitGroup
	wg.Add(c)
	jobs := make(chan struct{}, n)
	for i := 0; i < c; i++ {
		go func() {
			defer wg.Done()

			conn, err := grpc.Dial(url)
			if err != nil {
				fmt.Errorf("dial error: %v", err)
				os.Exit(1)
			}
			etcd := etcdserverpb.NewEtcdClient(conn)
			req := &etcdserverpb.RangeRequest{Key: key, RangeEnd: rangeEnd}

			for _ = range jobs {
				st := time.Now()
				resp, err := etcd.Range(context.Background(), req)

				var errStr string
				if err != nil {
					errStr = err.Error()
				} else {
					errStr = resp.Header.Error
				}
				results <- &result{
					errStr:   errStr,
					duration: time.Now().Sub(st),
				}
				bar.Increment()
			}
		}()
	}
	for i := 0; i < n; i++ {
		jobs <- struct{}{}
	}
	close(jobs)

	wg.Wait()
}