ajay01's avatar

Production Server facing Out of the memory problem.

On my production server, I'm frequently facing memory problem. apache error log frequently logging this error.

856685.751702] Out of memory: Kill process 29946 (httpd) score 12 or sacrifice child
[856685.757737] Killed process 29946 (httpd) total-vm:585720kB, anon-rss:25324kB, file-rss:0kB, shmem-rss:72kB

In the Laravel Log file, I have this error is logging frequently.

[2021-01-29 07:10:45] local.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Out of memory (allocated 14680064) (tried to allocate 1052672 bytes) in /var/www/html/instacutportal/vendor/guzzlehttp/psr7/src/Stream.php:228
Stack trace:

I have some questions.

  1. Suppose somebody is using the system, they're logged in and doing stuff. When they're done, they close the browser tab without logging out. How does the server respond and release resources? Dose laravel handles it by itself?
  2. I have a file uploading feature where users can upload 200+ images, I'm storing it on an S3 bucket. The images are pass through the application server. dose there is some stage of an upload process where images or (parts of them at least) are stays in application server memory. Which seemed like it might be relevant for out of memory errors. in nutshell dose it store locally first?
0 likes
6 replies
Snapey's avatar
Snapey
Best Answer
Level 122

1.when a user visits your site, the request is processed and the result returned. The user does not occupy memory whilst they are 'logged in'. If another user connects, they will use the same memory that the first user was using. If a user closes their browser, nothing happens since PHP has no connection to the client and only uses RAM when the request is being processed.

You have a very small amount of ram (just over 128MB) so you should increase the memory size.

You should also profile your requests with something like Laravel debugbar to see how much memory is being used in each request.

2.Your images will be passing through your server unless you have taken specific steps to avoid it. If you receive a file and then send it to S3 then Yes, images could be taking up memory. PHP will have garbage collection to clear up memory that is no longer required, but you can preempt this by unsetting variables that you used and no longer need.

1 like
ajay01's avatar

Thanks, @snapey.

  1. I got your point.
  2. Can you suggest which steps should I take to avoid images passing through my server. Also is do you know any folder path where that images being placed before they being sent to the S3 bucket?

Please or to participate in this conversation.