high memory and mysql disconnecting issues

Posted November 30, 2017 6.5k views


I careated LEMP 512MB droplet with ubuntu 17.04 and php 7.1. and i uploaded my laravel project on it.
i see high memory usage between 85% and 95%, after that I upgraded the droplet to 1GB.

after that i make swap to enable me to install Redis.

Now i face 2 problems:
First one is memory is still high. there are 2 attached images appear this issue with top process in memory.

Image 1 link

Image 2 link

Second problem mysql is disconnect usually and can’t restart mysql, i reboot the droplet to re work.
this problem related with cannot connect to mysql (DB_SOCKET=/var/run/mysqld/mysqld.sock).
how i can solve those?

1 comment
  • @kamaln7 @emestee @alastairc

    Thank you for reply and assistance.

    I like to tell you, I found the mistake in high memory, and I need your suggestion.

    I make crontab to run queue:work in laravel

    * * * * * /usr/bin/php7.1 /var/www/html/artisan schedule:run >> /dev/null 2>&1

    I comment it since 3 hours, here is a screen shot of droplet status:

    Droplet Status

    Now, how i can run queue:work in laravel without errors?


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

If the php process is taking up way too much RAM, it’s possible that your code has a memory leak of some sorts. I would suggest using to profile your application’s memory usage and see what’s taking up so much RAM.

  • Sorry for late in reply, but I want to give you a biggest thanks on your reply, I installed debugbar and I reduced all User-Side queries (in one page from 59 to 14 queries).

    Yesterday, I upgrade the droplet to 3 GB RAM after reducing queries. But also mysql is crashed today.

Examine dmesg and log files for signs of mysql crashing. Very likely it’s killed for out of memory errors.

Post memory profile like the output of free(1).

Ensure you have swap enabled.

In my experience at least 2Gb RAM is required for running PHP-FPM in production along with mysql/redis.

As another option you could run mysql on a second droplet and enable local networking for both of them. That way when your php application hogs too much memory the OOM killer will only murder your webserver workers and not your mysql database. (You’ll have to connect to your database via tcp instead of unix sockets though).

As a plus you can also increase the size of each droplet as each sides needs grow, rather than hoping they don’t step on each others’ toes, there’s also less risk of mysql losing data when it’s randomly killed.