使用Go、App Engine、专用Memcache和实例内存实现分片计数器

huangapple go评论69阅读模式
英文:

Implementing sharded counter using Go, App Engine, Dedicated Memcache and Instance Memory

问题

我们计划实现一个大规模扩展的后端系统,基本上需要在相当短的时间内(大约5分钟)计算数十万个最终用户的投票。

实现可能会在App Engine上进行,使用Go运行时和专用Memcache服务。也许,在投票期结束后,会使用Datastore来持久化计数器的值。

我们目前的架构想法和问题如下:

  • 我们计划使用实例内存来进行即时的每个请求计数。我们是否正确地认为,只使用Go全局变量实际上就是“使用实例内存”?

  • 我们计划在一个预定义的时间间隔内(例如每10秒或每250次增加)将每个实例的总计数器值(全局变量的值)存储到专用Memcache中。我们可能会对这些Memcache计数器进行分片,以避免对单个键/项的峰值负载。

  • 使用App Engine的定期作业,我们可能会将Memcache计数器持久化以供长期使用。

你认为呢?这样做有意义吗?这是一个好的方法吗?

英文:

We are planning to implement a massively scaling backend system which essentially has to count hundreds of thousands of end user votes within a pretty short amount of time (approx. 5 minutes).

The implementation will likely be done on App Engine, using the Go runtime and Dedicated Memcache service. Perhaps, Datastore will be used for persisting counter values after the voting period.

Our current architectural ideas and questions:

  • We plan to use instance memory for the immediate per-request-counts. Are we correct in assuming that just using a Go global variable actually translates into "using instance memory"?

  • We plan to store each instances total counter value (the value of the global variable) into Dedicated Memcache in a to-be-defined interval, e.g. every 10 seconds or on 250 increments. We possibly will shard these memcached counters to avoid peak load on single Key / Items.

  • Using an App Engine cron job, we might persist the Memcache counters for long term use.

What do you think? Does this make sense? Is this a good approach?

答案1

得分: 1

对于这样的情况,你可能想要使用任务队列机制(特别是拉取队列机制)。这将允许你在单个操作中处理(计数+提交)多个投票任务。这比使用实例内存更可靠,因为任务队列会在任务重新启动时保持存在。

英文:

For something like this, you probably want to use the <a href="https://developers.google.com/appengine/docs/go/taskqueue/">task queue</a> mechanism (in particular, the <a href="https://developers.google.com/appengine/docs/go/taskqueue/overview-pull">pull queue</a> mechanism). This would allow you to process (tally + commit) several vote tasks in a single operation. This is likely to be more reliable than using instance memory, since the task queue will outlive task restarts.

huangapple
  • 本文由 发表于 2014年2月18日 18:16:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/21850568.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定