high memory and mysql disconnecting issues


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?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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.

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.