简体   繁体   English

在高流量 Web 开发中设计全局动作计数器

[英]Designing a global action counter in high traffic web development

We have a webapp that caters to hundreds of simultaneously logged in users (about 10K-30K users at any given time).我们有一个 web 应用程序,可以满足数百个同时登录的用户(在任何给定时间大约有 10K-30K 用户)。 The app collects analytics, specifically on certain user actions that may occur a few times a second.该应用程序收集分析,特别是针对每秒可能发生几次的某些用户操作。

So far our app design has been pretty decoupled (a lot of memcache/redis with delayed DB writes) and we avoided locks pretty well to make sure nothing is "centralized".到目前为止,我们的应用程序设计已经非常解耦(很多 memcache/redis 具有延迟的 DB 写入)并且我们很好地避免了锁以确保没有任何东西是“集中的”。

Management finally decided to build a real time analytics panel that should aggregate these actions in global counters (down to 1 second granularity).管理层最终决定构建一个实时分析面板,将这些操作汇总到全局计数器中(低至 1 秒的粒度)。 Whats the best way to have these "global" counters?拥有这些“全局”计数器的最佳方法是什么? We could increment some memcache key but we have a cluster of memcaches (EC2) so iterating over all of them to count up the keys would delay this metric.我们可以增加一些内存缓存键,但我们有一个内存缓存集群 (EC2),因此遍历所有内存缓存以计算键会延迟此指标。 DB is out of the question since we were bottlenecking alot in that regard so all DB writes are delayed thru a message queue (beanstalkd) DB 是不可能的,因为我们在这方面遇到了很多瓶颈,因此所有 DB 写入都通过消息队列 (beanstalkd) 延迟

Any tips would be highly appreciated.任何提示将不胜感激。

This would appear suited to a NoSQL dump of the actions, with periodic agregation.这似乎适合具有定期聚合的操作的 NoSQL 转储。 And being on EC2, you're in the right place to have access to the tools you need.在 EC2 上,您就可以访问所需的工具。

You could avoid your existing webserver infrastructure entirely by setting up a secondary webserver to record all the actions, pumping into a separate database server.您可以通过设置一个辅助网络服务器来记录所有操作,将所有操作注入到单独的数据库服务器中,从而完全避免使用现有的网络服务器基础设施。 Or if not appropriate, share the webserver but still offload to a separate NoSQL server.或者,如果不合适,共享网络服务器但仍卸载到单独的 NoSQL 服务器。

Then, if "real time" can be delayed by a small period (seconds or a few minutes), you can have a sweeper function that agregates the NoSQL table into a format that more suits the analytics system, and pumps into your "live" database and clears out NoSQL data that has been processed.然后,如果“实时”可以延迟一小段时间(几秒或几分钟),您可以拥有一个清扫器功能,将 NoSQL 表聚合为更适合分析系统的格式,并注入您的“实时”数据库并清除已处理的 NoSQL 数据。

Alternatively, you may be able to get your stats directly from the NoSQL?或者,您可以直接从 NoSQL 获取统计信息吗?

NoSQL may be as fast as using Memcached (various benchmarks report various results, depending on who wrote the report) but it'll certainly be faster in pulling the data together when you need to agregate. NoSQL 可能与使用 Memcached 一样快(各种基准报告会报告各种结果,具体取决于报告的编写者),但是当您需要聚合时,它肯定会更快地将数据拉到一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM