The post has been translated automatically. Original language: Russian
One of the most common questions after starting a new project sounds very simple.:
"How much memory should I allocate to the VM?"
There is no universal answer. The same volume may be excessive for a corporate website and insufficient for a database.
Therefore, after some time after launch, it is better not to guess, but to see how the system uses the allocated resources.
There are several signs that are really worth paying attention to.
The first sign is that the memory is almost always fully occupied.
If there is very little free memory left, and the system regularly starts using the swap partition, this is already a reason to figure out the reasons. It is not always necessary to immediately increase the amount of RAM, but you should not ignore this situation.
The second sign is that the response time has increased significantly after the load has increased.
For example, a website runs fast in the morning, but starts to slow down in the afternoon when more visitors arrive. Sometimes the reason turns out to be in the application or database, but lack of memory is also quite common.
The third sign is that the system itself has changed in recent months.
New services have been added.
The database has increased.
Additional modules have been added.
If the VM has started to perform more tasks, its initial configuration may no longer match the actual load.
There is also a reverse situation.
Sometimes the memory is increased immediately after the first signs of slowing down, without checking the rest of the indicators.
In practice, this does not always help.
If the problem is related to a slow disk, an unsuccessful database query, or an error in the application, the extra gigabytes won't change anything.
That is why it is better to make any changes after analyzing the monitoring, rather than feeling it.
Modern cloud platforms allow you to increase the amount of memory quickly enough.
It is much more difficult to determine the moment when it is really necessary.
If you focus not on assumptions, but on the actual performance of the system, the solution usually turns out to be much more accurate.
Иногда владелец сайта видит, что на сервере остается несколько гигабайт свободного места, но при этом перестают загружаться изображения, не создаются новые файлы или начинают появляться странные ошибки.
На первый взгляд это выглядит нелогично.
Причина может быть совсем не в свободном месте.
Что происходит на самом деле
Помимо объема диска существует еще один ресурс — количество файлов, которое может хранить файловая система.
Даже небольшой сайт способен со временем накопить сотни тысяч кэш-файлов, миниатюр изображений, журналов и временных данных.
Когда этот лимит заканчивается, создание новых файлов становится невозможным, хотя свободное место на диске еще есть.
Как это проявляется
Проблема редко возникает сразу во всем проекте.
Сначала могут перестать загружаться изображения.
Потом начинают работать нестабильно отдельные функции сайта.
И только позже становятся заметны более серьезные ошибки.
Что полезно проверять
Если сайт неожиданно начинает вести себя нестабильно, стоит посмотреть не только на свободное место.
Полезно также проверить:
- Количество файлов на диске.
- Размер каталогов с кэшем.
- Старые журналы, которые уже не нужны.
- Временные файлы, оставшиеся после обновлений.
Иногда очистка нескольких каталогов полностью решает проблему без увеличения объема диска.
Вместо вывода
Свободные гигабайты показывают только часть картины.
Иногда именно количество файлов становится тем ограничением, которое неожиданно влияет на работу сайта, хотя место на диске еще далеко не закончилось.