Solved

How do I find out why Apache is grabbing a lot of my memory?

Posted on 2007-11-21
6
271 Views
Last Modified: 2013-12-15
How do I figure out why Apache will go from around 17M per process to 200-300M each?  This happens when I delete a MySQL Query that seems to be running too long!  

If I delete a single MySQL query then I will notice a single http process will grow in size.  If I stop MySQL then I notice that all http process start growing in size.

Here is output from the linux "top" command before and after.  As you can see ALL 4GB of memory gets used and ALL 2GB of Swap.  The system then becomes unresponsive.   I have to do a reboot because this will happen so quick that I'm not able to stop any of the http processes.

BEFORE

top - 11:38:23 up 9 min,  1 user,  load average: 7.93, 5.12, 2.47
Tasks: 137 total,   2 running, 135 sleeping,   0 stopped,   0 zombie
Cpu(s): 17.8% us,  1.6% sy,  0.0% ni, 44.7% id, 35.9% wa,  0.0% hi,  0.0% si
Mem:   4148584k total,  1295320k used,  2853264k free,     6508k buffers
Swap:  2096472k total,   144676k used,  1951796k free,   223304k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2361 mysql     15   0 1558m 641m 4516 S 71.2 15.8   4:30.28 mysqld
 3491 apache    16   0 23136  15m 3640 S  0.0  0.4   0:00.46 httpd
 3519 apache    15   0 23228  15m 3492 S  0.0  0.4   0:00.35 httpd
 3477 apache    16   0 22368  14m 3628 S  0.0  0.4   0:00.85 httpd
 3498 apache    16   0 22236  14m 3616 S  0.0  0.4   0:00.95 httpd
 3500 apache    15   0 22116  14m 3652 S  0.0  0.4   0:00.48 httpd
 3475 apache    15   0 22112  14m 3664 S  0.0  0.4   0: 00.70 httpd
 3511 apache    15   0 22060  14m 3564 S  0.0  0.3   0:00.38 httpd
 3484 apache    16   0 21936  13m 3568 S  0.0  0.3   0:00.35 httpd
 3490 apache    17   0 21952  13m 3392 S  0.0  0.3   0:00.21 httpd
 3487 apache    15   0 21676  13m 3644 S  0.0  0.3   0:00.37 httpd
 3481 apache    16   0 21676  13m 3628 S  0.0  0.3   0:00.53 httpd
 3485 apache    15   0 21536  13m 3568 S  0.0  0.3   0:00.33 httpd
 3468 apache    16   0 21428  13m 3596 S  0.0  0.3   0:01.13 httpd
 3470 apache    15   0 20152  12m 3580 S  0.0  0.3   0:00.47 httpd
 3472 apache    17   0 20140  12m 3568 S  0.0  0.3   0:00.76 httpd
 3476 apache    15   0 20000  12m 3616 S  1.3  0.3   0: 00.58 httpd
 3479 apache    16   0 19960  12m 3568 S  0.0  0.3   0:00.17 httpd
 3512 apache    15   0 19960  12m 3580 S  0.0  0.3   0:00.28 httpd
 3515 apache    15   0 18892  11m 3592 S  0.0  0.3   0:00.46 httpd
 3463 apache    16   0 18848  11m 3592 S  0.0  0.3   0:00.44 httpd



AFTER

top - 12:34:11 up  1:05,  1 user,  load average: 77.85, 26.91, 11.29
Tasks: 200 total,  26 running, 173 sleeping,   0 stopped,   1 zombie
Cpu(s): 20.0% us, 80.0% sy,  0.0% ni,  0.0% id,  0.0% wa,  0.0% hi,  0.0% si
Mem:   4148584k total,  4134260k used,    14324k free,      324k buffers
Swap:  2096472k total,  2096456k used,       16k free,    16308k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2361 mysql     15   0 1250m 593m 4300 S  0.0 14.6  44:57.33 mysqld
 5512 apache    16   0  332m 231m 3532 R 13.4  5.7   0:12.28 httpd
 5530 apache    16   0  230m 157m 3416 R  7.7  3.9   0:08.75 httpd
 5722 apache    18   0  186m 123m 3296 R  0.0  3.0   0:01.29 httpd
 5511 apache    16   0  235m  91m 3528 D  0.0  2.2   0:09.52 httpd
 5574 apache    16   0  167m  73m 3560 D  0.0  1.8   0:07.97 httpd
 5569 apache    15   0  159m  70m 3528 D  0.0  1.7   0:06.33 httpd
 5571 apache    16   0  128m  67m 3528 D 17.6  1.7   0:11.57 httpd
 5538 apache    16   0  133m  62m 3532 D  0.0  1.5   0: 09.51 httpd
 5607 apache    15   0  133m  61m 3528 D  0.0  1.5   0:07.86 httpd
 5729 apache    20   0 99.3m  61m 3224 R  0.0  1.5   0:01.14 httpd
 5572 apache    16   0  150m  60m 3400 R  6.3  1.5   0:10.50 httpd
 5727 apache    18   0 97.7m  55m 3184 R  0.0  1.4   0:01.33 httpd
 5728 apache    18   0 96392  54m 3184 R  0.0  1.3   0:01.75 httpd
 5577 apache    15   0  105m  54m 3544 D  0.0  1.3   0:03.18 httpd
 5548 apache    15   0 93740  52m 3536 D  0.0  1.3   0:04.34 httpd
 5501 apache    15   0  105m  51m 3528 D  0.0  1.3   0:07.27 httpd
 5556 apache    16   0 97256  50m 3508 D  0.0  1.3   0:06.41 httpd
 5518 apache    16   0 96932  49m 3544 D  0.0  1.2   0: 07.82 httpd
 5594 apache    16   0  103m  49m 3524 D  0.0  1.2   0:05.08 httpd
 5522 apache    16   0 92216  48m 3404 D  0.0  1.2   0:02.95 httpd
 5608 apache    15   0 67084  48m 3552 D  0.0  1.2   0:08.82 httpd
 5636 apache    16   0 79688  47m 3528 D  0.0  1.2   0:07.52 httpd
 5504 apache    16   0 94264  44m 3532 D 10.6  1.1   0:08.94 httpd
0
Comment
Question by:michaelchunn
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:terrydavis
ID: 20330219
What is the application calling mysql?  The application (php/perl/java) must not know how to handle this type of exception and is running away.
0
 

Author Comment

by:michaelchunn
ID: 20330512
php is making the mysql call.
0
 
LVL 2

Expert Comment

by:terrydavis
ID: 20330591
I would attack the problem from that angle.  Is it a custom application?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:michaelchunn
ID: 20330744
Nope.  I just have a web application that is being served via apache.  The web app is making mysql calls.  Why would apache grow so large.  Why would apache need the memory?  What would it be doing with it?
0
 
LVL 2

Accepted Solution

by:
terrydavis earned 500 total points
ID: 20330885
PHP, which runs inside of apache, is running code that is consuming all of the memory on your server.  The fact that this only happens when you kill a query on the mysql side leads me down this path.  
0
 
LVL 28

Expert Comment

by:Jan Springer
ID: 20331215
Have you tried mod_leak?
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now