4

I use Amazon EC2 large instance (Memory 7.5 GB) for my http server. Recently I noticed my ssh commands running slow so I checked the memory usage.

free -t -m
             total       used       free     shared    buffers     cached
Mem:          7455       7373         82          0       1404         39
-/+ buffers/cache:       5929       1526
Swap:            0          0          0
Total:        7455       7373         82

So something is consuming a lot of memory. I twice a day restart httpd to free up the memory and about in 12hrs or so it gets full again. The daily average CPU utilization is below 20%.

Here is the top comannd sorted by memory usage.

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                        
31492 apache      20   0 98.6m 4444  460 S  1.0  0.1   0:04.38 sshd                                                                                            
31493 apache      20   0  168m  12m  608 D  1.0  0.2   0:09.09 rsync                                                                                           
 3288 apache      20   0 1988m 1.5g 1468 S  0.7 20.0   4:13.87 httpd                                                                                           
16935 apache      20   0  782m 246m 1532 S  0.7  3.3   0:38.71 httpd                                                                                           
31505 apache      20   0  263m  14m  412 S  0.7  0.2   0:01.27 rsync                                                                                           
    3 root      20   0     0    0    0 S  0.3  0.0   7:35.26 ksoftirqd/0                                                                                     
  217 root      20   0     0    0    0 S  0.3  0.0  10:38.66 kswapd0                                                                                         
 3844 apache      20   0 1676m 1.1g 1628 S  0.3 14.8   3:20.79 httpd                                                                                           
 4280 apache      20   0 1275m 847m 1376 S  0.3 11.4   2:36.90 httpd                                                                                           
 5323 apache      20   0  946m 616m 1304 S  0.3  8.3   1:53.98 httpd                                                                                           
 6580 apache      20   0 1038m 504m 1584 S  0.3  6.8   1:30.28 httpd                                                                                           
 8394 apache      20   0  974m 402m 1584 S  0.3  5.4   1:10.86 httpd                                                                                           
22210 apache      20   0  647m 191m 1532 S  0.3  2.6   0:26.09 httpd                                                                                           
26899 apache      20   0  717m 139m 1480 S  0.3  1.9   0:14.65 httpd                                                                                           
31622 root      20   0 15060 1176  888 R  0.3  0.0   0:00.12 top                                                                                             
    1 root      20   0 19380  296    0 S  0.0  0.0   0:00.46 init                                                                                            
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd                                                                                        
    4 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kworker/0:0    
Maca
  • 1,043
  • 2
  • 19
  • 30
  • 1
    possible duplicate of [How can I determine the cause of an apparent memory leak in my Apache/PHP based web app?](http://serverfault.com/questions/88997/how-can-i-determine-the-cause-of-an-apparent-memory-leak-in-my-apache-php-based) – Wesley Apr 06 '12 at 04:42

2 Answers2

3

One of the scripts that Apache runs has a memory leak. You need to trace the script down. You will likely want to use strace.

In the mean time, you can schedule /etc/init.d/httpd graceful to run on an interval to release the memory.

Wesley
  • 32,690
  • 9
  • 82
  • 117
0

You may want to look into your PHP variables. There are various tuning scripts you can run to get a more in-depth look at how Apache is performing. One I personally recommend is ApacheBuddy (http://quicksnips.dunsmor.com/remote/apachebuddy.pl) strace is also a good resource if your versed in reading the output, you can try the following command for starters:

# ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace
Lucas Kauffman
  • 16,880
  • 9
  • 58
  • 93
Kotori
  • 1
  • 1