Basic performance. Make Drupal fly. Part I
Hello! Let's talk about the performance of the popular CMS / CMF Drupal, namely the 7th version.
Many less experienced users blame Drupal for being slow. Like, for every request Drupal is always loaded in its entirety, loading all-all-all of its modules. In general, they may be right, Drupal has such a problem, but it can be solved.
In Drupal, almost all content that is intended for visitors is an entity, whether it be nodes, users, or taxonomy terms. Let's start with them.
We generate 1000 users using the devel_generate module , which is included in devel and measure the time of their loading from the database.
The example shows that this operation takes 30 seconds, which is actually not very good. Well, just for this case, Drupal has its own system for caching entities. Let's look at her at work.
When you restart, these users load in 2 seconds, well, well done Drupal, but it can be better.
Download and enable a couple of modules ( Entity cache and Memcache ).
The Entity cache module allows you to cache standard Drupal entities using the Cache API.
Memcache provides the ability to transfer cache care from MySQL to a Memcached server that stores data in RAM and therefore works faster with them.
And - success right away, the first launch is completed in just 2.8 seconds instead of 30. Let's move on.
A restart, in which data is retrieved from the Memcached server’s cache, takes 0.4 seconds. Pretty good compared to default caching in Drupal.
However, Memcached is not the only one, Redis can do such things .
Disable the Memcache module and install the Redis module .
The first launch is long again, because the cache is first formed. The result is 2.2 seconds, while this is the best result.
Thus, we achieved a performance increase of 13 times in the case of the first launch and 5 times in the case when data is taken from the cache.
Unfortunately, hosting does not always have the ability to install an additional Memcached or Redis server. In this case, you can do only the Entity cache module.
The first request takes quite a while. This is again due to cache generation.
But all subsequent ones are completed in less than a second.
From this we can conclude that the Entity cache module is a must have module on any Drupal site. Based on the capabilities, it can be supplemented with Redis.