News for hackers. Stuff that matters.
Re:Efficient way to calculate active users by jacquesm on Wednesday June 11, 2014 @11:18AM (#7878431)
There is always a trade-off between speed and precision, this is why many systems that determine to figure out some value will resort to sampling and other tricks.

Another trade-off used is the space-speed one, which this article is an example of (and a very elegant one at that). If you want to use this then you're going to have to keep intermediate results around in some form.

If you want the best of both worlds (in even less space!) for this particular usecase you can find a pretty good medium by figuring out what the ratio of users:unique users is for some period, then just keep a single count per day, add for your desired period and divide by the ratio found earlier.

This will allow near instantaneous computation whenever the result is required and allows you to push the time-consuming portion of the computation to whenever the system is loaded lightly. The more frequently you compute the ratio the closer your result will be to the actual number.

Of course these are all approximations, if for some reason you require the exact number then you're going to have to simply do more work.

There are no comments on this comment yet.