Forum Moderators: phranque

Message Too Old, No Replies

Apache Memory consumption with MOD PHP?

         

dcabbar

2:00 am on Nov 1, 2006 (gmt 0)

10+ Year Member



I am running apache with mod_php, and have been trying to find out how much memory apache consumes. For this, wrote a very little script, which allocates 100 meg of string, and sleeps 240 seconds. Then, I hit this script from 5 browsers concurrently. And, measured memory consumption with free and top before running the test, during the test (during this 240 second sleep -- after about 60 seconds), and after tests are finished (php script exit)

This test should have allocated 450-500 megs in total, but for some reason, I can only see about 100 megs when I use free. And, top shows about 110 megs...

Am I doing something wrong here? Why can't I see this 500 megs and/or how can I see it?

Thanks.


free RESULTS

total used free shared buffers cached

BEFORE RUNNING THE TESTS:
Mem: 1035436 989896 45540 0 89892 780480
Swap: 2056300 295640 1760660

DURING THE TESTS (AFTER MEMORY ALLOCATION, PHP STILL IS IN SLEEP):

Mem: 1035436 1021228 14208 0 90692 721304
Swap: 2056300 297080 1759220

AFTER TESTS ARE COMPLETED (PHP SCRIPT IS FINISHED)

Mem: 1035436 895352 140084 0 87944 686372
Swap: 2056300 297312 1758988

top -b -n 1 RESULTS:

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

BEFORE RUNNING THE TESTS:

28917 root 18 0 25584 9872 5928 S 0.0 1.0 0:00.09 httpd
28919 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28920 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28921 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28922 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28923 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28924 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28925 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28926 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd

DURING THE TESTS (AFTER MEMORY ALLOCATION, PHP STILL IS IN SLEEP):

28917 root 18 0 25584 9872 5928 S 0.0 1.0 0:00.09 httpd
28919 apache 18 0 110m 91m 2248 S 0.0 9.1 0:00.29 httpd
28920 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28921 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28922 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28923 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28924 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28925 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28926 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd

AFTER TESTS ARE COMPLETED (PHP SCRIPT IS FINISHED)

28917 root 18 0 25584 9872 5928 S 0.0 1.0 0:00.09 httpd
28919 apache 18 0 25672 6376 2356 S 0.0 0.6 0:00.31 httpd
28920 apache 18 0 25672 6376 2356 S 0.0 0.6 0:00.32 httpd
28921 apache 18 0 25672 6376 2356 S 0.0 0.6 0:00.33 httpd
28922 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28923 apache 17 0 25672 6376 2356 S 0.0 0.6 0:00.32 httpd
28924 apache 18 0 25672 6376 2356 S 0.0 0.6 0:00.27 httpd
28925 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd
28926 apache 25 0 25584 4972 1004 S 0.0 0.5 0:00.00 httpd

SCRIPT:

ini_set("memory_limit","256m");

$aa = array();

$total = 0;
for ($i = 0; $i < 9; $i++) {
$tc = chr(rand(65, 85)) . chr(rand(65, 85)) .chr(rand(65, 85)) .chr(rand(65, 85)) .chr(rand(65, 85));
$aa[$i] = str_repeat($tc, 2000000);
$total += strlen($aa[$i]);
}
print "<h1>$total</h1>";

sleep(240);