N
N
Northern Lights2021-03-31 03:20:53
PHP
Northern Lights, 2021-03-31 03:20:53

Parallel queries to the DBMS during the absence of the write cache - which algorithm?

I can not find information on this topic, I found only one article :

If there is a request that takes 10 seconds to complete, the ttl for its cache is 1 hour.

When this time passes, the data in the cache is deleted.

In the first 10 seconds after that, a situation occurs when several users simultaneously call this request. This can be disastrous, as there may be several hundred or thousands of such calls within 10 seconds.

To avoid this, it is necessary to use a special duplication technique. For each heavy request, not one, but two keys are created - ttl and ttl +10 sec.

At the moment when data is deleted in the cache, you must first write the value from the spare to the main key, and only then proceed to execute the SQL query.
The problem is described, but the solution is not clear, because confuses the phrase " At the moment when the data is deleted in the cache, you must first ... ".

First. The cache can be deleted by memcached itself after the expiration of time, and there is simply "no one" to apply the above algorithm.
Second. I'm not deleting cache data from the client code, it's all assigned to memcache, to the expire value of the data element, and I don't know when the data from the cache will be deleted. I suppose that here we are talking about the fact that under "data deletion" a certain CRUD of data is initiated, i.e. CRUD should initiate the above process.

But I don’t want to do this at the CRUD level, i.e. I do not want the cache to change on this event, ideally - just on the set expire value.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
rPman, 2021-03-31
@php666

The problem is not in the cache and its expiration, the problem is in the generation of content when there is no data in the cache or when it needs to be regenerated when the data changes.
Definitely, it is necessary to catch this situation and stop the generation of content on all pages except one, literally - 'slow down to move faster'.
Implementation option - a method in which content is generated using an in memory key-value database (probably better not memcached, since it does not guarantee the safety of data, although if you administer with an eye to this, why not, you can suggest adding a certain value to memcache before the start of generation, and check for it), marks the beginning and end of this process, with a link to the identifier of this data (for example, a website page), i.e. the record appears only for the time of data generation, and if there is a record, it slows down the process.
It would be logical not to do a random sleep for this, but to wait for an event from a neighboring process, ideally using this database

R
Rsa97, 2021-03-31
@Rsa97

https://habr.com/ru/post/43540/

L
Lazy @BojackHorseman PHP, 2021-03-31
Tag

this is called the dogpile effect and is treated by warming up the cache

The cache can be deleted by memcached itself after the expiration of time.

fail! the cache should only expire if the data has changed. otherwise, caching efficiency is reduced by a noticeable fraction of %%.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question