Пример #1
0
func main() {
	var (
		c, n int
		url  string
		size int
	)

	flag.IntVar(&c, "c", 50, "number of connections")
	flag.IntVar(&n, "n", 200, "number of requests")
	flag.IntVar(&size, "s", 128, "size of put request")
	// 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)
	}

	var act string
	if act = flag.Args()[0]; act != "get" && act != "put" {
		fmt.Printf("unsupported action %v\n", act)
		os.Exit(1)
	}

	conn, err := grpc.Dial(url)
	if err != nil {
		fmt.Errorf("dial error: %v", err)
		os.Exit(1)
	}

	results = make(chan *result, n)
	bar = pb.New(n)
	bar.Format("Bom !")
	bar.Start()

	start := time.Now()

	if act == "get" {
		var rangeEnd []byte
		key := []byte(flag.Args()[1])
		if len(flag.Args()) > 2 {
			rangeEnd = []byte(flag.Args()[2])
		}
		benchGet(conn, key, rangeEnd, n, c)
	} else if act == "put" {
		key := []byte(flag.Args()[1])
		// number of different keys to put into etcd
		kc, err := strconv.ParseInt(flag.Args()[2], 10, 32)
		if err != nil {
			panic(err)
		}
		benchPut(conn, key, int(kc), n, c, size)
	}

	wg.Wait()

	bar.Finish()
	printReport(n, results, time.Now().Sub(start))
}
Пример #2
0
Файл: pb.go Проект: algoadv/etcd
func main() {
	count := 5000
	bar := pb.New(count)

	// show percents (by default already true)
	bar.ShowPercent = true

	// show bar (by default already true)
	bar.ShowBar = true

	// no need counters
	bar.ShowCounters = true

	bar.ShowTimeLeft = true

	// and start
	bar.Start()
	for i := 0; i < count; i++ {
		bar.Increment()
		time.Sleep(time.Millisecond)
	}
	bar.FinishPrint("The End!")
}
Пример #3
0
func main() {
	// check args
	if len(os.Args) < 3 {
		printUsage()
		return
	}
	sourceName, destName := os.Args[1], os.Args[2]

	// check source
	var source io.Reader
	var sourceSize int64
	if strings.HasPrefix(sourceName, "http://") {
		// open as url
		resp, err := http.Get(sourceName)
		if err != nil {
			fmt.Printf("Can't get %s: %v\n", sourceName, err)
			return
		}
		defer resp.Body.Close()
		if resp.StatusCode != http.StatusOK {
			fmt.Printf("Server return non-200 status: %v\n", resp.Status)
			return
		}
		i, _ := strconv.Atoi(resp.Header.Get("Content-Length"))
		sourceSize = int64(i)
		source = resp.Body
	} else {
		// open as file
		s, err := os.Open(sourceName)
		if err != nil {
			fmt.Printf("Can't open %s: %v\n", sourceName, err)
			return
		}
		defer s.Close()
		// get source size
		sourceStat, err := s.Stat()
		if err != nil {
			fmt.Printf("Can't stat %s: %v\n", sourceName, err)
			return
		}
		sourceSize = sourceStat.Size()
		source = s
	}

	// create dest
	dest, err := os.Create(destName)
	if err != nil {
		fmt.Printf("Can't create %s: %v\n", destName, err)
		return
	}
	defer dest.Close()

	// create bar
	bar := pb.New(int(sourceSize)).SetUnits(pb.U_BYTES).SetRefreshRate(time.Millisecond * 10)
	bar.ShowSpeed = true
	bar.Start()

	// create multi writer
	writer := io.MultiWriter(dest, bar)

	// and copy
	io.Copy(writer, source)
	bar.Finish()
}