Best way to implement global counters for highly concurrent applications?

前端 未结 9 1189
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 02:07

What is the best way to implement global counters for a highly concurrent application? In my case I may have 10K-20K go routines performing \"work\", and I want to count th

9条回答
  •  悲&欢浪女
    2020-12-23 02:47

    Old question but I just stumbled upon this and it may help: https://github.com/uber-go/atomic

    Basically the engineers at Uber has built a few nice util functions on top of the sync/atomic package

    I haven't tested this in production yet but the codebase is very small and the implementation of most functions is quite stock standard

    Definitely preferred over using channels or basic mutexes

提交回复
热议问题