Exemple #1
0
func Start(delay int) (err error) {
	barContainer, err := multibar.New()
	if err != nil {
		return
	}

	setter := barContainer.MakeBar(hosts.Len(), "STATUS:")
	go barContainer.Listen()

	time.Sleep(100 * time.Millisecond)
	setter(0)

	i := 0
	for hostInf := range hosts.Iter() {
		host := hostInf.(string)

		_, err = http.Get(
			fmt.Sprintf("http://%s:3800/start", host))
		if err != nil {
			return
		}
		setter(i + 1)

		if i < hosts.Len()-1 {
			time.Sleep(time.Duration(delay) * time.Second)
		}

		i += 1
	}

	time.Sleep(1 * time.Second)
	fmt.Println("START COMPLETE")

	return
}
Exemple #2
0
func LoadMetadata(client *http.Client, cfg *EndpointConfig) (nodes []Metadata, err error) {
	nodesPath := "./nodes.json"
	if err = LoadMetadataFromFile(&nodes, nodesPath); err == nil {
		return
	}

	// if we couldn't load from file, load from API
	if len(nodes) == 0 {

		// now try the metadata url
		list, err := ListNodes("nodes", client, cfg)
		if err != nil {
			log.Fatal(err)
		}

		fmt.Println("List Count:", list.Count)

		nodes = append(nodes, list.Data...)

		var progressBars, _ = multibar.New()
		progressBars.Println("getting the pages")
		barProgress1 := progressBars.MakeBar(list.Count, "loading...")
		go progressBars.Listen()

		getPage(list.NextToken, client, cfg, func(newList *MetadataPage) {
			barProgress1(len(nodes))
			nodes = append(nodes, newList.Data...)
		})

		SaveMetadataToFile(&nodes, nodesPath)
	}

	return
}
Exemple #3
0
func (cmd *s3fillCmd) Run(session *session.Session) error {
	svc := s3.New(session)
	bars, err := multibar.New()
	if err != nil {
		return err
	}
	go bars.Listen()
	progress := bars.MakeBar(cmd.N, cmd.Bucket)
	left := cmd.N
	for left > 0 {
		s := fmt.Sprintf("object-%d", rand.Int63())
		key := path.Join(cmd.Path, s)
		params := &s3.PutObjectInput{
			Bucket:        aws.String(cmd.Bucket),
			ACL:           aws.String(s3.BucketCannedACLPrivate),
			Key:           aws.String(key),
			Body:          strings.NewReader(s),
			ContentLength: aws.Int64(int64(len(s))),
			ContentType:   aws.String("text/plain"),
		}
		_, err := svc.PutObject(params)
		if matches(err, "duplicate") {
			cmd.Log.Printf("bucket=%q, key=%q: %s", cmd.Bucket, key, err)
			continue
		}
		if err != nil {
			return err
		}
		left--
		progress(cmd.N - left - 1)
	}
	return nil
}
Exemple #4
0
func main() {
	flag.Parse()
	progressBars, _ := multibar.New()
	totalRequests := progressBars.MakeBar(999999, "Total requests")
	go progressBars.Listen()

	workers := 100
	group.Add(1)
	go func(w int) {
		for i := 0; i < workers; i++ {
			go worker()
		}
	}(workers)

	progressBars.Printf("Amount of workers: %v", workers)
	go func() {
		for cur := 0; cur < 1000000; cur++ {
			group.Add(1)
			jobs <- strconv.Itoa(cur)
			if cur%100 == 0 {
				totalRequests(cur)
				progressBars.Printf("Requests completed: %v", cur)
				progressBars.Printf("Channel size: %v", len(jobs))
			}
		}
		group.Done()
	}()

	group.Wait()
}
Exemple #5
0
func Close() (err error) {
	bars = []*Bar{}
	barsWaiter = sync.WaitGroup{}

	barContainer, err := multibar.New()
	if err != nil {
		return
	}

	for i := 0; i < hosts.Len(); i += 1 {
		bar := &Bar{
			size: controllerSize,
			setter: barContainer.MakeBar(
				controllerSize, fmt.Sprintf("HOST%03d:", i)),
		}
		bars = append(bars, bar)
		barsWaiter.Add(1)
	}

	go barContainer.Listen()

	for hostInf := range hosts.Iter() {
		host := hostInf.(string)

		resp, e := http.Get(
			fmt.Sprintf("http://%s:3800/close", host))
		if e != nil {
			err = e
			return
		}
		if resp.StatusCode != 200 {
			err = fmt.Errorf("BAD STATUS %d ON %s",
				resp.StatusCode, host)
			return
		}
	}

	barsWaiter.Wait()
	time.Sleep(1 * time.Second)
	fmt.Println("CLOSE COMPLETE")

	return
}
Exemple #6
0
func Stop() (err error) {
	barContainer, err := multibar.New()
	if err != nil {
		return
	}

	setter := barContainer.MakeBar(hosts.Len(), "STATUS:")
	go barContainer.Listen()

	time.Sleep(100 * time.Millisecond)
	setter(0)

	i := 0
	for hostInf := range hosts.Iter() {
		host := hostInf.(string)

		resp, e := http.Get(
			fmt.Sprintf("http://%s:3800/stop", host))
		if e != nil {
			err = e
			return
		}
		if resp.StatusCode != 200 {
			err = fmt.Errorf("BAD STATUS %d ON %s",
				resp.StatusCode, host)
			return
		}

		setter(i + 1)

		i += 1
	}

	time.Sleep(1 * time.Second)
	fmt.Println("STOP COMPLETE")

	return
}