views:

93

answers:

1

Problem: my mod_perl leaks and I cannot control it.

I run mod_perl script under Ubuntu (production code). Usually there are 8-10 script instances running concurrently.

According to Unix "top" utilty each instance takes 55M of memory. 55M is a lot, but I was told here that most of this memory is shared.

The memory is leaking. There are 512M on the server. There is a significant decrease of free memory in 24 hours after reboot.

Test: free memory on the system at the moment 10 scripts are running: -after reboot: 270M -in 24 hours since reboot: 50M

In 24 hours memory taken by each script is roughly the same - 55M (according to "top" utility). I don't understand where the memory leakes out. And don't know how can I find the leaks.

I share memory, I preload all the modules required by the script in startup.pl.

One more test. A very simple mod_perl script ("Hello world!") takes 52M (according to "top")

According to "Practical mod_perl" I can use GTop utility to measure the real memory taken by mod_perl. I have made a very simple script that measures the memory with GTop. It shows there are 54M real memory taken by a very simple perl script! 54 Megabytes by "Hello world"?!!!

proc-mem-size: 59,707392
proc-mem-share: 52,59264
diff: 54,448128

There must be something wrong in the way I measure mod_perl memory. Help please! This problem is driving me mad for several days.

These are the snapshots of "top" output after reboot and in 24 hours after reboot. The processes are sorted by Memory.

---- RIGHT AFTER REBOOT ----

top - 10:25:24 up 55 min,  2 users,  load average: 0.10, 0.07, 0.07
Tasks:  59 total,   3 running,  56 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni, 97.3%id,  0.7%wa,  0.0%hi,  0.0%si,  2.0%st
Mem:    524456k total,   269300k used,   255156k free,    12024k buffers
Swap:        0k total,        0k used,        0k free,    71276k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2307 www-data  15   0 58500  27m 5144 S  0.0  5.3   0:02.02 apache2
 2301 www-data  15   0 58492  27m 4992 S  0.0  5.3   0:02.09 apache2
 2302 www-data  15   0 57936  26m 4960 R  0.0  5.2   0:01.74 apache2
 2895 www-data  15   0 57812  26m 5048 S  0.0  5.2   0:00.98 apache2
 2903 www-data  15   0 56944  26m 4792 S  0.0  5.1   0:01.12 apache2
 2886 www-data  15   0 56860  26m 4784 S  0.0  5.1   0:01.20 apache2
 2896 www-data  15   0 56520  26m 4804 S  0.0  5.1   0:00.85 apache2
 2911 www-data  15   0 56404  25m 4768 S  0.0  5.1   0:00.87 apache2
 2901 www-data  15   0 56520  25m 4744 S  0.0  5.1   0:00.84 apache2
 2893 www-data  15   0 56608  25m 4740 S  0.0  5.1   0:00.73 apache2
 2277 root      15   0 51504  22m 6332 S  0.0  4.5   0:01.02 apache2
 2056 mysql     18   0 98628  21m 5164 S  0.0  4.2   0:00.64 mysqld
 3162 root      15   0  6356 3660 1276 S  0.0  0.7   0:00.00 vi
 2622 root      15   0  8584 2980 2392 R  0.0  0.6   0:00.07 sshd
 3083 root      15   0  8448 2968 2392 S  0.0  0.6   0:00.06 sshd
 3164 par       15   0  5964 2828 1868 S  0.0  0.5   0:00.05 proftpd
    1 root      18   0  3060 1900  576 S  0.0  0.4   0:00.00 init
 2690 root      17   0  4272 1844 1416 S  0.0  0.4   0:00.00 bash
 3151 root      15   0  4272 1844 1416 S  0.0  0.4   0:00.00 bash
 2177 root      15   0  8772 1640  520 S  0.0  0.3   0:00.00 sendmail-mta
 2220 proftpd   15   0  5276 1448  628 S  0.0  0.3   0:00.00 proftpd
 2701 root      15   0  2420 1120  876 R  0.0  0.2   0:00.09 top
 1966 root      18   0  5396 1084  692 S  0.0  0.2   0:00.00 sshd


---- ROUGHLY IN 24 HOURS AFTER REBOOT

top - 17:45:38 up 23:39,  1 user,  load average: 0.02, 0.09, 0.11
Tasks:  55 total,   2 running,  53 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    524456k total,   457660k used,    66796k free,   127780k buffers
Swap:        0k total,        0k used,        0k free,   114620k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
16248 www-data  15   0 63712  35m 6668 S  0.0  6.8   0:23.79 apache2
19417 www-data  15   0 60396  31m 6472 S  0.0  6.2   0:10.95 apache2
19419 www-data  15   0 60276  31m 6376 S  0.0  6.1   0:11.71 apache2
19321 www-data  15   0 60480  29m 4888 S  0.0  5.8   0:11.51 apache2
21241 www-data  15   0 58632  29m 6260 S  0.0  5.8   0:05.18 apache2
22063 www-data  15   0 57400  28m 6396 S  0.0  5.6   0:02.05 apache2
21240 www-data  15   0 58520  27m 4856 S  0.0  5.5   0:04.60 apache2
21236 www-data  15   0 58244  27m 4868 S  0.0  5.4   0:05.24 apache2
22499 www-data  15   0 56736  26m 4776 S  0.0  5.1   0:00.70 apache2
 2055 mysql     15   0  100m  25m 5656 S  0.0  5.0   0:20.95 mysqld
 2277 root      18   0 51500  22m 6332 S  0.0  4.5   0:01.07 apache2
22686 www-data  15   0 53004  21m 4092 S  0.0  4.3   0:00.21 apache2
22689 root      15   0  8584 2980 2392 R  0.0  0.6   0:00.06 sshd
 2176 root      15   0  8768 1928  736 S  0.0  0.4   0:00.00 sendmail-
+mta
    1 root      18   0  3064 1900  576 S  0.0  0.4   0:00.02 init
22757 root      15   0  4268 1844 1416 S  0.0  0.4   0:00.00 bash
 2220 proftpd   18   0  5276 1448  628 S  0.0  0.3   0:00.00 proftpd
22768 root      15   0  2424 1100  876 R  0.0  0.2   0:00.00 top
 1965 root      15   0  5400 1088  692 S  0.0  0.2   0:00.00 sshd
 2258 root      18   0  3416 1036  820 S  0.0  0.2   0:00.01 cron
 1928 klog      25   0  2248 1008  420 S  0.0  0.2   0:00.04 klogd
 1946 messageb  19   0  2648  804  596 S  0.0  0.2   0:01.63 dbus-daem
+on
 1908 syslog    18   0  2016  716  556 S  0.0  0.1   0:00.17 syslogd
+1  A: 

It doesn't actually look like the number of apache/mod_perl processes in existence or the memory they use has changed much between the two reports you post. I note you did not post the header for the second report. It would be interesting to see the "cached" figure after 24 hours. I am going to go out on a limb and guess that this is where your memory is going - Linux is using it for caching file I/O. You can think of the file I/O cache as essentially free memory, since Linux will make that memory available if processes need it.

You can also check that this is what's going on by performing

sync; echo 3 > /proc/sys/vm/drop_caches

as root to cause the memory in use by the caches to be released, and confirming that this causes the amount of free memory reported to revert to initial values.

moonshadow
drop_caches command is amaizing!Thank you much!Now I have a better control on my system.I have updated "after 24h" top diagnostics.114620k (cached) + 66796k (free) = 181416kCompared to original 269300k is a 90M difference.
Pavel