简体   繁体   English

排队更新请求以进行大更新?

[英]Queuing update requests for a giant update?

I have a site, and when the user does an action I wish to add that to a count of how many actions the person has ever done. 我有一个网站,当用户执行某项操作时,我希望将其添加到此人曾经执行过的操作数中。 Naturally I'd say "update the user table each time!" 当然,我会说“每次更新用户表!” but I don't feel as if that's a good solution, and I'm interested in seeing if there is a way to do this. 但我觉得这不是一个很好的解决方案,我很想知道是否有办法做到这一点。

Basically the user would log in and start using actions, and every time they make an action I would do [whatever] and then at the end of the day, I take all [whatever]s and make the query, saving resources on each action. 基本上,用户会登录并开始使用操作,并且每次他们执行一个操作时,我都会[执行],然后在一天结束时,我会执行所有[所有操作]并进行查询,从而节省了每个操作的资源。 Were the site to grow to 1,000 users, those little queries would start adding up! 如果站点增加到1,000个用户,这些小查询就会开始加起来! There is only one type of "action", for the sake of this question just assume each page load would be an action. 仅存在一种类型的“动作”,出于这个问题,只需假设每个页面加载都是一个动作即可。

if its a single session, store (queue) "all the updates" in a session / global variable. 如果是单个会话,则将“所有更新”存储(排队)在会话/全局变量中。 Update at the end of the session. 在会话结束时进行更新。

if its a multiple-session system, I would suggest doing the above and update the table at the end of each session. 如果它是一个多会话系统,我建议您执行上述操作,并在每个会话结束时更新表。

:(upwards of few hundred kbs, this is not a good idea): :(超过几百kbs,这不是一个好主意):

You would want to make a shortcode endcoing /decoding library to store it into the sessions vars. 您可能需要制作一个简码结束代码/解码库,以将其存储到会话vars中。 If we are talking about huge data. 如果我们在谈论海量数据。 For example, if you have a drag and drop system, the intermediate states could be key<>val pair structures. 例如,如果您有一个拖放系统,则中间状态可以是key <> val对结构。 eg: LOC_A=WIDGET_1 ; 例如:LOC_A = WIDGET_1; LOC_B=WIDGET_88 .. so on and so forth.. LOC_B = WIDGET_88 ..依此类推。

is this making sense? 这有意义吗?

Don't discount keeping an action event table. 保留动作事件表不要打折扣。 Unless you have very high user action rates it may easily be reasonable to query and count action events rather than accumulating totals somewhere. 除非您的用户操作率很高,否则查询和计算操作事件而不是在某个地方累计总数可能很容易。 An index can provide single-block read access to several hundred or thousand events with a reasonable design. 索引可以通过合理的设计提供对数百或数千个事件的单块读取访问。 Developers often can be intimidated by table sizes for stuff like this that are actually quite reasonable. 对于这样的东西,实际上相当合理的表大小经常会吓到开发人员。 IME a table size of several GB is not a problem for MYSQL as long as the table is write-only. IME只要MySQL表是只写的,几张表的大小对于MYSQL来说不是问题。

As usual, testing several options is the best idea, and expect to be surprised. 像往常一样,测试几个选项是最好的主意,并且会感到惊讶。

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

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