A
A
Arkady2012-05-04 21:55:35
Algorithms
Arkady, 2012-05-04 21:55:35

How to organize a smart queue?

Implemented resizing images the other day, the user selects the size, presses the button, waits, receives the image.
I took into account such an option that if two users simultaneously select the same size of one image, the second one will queue up for the first and, as a result, receive the result of the first, that is, the server will change the size once and give the result to both.
Saving? Yes.
But the sleepy brain works differently, the thought is what if you do the same thing but only with database queries? Changed the code a bit and it works.
And indeed, it will be much faster (if you have a lot of simultaneous requests), it's like a cache only a little higher (c).
But the question is different, if this is implemented on nginx, only there are no longer images or database queries, we are talking about proxy_ or fastcgi_, how difficult or maybe just stupid?
PS Firefox works in a similar way, if you open two identical (by url) pages at the same time, the second one will be taken from the cache from the first one.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
VBart, 2012-05-05
@p0is0n

This is called cache lock:
nginx.org/r/proxy_cache_lock/ru
nginx.org/r/fastcgi_cache_lock/ru
etc…

A
avalak, 2012-05-04
@avalak

I didn't quite understand what you want, but nginx is a caching proxy and yes it can cache a page for a while and serve it out of the cache without disturbing the engine.
fastcgi_cache
It is only important to choose the right key and delete cookies.

S
Snowindy, 2012-05-05
@Snowwindy

Not sure about MySQL, but Oracle, for example, already does the job of caching frequent query data for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question