Answer the question
In order to leave comments, you need to log in
Why the increased memory consumption on VPS?
Good afternoon, there was some problem on the VPS used, maybe someone will tell you the most correct solution.
There is a script for uploading images by users (assumed up to 10Mb), uploading occurs
through AJAX in the background, 1 file at a time. Up to this point, everything works well and beautifully. After the applause, images are cropped, thumbnails are created and a watermark is applied using
Imagick extensions and the graph of memory consumption in the hosting panel grows in steps, there were even two VPS crashes with errors in the log like: Cannot allocate memory: fork: Unable to fork new process and PHP Fatal error: Out of memory (allocated 262144) (tried to allocate 261900 bytes) in Unknown on line 0. At this moment the tariff plan included 512 Mb (1024 Mb burst). The server crashed when reaching a gigabyte. Also, from time to time, the applause operation for rather large files of 5-7 MB ended with a POST error in the browser console.
On the advice of the hoster, an upgrade was made to 1024 Mb (2048 Mb burst) and the files began to be applauded and processed without errors, but the memory still grows after each session of downloading files (5-7 pieces) and does not decrease afterwards. One gets the feeling that sooner or later it will reach the limit and everything will collapse. This is on the condition that there has not yet been a release of the project and the files are applauded by 1 person.
Actually a question: in what there can be a problem?
In using imagick or configs? There is an option to pick up the configs, but it's not very clear yet what exactly. Thinking about maxrequestsperprocess, maxprocesses and setting ulimit -s 1024. Or looking for an imagick alternative?
Thanks in advance to all who respond.
Answer the question
In order to leave comments, you need to log in
You have openvz with incorrectly configured memory limits. Just move to any Xen/KVM virtual machine - digitalocean, flops, for example.
Finding an openvz host with the correct memory limits will be more difficult.
Thank you for your answer, at the moment everything is on IntoVPS, which was chosen after a number of positive reviews read. I chose between him and Hetzner. Is it easier to leave than to deal with and agree with the hoster and its settings?
A small test report on Digitalocean. I took 512MB and uploaded the scripts. I perform similar actions - the picture applauds, after which the script makes a crop and creates two thumbnails using the Imagick extension. I look at the memory in a way known to me through free -m.
Memory state before the script was running:
total used free shared buffers cached
Mem
: 495 218 276 0 2 127
-/+ buffers/cache: 89 406
Swap: 0 0 0
-m.
At the moment of loading the file, nothing really changes, after loading, my crops and resizes obviously start working, the memory jumps sharply to a peak value of 486 MB.
used free shared buffers cached
495 490 5 0 2 263
224 271
0 0 0
And also drops sharply. At the moment, after some time of the script, the memory level is like this.
total used free shared buffers cached
495 103 392 0 0 18
84 411
0 0 0
Digitalocean does not have graphics for memory, so I cannot boast of a beautiful picture, but I see the situation with memory differently than on IntoVPS.
Profile the application by memory consumption and see who or what was eating it.
Several sessions of downloading files ate and 2 GB for an hour last night.
You can see it on the chart. Memory consumption is still at this level.
@rivalsm
Read my answer to High Memory Consumption on VPS
Your application may mishandle memory (not release it or otherwise behave incorrectly), but Linux has long been able to handle such situations on its own. As a last resort - there is always OOM, which will kill -9 part of the processes and the memory will appear again. Cannot allocate memory means that your virtual machine does not actually have the specified amount of _physical_ memory.
Move to kvm first, then keep tinkering with the application.
The situation "all memory is busy" is absolutely normal, and this is not a reason for "Cannot allocate memory" when forking.
Results of working with memory from monitorix. In a place where a continuous rise is visible, successive applause was made for a certain period of time.
In general, it can be seen from free that the level of free memory minus buffers and caches
remains at approximately the same level of 390-400 megabytes, from which we can assume
that the IntoVPS hoster had a problem. Apparently, Vlad @inkvizitor68sl turned out to be right, for which many thanks to him, otherwise I had already started to tear my hair out of my head and was going to go to a fortuneteller to find out the causes of the problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question