📜 ⬆️ ⬇️

The first three steps to optimizing LAMP

There is an opinion that the LAMP bundle (Linux + Apache + Mysql + PHP) does not require any special configuration and works out of the box. Far from it. After I had been persuading a comrade to install a PHP caching accelerator xcache for a long time, I decided to conduct a small experiment and try to turn off xcache on my virtual server under a small load (about a hit per second). In real life, the load on the processor is small, but the memory is heavily loaded, because its a bit (256MB).

The results of the experiment exceeded all expectations. I think you can easily find the period when the cache was turned off on the graphs of the CPU and memory load.



')
After half an hour of experiments, the system got into a cruel swap and I could barely return the caching to the site:



This experiment, unfortunately, was not clean, since I set up Apache exactly for the existing configuration, and turning off the cache led to swapping. Xcache (like other PHP accelerators) allows you to save immediately and processor time, and memory, and disk access, keeping the intermediate code of PHP scripts in RAM. Despite the fact that the cache occupied 64MB bytes from me, its absence led to the growth of each of the work processes so that they got out of the physical memory.

We will take out three optimization lessons - one per component AMP:

1. Always configure Apache so that the execution of the command ab -n1000 -c100 yoursite / bigscript.php does not lead to a swap. To do this, read this article . Apache box plus scripts of moderate severity - the right way into the abyss with increasing load. Especially for memory limited VDS.
2. Always install a PHP accelerator. On conventional projects and CMS (Drupal / Joomla / WP) it will bring the acceleration of impact and reduction in the load on the processor by 2-4 times, as well as savings in RAM. Adjust the amount of cache sufficient to store active scripts (cache occupancy can be monitored).

The third lesson - turn on Query Cache in MySQL. It is graphically illustrated by the following schedule:

For more detailed MySQL tips, refer to the tuning-primer.sh script by running it on a live database.

The remaining measures (except for the optimization of the applications themselves) give a weaker effect, but they can save a lot more resources. If you are interested, I recommend reading these articles.

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


All Articles