• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang api.SyncGatewayClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pavel-paulau/gateload/api.SyncGatewayClient的典型用法代码示例。如果您正苦于以下问题:Golang SyncGatewayClient类的具体用法?Golang SyncGatewayClient怎么用?Golang SyncGatewayClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SyncGatewayClient类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

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()
	}
}
开发者ID:pavel-paulau,项目名称:gateload,代码行数:32,代码来源:main.go


示例2: createSession

func createSession(admin *api.SyncGatewayClient, user workload.User, config workload.Config) http.Cookie {
	userMeta := api.UserAuth{Name: user.Name, Password: "password", AdminChannels: []string{user.Channel}}
	admin.AddUser(user.Name, userMeta)

	session := api.Session{Name: user.Name, TTL: 2592000} // 1 month
	return admin.CreateSession(user.Name, session)
}
开发者ID:pavel-paulau,项目名称:gateload,代码行数:7,代码来源:main.go


示例3: main

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)
	}
}
开发者ID:pavel-paulau,项目名称:go-cbagent,代码行数:27,代码来源:main.go


示例4: runUser

func runUser(user workload.User, config workload.Config, cookie http.Cookie, wg *sync.WaitGroup) {
	c := api.SyncGatewayClient{}
	c.Init(config.Hostname, config.Database)
	c.AddCookie(&cookie)

	log.Printf("Starting new %s (%s)", user.Type, user.Name)
	if user.Type == "pusher" {
		go workload.RunPusher(&c, user.Channel, config.DocSize, user.SeqId, config.SleepTimeMs, wg)
	} else {
		go workload.RunPuller(&c, user.Channel, user.Name, wg)
	}
}
开发者ID:pavel-paulau,项目名称:gateload,代码行数:12,代码来源:main.go


示例5: RunPusher

func RunPusher(c *api.SyncGatewayClient, channel string, size, seqId, sleepTime int, wg *sync.WaitGroup) {
	defer wg.Done()

	for doc := range DocIterator(seqId*DocsPerUser, (seqId+1)*DocsPerUser, size, channel) {
		revsDiff := map[string][]string{
			doc.Id: []string{doc.Rev},
		}
		c.PostRevsDiff(revsDiff)
		docs := map[string]interface{}{
			"docs":      []api.Doc{doc},
			"new_edits": false,
		}
		c.PostBulkDocs(docs)
		time.Sleep(time.Duration(sleepTime) * time.Millisecond)
	}
}
开发者ID:pavel-paulau,项目名称:gateload,代码行数:16,代码来源:workload.go


示例6: RunPuller

func RunPuller(c *api.SyncGatewayClient, channel, name string, wg *sync.WaitGroup) {
	defer wg.Done()

	lastSeq := fmt.Sprintf("%s:%d", channel, int(math.Max(c.GetLastSeq()-MaxFirstFetch, 0)))
	lastSeq = readFeed(c, "normal", lastSeq)

	checkpointSeqId := int64(0)
	for {
		timer := time.AfterFunc(CheckpointInverval, func() {
			checkpoint := api.Checkpoint{LastSequence: lastSeq}
			chechpointHash := fmt.Sprintf("%s-%s", name, Hash(strconv.FormatInt(checkpointSeqId, 10)))
			c.SaveCheckpoint(chechpointHash, checkpoint)
			checkpointSeqId += 1
		})
		lastSeq = readFeed(c, "longpoll", lastSeq)
		timer.Stop()
	}
}
开发者ID:pavel-paulau,项目名称:gateload,代码行数:18,代码来源:workload.go


示例7: readFeed

func readFeed(c *api.SyncGatewayClient, feedType, lastSeq string) string {
	feed := c.GetChangesFeed(feedType, lastSeq)

	ids := []string{}
	for _, doc := range feed["results"].([]interface{}) {
		ids = append(ids, doc.(map[string]interface{})["id"].(string))
	}
	if len(ids) == 1 {
		c.GetSingleDoc(ids[0])
	} else {
		for docs := range RevsIterator(ids) {
			c.GetBulkDocs(docs)
		}
	}

	return feed["last_seq"].(string)
}
开发者ID:pavel-paulau,项目名称:gateload,代码行数:17,代码来源:workload.go


示例8: measurePullLatency

func measurePullLatency(c *api.SyncGatewayClient, doc api.Doc) (int64, float64) {
	t0 := time.Now()
	c.GetSingleDoc(doc.Id)
	t1 := time.Now().Round(100 * time.Microsecond)
	return t0.UnixNano(), float64(t1.Sub(t0.Round(100*time.Microsecond))) / math.Pow10(6)
}
开发者ID:pavel-paulau,项目名称:go-cbagent,代码行数:6,代码来源:main.go



注:本文中的github.com/pavel-paulau/gateload/api.SyncGatewayClient类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang types.GenerateCodeLocation函数代码示例发布时间:2022-05-28
下一篇:
Golang geos.Geometry类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap