If there are 1000 connected clients on the site requesting Mysql, then there are 1000 Mysql connections?
Not necessarily. Even if your database server supports a thousand connections simultaneously making requests, it would be a huge waste of resources if these requests were asking for equal data.
For example, if your site receives 1000 data requests over a certain period of time, it is likely that many different requests are asking for the same data. It is still very likely that during this period of time these data have not been modified.
Considering this, it becomes a waste of resources, consult the bank looking for something already consulted and that has not been changed.
The solution to this type of situation is the caching of data.
A database server with caching implanted, stores in memory the response of each new query as they are requested, so that a similar future request does not need to go to the database to retrieve the data. The data will already be available in memory and a new query only happens if a previously consulted data has been modified or if it has not been previously consulted and so is not in memory, is not in the cache.
Therefore, on a server with a caching deployed, 1000 requests means 1000 queries only if they ask for different data.
Remembering that the technique of
Cache / buffer
can also be a double-edged knife, since when bringing an entire block of data (for paging, for example) it is assumed that the user will consume this entire block, which is not necessarily true.– Kazzkiq
@Kazzkiq actually think I got a bad example, because the case of the.br record is a mixture of cache and prediction, if you like. I’ll think it over, and on the next Edit I put a pure example cache.
– Bacco
I found the example for good paging, it is a really useful thing, but speaking more in practice, it can be a shot in the foot. Look at Globo.com for example, the site’s comments all come together in a JSON block. Then you get news with up to 10,000 comments and imagine the trouble it takes for the bank to bring it all, when for sure users won’t even read 10% of it. Of course it’s an extreme example and they should have n ways to optimize requests, but it’s still worth studying each case before using this solution. Anyway, just a small addition to this great answer!
– Kazzkiq
@Kazzkiq agree, only I think the pagination I should have put in the example below, which is more the case. From the cache, it would have to be a pagination already seen, and not load the following (like globe and.br record). The cache would actually keep the data that has already been viewed, and not necessarily load the following (as well as a browser history). But I’ll think it over and move it only when I find clear examples.
– Bacco