📜 ⬆️ ⬇️

How caching will speed up your site



It seems that the word "caching" exists from the very beginning of the computer era. But what is it and how is it used in the work of sites?

Definitions and performance


If we proceed from the simplest definition, then the cache is a temporary storage space or temporary memory that allows for quick access to data. Caching is often classified by use case. Today, website developers use at least five main types of caches.

The first is object caching , in which application objects are stored locally for future use with future requests without having to contact the source server. The next one is database caching , which allows storing query data to a memory buffer to increase database speed. Caching bytecodes, such as using OPcache , increases the efficiency of PHP by saving precompiled scripts to shared memory. Thus, there is no need to download and parse PHP with each request. When caching the page , the results of the script are saved as an HTML file, which the web server can easily return immediately, without resorting to dynamic data retrieval again. Finally, when caching the distributed content, geographically distributed servers are used to increase download speeds.
')
Although the difference may seem insignificant, in fact, different ways of caching optimize the work of a particular site in different ways. A little later we will look at how some of them are used.

Power for performance


The caching mechanism depends on the hardware component on which it is applied. The faster the hardware, the faster the requested information is retrieved from the cache.

The slowest option is an ordinary hard disk, which processes 200 megabytes per second (MB / s) and performs 100 I / O operations per second (IOPS). A solid-state drive (SSD) transfers 600 MB / s and performs 300,000 IOPS — much better than an ordinary hard drive. But the SSD is losing compared to the speed of RAM: as much as 20 Gb / s and four million IOPS.

The speed of the cache, regardless of where the cache is cached, depends directly on the type of storage medium used. That is, to make your site work as fast as possible, you need new, fast equipment.

Caching and hosting selection


When choosing a hosting service for your site, it is necessary that it meets your needs in RAM. There is nothing wrong with hosting surpassing your requests, but if, on the other hand, it does not hold out for any indicators, this could have serious consequences for the performance of your site. Let's see how virtual hosting, dedicated server and virtual private cloud (VPC) differ in RAM resources, and how these differences affect the caching capabilities, and accordingly, the performance of the site.

Shared hosting


This is the most popular (and most economical) type of web hosting. With this option, a large number of sites are hosted on a single server connected to the network. Often there is a sub-type of virtual hosting - distributed hosting, which shares the needs of sites across all servers in a cluster, similar to the power grid (for example, Grid from Media Temple).

On a virtual hosting, the speed depends on the allocated amount of RAM and the type of media. You will not have amazing performance or full access to the system, but in the worst case you can count on 200 MB of RAM and storage on the SSD.

Dedicated server and virtual honest cloud


Although the dedicated and virtual private server (VPS) are called differently, they are similar in terms of caching, since both options offer priority access to the allocated resources.

Dedicated hosting provides a whole server with full access to it using Linux or Windows. As before, your choice should be made in favor of a larger amount of RAM (or at least according to your needs) and data storage based on SSD drives. SSD provides quick access to stored databases or pages of sites, based on various caching settings for RAM usage and web page delivery. One of the key points is that you can host your own virtual machines (VM) on a dedicated server - computer analogs that will work within the limitations of your web hosting.

On a VPS hosting, users get a separate virtual machine. The service provider reserves the necessary resources from its own network and shares them in a way that does not affect the underlying equipment. Like dedicated hosting, VPS has a variety of uses. You get full control over the resources and you can run several processes to maximize their use. As in other cases, RAM and the type of data carrier determine the speed of the site, as well as the type of caching used.

Power cdn


You can also speed up the site using the Content Delivery Network (CDN), which is additional to the hosting. CDN is a network of servers that allows web pages and other content to be delivered to users depending on their geographic location, source of the web page and the content delivery server closest to the user.



CDN - an intelligent solution to increase site loading speed. As web resources are transferred to a server located close to the user, a CDN saves invaluable milliseconds by caching images, videos, downloaded files, JS, CSS, and even HTML.

Choosing the right CDN is not easy. I advise you to pay attention to such companies as cedexis , publishing free useful statistics that will help in choosing the right CDN for your requirements.

Case Study: Media Temple Enterprise WordPress


This year we launched Enterprise WordPress , a new enterprise-level service for WordPress. It combines the hosting management of WordPress, Amazon Web Services (AWS), round-the-clock technical support and management of a dedicated account. Enterprise WordPress uses a variety of different caching methods, which guarantees users the highest speed of cloud hosting. In general, we follow the general scheme:



Almost every type of caching mentioned by us is used to optimize sites on Enterprise WordPress. First, the MySQL server is configured to improve database caching. Object caching is performed on separate servers, completely in RAM. Secondly, PHP scripts are cached in shared memory via OpCache, which means that there is no need to reload the script for each request. In addition, the page is cached on a proxy server and on individual servers completely in RAM, so that on request it is possible to deliver entire HTML files. Finally, to ensure that site users receive data from the nearest server, a CDN is used to deliver and store all static content.

The combination of several levels of caching ensures not only fast delivery of data, but also the possibility of simultaneously finding a large number of users on the site. Who said that it would not be possible to immediately kill two birds with one stone?

Core caching plugins


Fortunately, there are already a lot of plug-ins that will help optimize the speed of your sites. Below are some of their most popular:


Have questions or tips related to caching? Write in the comments!

HOSTING.cafe offers tools for searching virtual and dedicated servers, shared hosting and SSL certificates.

Source: https://habr.com/ru/post/327504/


All Articles