A
A
AlikDex2015-11-07 23:41:00
Database
AlikDex, 2015-11-07 23:41:00

Saving counters from cache to database, algorithm?

So. The task is basically typical (it seems to me so).
Let's say we have 10,000 pages that are visited by a bunch of users, but not all of them, but half of them. We need to count visits per page. It is clear that you can increment the hit counter for each page directly in the database. But I want to do something a little differently, namely, first save the data on visits in a mesh or radish, and then periodically dump them into the database. I read that it's kind of cool, I decided to implement it. But after scratching a little turnip came to the conclusion that I can not understand how it's done. Those. the solution in the forehead - to take data from the cache, then reset it does not seem so effective and there is a possibility of losing this data in case of some kind of failure. Here is the question. What other options might be available to resolve this issue? (also applies to all sorts of likes, ratings and other clickable)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Walt Disney, 2016-02-18
@ruFelix

1) you can simply execute cron into a console command like cut access.log -d' ' -f 7 | sort | uniq -c and dump the result into the database.
2) the memcache will not be convenient, sooner or later it will start deleting the accounts itself, due to a timeout or lack of memory, and this must be borne in mind, respectively, and the solution must be designed for losses. Those. for example, if the key is empty in the memcache, then we take the value from the database and put it in it, we also use the value from the memcash for display, when requesting the page, we increment the key in the memcash. But the value in the database is updated, for example, from the method described in the first paragraph. Accordingly, playing with the lifetime of entries in the memcache and the frequency of parsing logs, we will adjust possible lags in the counter values.
3) log parsing can be replaced with queues like rabbitmq
4) in most cases, you can not take a steam bath and take out the counters in redis.io

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question