Does caching always improve performance?

I have several sites with PHP and MySQL , MediaWiki especially works, and I need to improve performance. However, I only have a limited percentage of the processor that I am allowed to use.

The best I can think of to improve performance is to enable caching. However, I am confused: does this really improve overall performance or just increase speed?

I might think that if caching uses files, then more processing is needed to get the contents of these files. If he will use SQL tables, then processing these tables will require more processing, maybe the time will be shorter, but CPU usage will be more.

Is this right or wrong? Does caching consume more processor to get acceleration results or improves overall performance?

+7
source share
5 answers

At the most basic level, caching should be used to store the results of CPU intensive processes. For example, if you have a server-side image processor that creates an image "on the fly" (for example, a thumbnail and a larger view), you do not want this operation to be performed for each request - you want to start this process once and save results; Then, every other request gets a stored result.

This is obviously an extremely simplified description of basic caching, and using the image in this case is great, since you don’t have to worry about outdated data, that is, how often does the actual image change? In your case, the databases are very different. If you are caching data, then how can you guarantee that there will be no instant discrepancy between your data and the actual cached data? Querying a database is also not always a CPU intensive task (assuming you need to think about how the database is created in terms of indexing, table size, etc.), but in most cases a request for a well-designed database data is much more intense on disk I / O than it is in the processor cycle.

Firstly, you need to take a look at the database design and secondly, your queries. For example, you normalize your database correctly , your queries spend through a huge amount of data, when you can simply archive, whether you join tables to non-indexed fields, are your sentences that request fields that can be indexed ( IN in these cases especially harmful).

I recommend that you get a query analyzer and spend some time optimizing the structure of tables and queries to find this bottleneck before looking further at the radical changes.

+4
source

Link: http://msdn.microsoft.com/en-us/library/ee817646.aspx

Performance. Caching techniques are commonly used to improve application performance by storing relevant data as close to the data consumer as possible, avoiding the re-creation, processing, and transportation of data. For example, storing data that does not change, such as a list of countries in the cache, can improve performance by minimizing data access operations and eliminating the need to recreate the same data for each request.

Scalability. The same data, business functionality, and user interface fragments are often required by many users and processes in the application. If this information is processed for each request, valuable resources are lost, recreating the same result. Instead, you can store the results in a cache and reuse them for each query. This improves the scalability of your application, because as the user base grows, the demand for server resources for these tasks remains constant. For example, in a web application, the web server should display a user interface for each user request. You can cache the displayed page in the ASP.NET output cache, which will be used for future requests, freeing up resources for other uses.

Caching data can also help scale the resources of your database server. By storing frequently used data in the cache, fewer database queries are performed, which means that more users can be served.

Availability. Sometimes the services that provide information to your application may not be available. By storing this data elsewhere, your application will be able to survive system crashes such as network latency, web service issues, or hardware crashes. For example, every time a user requests information from your data warehouse, you can return information, as well as cache the results, updating the cache for each request. If the data warehouse becomes unavailable, you can still serve requests using cached data until the data warehouse returns to the network.

+1
source

You need to consult your eyes and find out where the bottle is narrowing. Cacheing is the best type of page load that doesn’t hit the server at all. You can create a very simple caching system that only reloads information in 15 minutes. So, if a page has been cached in the last 15 minutes, it gives them a pre-prepared page. A page loaded once creates a temporary file. every 15 minutes you create a new one (if someone loads this page).

Caching only saves the file that the server has already done work on. The job of creating the file is already done, and you just save it.

0
source

The terms "performance" and "speed" are used. I assume that "performance" refers to the processor cycles on your web server and that "speed" refers to the time it takes for the page to serve the user. You want to maximize web server performance (by reducing the total number of processor cycles needed to serve the pages), maximizing "speed" (by reducing the time it takes to serve a web page).

The good news for you is that caching can improve both of these at the same time. By caching the content, you create an output page that is cached, and you can re-submit it directly to users without having to re-run the PHP code that originally created this output page (thus reducing CPU cycles). Retrieving a cached page from a cache takes less CPU cycles than re-executing PHP code.

Caching is especially useful for web pages, which are usually the same for all users who request a page - for example, on a wiki and for pages that usually don't change too often - again, a wiki.

0
source

"Productivity Improvement" sounds like part of the email I receive ...

There are two interconnected things. One of them is “how long does it take to service this request?”, And the other is “how many requests can I serve at the same time taking into account my limited resources?”. People tend to use one or both of these concepts when talking about productivity.

Caching can help with both of these things.

The most effective caching strategy uses resources outside of your computers to cache your stuff. The most obvious examples are a custom browser or CDN. I assume that you cannot use CDN, but by spending a bit of effort setting the HTTP cache headers, you can significantly reduce the number of requests to your server for static or sluggish resources.

For dynamic content - usually the web page that you generate by querying your database - the next most effective caching strategy is to cache the HTML generated (in part) of your page. For example, if you have “the most popular elements” on the home page, this usually launches some rather complex database queries, and then some “HTML backlinks”. If you can cache HTML, you save both database queries and CPU efforts to turn data into HTML.

If this is not possible, you can cache the result of some database queries. This helps to reduce the load on the database and, as a rule, also reduces the load on your web server - the code necessary to run a query on the database and process the results is usually more burdensome that retrieving an item from the cache; because it’s faster, it allows you to process your request faster, which frees up resources faster. This reduces the server load for a single request and therefore allows you to serve more concurrent requests.

0
source

All Articles