Question

Apache2 processes piling up to fill memory

Posted August 26, 2020 249 views
UbuntuApachePHPUbuntu 18.04

Hello,

I’m using the 5$ droplet with phpMyAdmin 1-click installation and serving a REST API over apache2.

Couple hours after I restart my apache service, when I use the following command to view processes that use the most memory:

ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | less

I see a lot of the same processes that over time piling up and never being killed, hence filling up the memory to about 90% :


%MEM %CPU   RSS    VSZ COMMAND

 2.9  0.2 30016 500080 /usr/sbin/apache2 -k start
 2.8  0.1 28420 498072 /usr/sbin/apache2 -k start
 2.8  0.0 28464 500084 /usr/sbin/apache2 -k start
 2.7  0.1 27696 498056 /usr/sbin/apache2 -k start
 2.7  0.0 27796 498052 /usr/sbin/apache2 -k start
 2.7  0.0 27512 499672 /usr/sbin/apache2 -k start
 2.7  0.0 27496 498060 /usr/sbin/apache2 -k start
 2.7  0.0 27332 279668 /lib/systemd/systemd-journald
 2.6  0.2 26956 498068 /usr/sbin/apache2 -k start
 2.6  0.2 26460 498068 /usr/sbin/apache2 -k start
 2.6  0.1 26616 498068 /usr/sbin/apache2 -k start
 2.6  0.1 26392 498048 /usr/sbin/apache2 -k start
 2.6  0.1 26340 497964 /usr/sbin/apache2 -k start
 2.6  0.1 26280 498032 /usr/sbin/apache2 -k start
 2.6  0.0 27116 494872 /usr/sbin/apache2 -k start
 2.6  0.0 26964 498004 /usr/sbin/apache2 -k start
 2.6  0.0 26296 497972 /usr/sbin/apache2 -k start
 2.6  0.0 26288 498068 /usr/sbin/apache2 -k start
 2.5  0.3 26168 498028 /usr/sbin/apache2 -k start
 2.5  0.3 25952 497976 /usr/sbin/apache2 -k start

As soon as I run “systemctl restart apache2” all of these processes disappear and my used memory decreases by a lot.

And idea about what is wrong with my server?

Thanks in advance.

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.

×
1 answer

Hi @hasancanboga,

Those are apache processes. Basically, people accessing your website/application. When you restart apache, you kill those processes since they are attached to the main Apache service. Basically you kill the sessions of your users. Having said that those can be malicious requests as well.

What you can try is to see the IP addresses which have accessed your application. You can view them and on which port they have connected, should be either port 80 or 443, with the following command :

netstat -punta

This command will show you the IP addresses accessing your server at the moment. If you see IP addresses from countries that generally shouldn’t be accessing your website/application, you can block them in IPtables.

Regards,
KFSys

  • Hi @KFSys,

    Thank you for the answer.

    That is not quite my concern though,

    My concern is that those processes should eventually be killed to free up memory. Because every request on my API gets processed under 100 milliseconds. But it looks like the processes are not being killed after several hours and my 1 GB memory gets used up to 90-95%.

    So I’m having to assign a crontab to restart apache every couple hours. Isn’t there a better way?

    • Hi @hasancanboga,

      Ah, I get it now. Okay, so they are not being killed for a reason. You’ll need to further investigate what is happening and why they are not being killed. In my experience, it can be another process that’s running and that’s holding up your Apache proceses. When there are so many apache processes and you run

      ps aux
      

      Do you see any other that has been running for as long as the apache ones?

      Regards,
      KFSys

Submit an Answer