Ejemplo n.º 1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	var config workload.Config
	workload.ReadConfig(&config)

	s := seriesly.SerieslyClient{}
	s.Init(config.SerieslyHostname, "sync_latency"+config.SerieslyDatabase)

	c := api.SyncGatewayClient{}
	c.Init(config.Hostname, config.Database)

	user := api.UserAuth{"collector", "password", []string{"stats"}}
	c.AddUser(user.Name, user)
	session := api.Session{Name: user.Name, TTL: 2592000}
	cookie := c.CreateSession(user.Name, session)
	c.AddCookie(&cookie)

	activeSamplers = 0
	for doc := range workload.DocIterator(0, DocsPerUser, config.DocSize, "stats") {
		if activeSamplers < MaxSamplers {
			activeSamplers++
			go measureLatency(&c, &s, doc)
		}
		time.Sleep(time.Duration(1000) * time.Millisecond)
	}
}
Ejemplo n.º 2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	var config workload.Config
	workload.ReadConfig(&config)

	admin := api.SyncGatewayClient{}
	admin.Init(config.Hostname, config.Database)

	users := [][]interface{}{}
	for user := range workload.UserIterator(config.NumPullers, config.NumPushers) {
		cookie := createSession(&admin, user, config)
		users = append(users, []interface{}{user, cookie})
	}

	rampUpDelay := config.RampUpIntervalMs / (config.NumPullers + config.NumPushers)
	rampUpDelayMs := time.Duration(rampUpDelay) * time.Millisecond
	wg := sync.WaitGroup{}
	for _, user := range users {
		wg := sync.WaitGroup{}
		go runUser(user[0].(workload.User), config, user[1].(http.Cookie), &wg)
		wg.Add(1)
		time.Sleep(rampUpDelayMs)
	}

	if config.RunTimeMs > 0 {
		time.Sleep(time.Duration(config.RunTimeMs-config.RampUpIntervalMs) * time.Millisecond)
		log.Println("Shutting down clients")
	} else {
		wg.Wait()
	}
}