about memory usage with application written with php and mysql [message #172496] |
Mon, 21 February 2011 12:30 |
lovecreatesbeauty
Messages: 4 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
I'm writing code with PHP 5, Apache 2 and Mysql 5 on Debian 6.
After system just starts up, it has this much memory:
Mem: 514644k total, 494964k used, 375900k free,
After playing with my web application written with PHP and Mysql for a
while, the system shows the memory usage as this:
Mem: 514644k total, 494964k used, 4876k free,
....
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2184 www-data 20 0 65060 28m 2680 D 4.1 5.6 0:02.55 apache2
2174 www-data 20 0 65084 27m 2200 R 4.1 5.4 0:07.89 apache2
2139 www-data 20 0 65084 27m 2024 R 7.3 5.4 0:17.21 apache2
2143 www-data 20 0 65076 27m 2016 D 3.2 5.4 0:21.21 apache2
2144 www-data 20 0 65076 27m 2016 D 3.2 5.4 0:18.55 apache2
2172 www-data 20 0 65084 26m 1912 R 3.5 5.4 0:08.88 apache2
2146 www-data 20 0 65084 26m 1912 D 3.2 5.4 0:07.21 apache2
2169 www-data 20 0 65084 26m 1912 R 3.5 5.3 0:09.87 apache2
2160 www-data 20 0 64828 26m 1912 R 6.1 5.3 0:07.35 apache2
2162 www-data 20 0 63548 25m 1908 R 7.3 5.1 0:07.01 apache2
2163 www-data 20 0 59452 21m 1912 R 7.0 4.3 0:07.58 apache2
1263 www-data 20 0 58672 20m 2020 R 15.7 4.2 0:19.92 apache2
2182 www-data 20 0 57144 19m 2196 D 3.2 4.0 0:07.07 apache2
2180 www-data 20 0 57144 19m 2196 D 3.8 3.9 0:07.01 apache2
2141 www-data 20 0 57392 19m 2016 R 8.1 3.9 0:17.30 apache2
2151 www-data 20 0 57144 19m 2028 D 3.2 3.9 0:10.63 apache2
1261 www-data 20 0 57136 19m 2032 D 2.6 3.9 0:11.05 apache2
1265 www-data 20 0 57136 19m 2032 D 2.6 3.9 0:10.06 apache2
1264 www-data 20 0 57136 19m 2032 D 2.3 3.9 0:14.93 apache2
1262 www-data 20 0 57136 19m 2032 D 3.2 3.9 0:10.83 apache2
2145 www-data 20 0 57136 19m 2016 R 0.9 3.9 0:24.08 apache2
2158 www-data 20 0 49492 11m 1372 S 0.0 2.3 0:11.30 apache2
2161 www-data 20 0 49492 11m 1372 S 0.0 2.3 0:09.42 apache2
2157 www-data 20 0 49492 11m 1332 S 0.0 2.2 0:09.12 apache2
1564 mysql 20 0 139m 3500 792 S 0.6 0.7 0:04.24 mysqld
2185 www-data 20 0 40476 2352 888 S 0.0 0.5 0:00.01 apache2
...
I wait a bit longer, it seems the system has more memory back now:
Mem: 514644k total, 475472k used, 39172k free, 3600k
buffers
|
|
|
Re: about memory usage with application written with php and mysql [message #172505 is a reply to message #172496] |
Mon, 21 February 2011 13:11 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
El 21/02/2011 13:30, lovecreatesbeauty escribió/wrote:
> I'm writing code with PHP 5, Apache 2 and Mysql 5 on Debian 6.
>
> After system just starts up, it has this much memory:
> Mem: 514644k total, 494964k used, 375900k free,
>
> After playing with my web application written with PHP and Mysql for a
> while, the system shows the memory usage as this:
> Mem: 514644k total, 494964k used, 4876k free,
>
> ...
>
> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
> 2184 www-data 20 0 65060 28m 2680 D 4.1 5.6 0:02.55 apache2
[...]
> 1564 mysql 20 0 139m 3500 792 S 0.6 0.7 0:04.24 mysqld
> 2185 www-data 20 0 40476 2352 888 S 0.0 0.5 0:00.01 apache2
> ...
>
> I wait a bit longer, it seems the system has more memory back now:
> Mem: 514644k total, 475472k used, 39172k free, 3600k
> buffers
I'm not sure about your exact question but Linux tends to consider free
memory as a wasted resource (why purchase RAM if you are not using it?)
so it normally tries to give it some use (cache or whatever). System
load is often a better indicator.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|
Re: about memory usage with application written with php and mysql [message #172532 is a reply to message #172505] |
Mon, 21 February 2011 16:51 |
lovecreatesbeauty
Messages: 4 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
On Feb 21, 9:11?pm, "álvaro G. Vicario"
<alvaro.NOSPAMTH...@demogracia.com.invalid> wrote:
> I'm not sure about your exact question but Linux tends to consider free
> memory as a wasted resource (why purchase RAM if you are not using it?)
> so it normally tries to give it some use (cache or whatever). System
> load is often a better indicator.
Thank you.
From 89.5% (375900k - 39172k) to 98.7% (375900k - 4876k) of the memory
is lost in my Php code issuing connection to Mysql. Some queries to
database may return records of ten thousand.
The Php mannual says it has garbage collection and mysql_close is not
needed. How can the code lead to memory lose like that? Is the code
wrong and needs to be rewritten?
|
|
|
Re: about memory usage with application written with php and mysql [message #172536 is a reply to message #172532] |
Mon, 21 February 2011 17:01 |
Peter H. Coffin
Messages: 245 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On Mon, 21 Feb 2011 08:51:53 -0800 (PST), lovecreatesbeauty wrote:
> On Feb 21, 9:11?pm, "?lvaro G. Vicario"
> <alvaro.NOSPAMTH...@demogracia.com.invalid> wrote:
>> I'm not sure about your exact question but Linux tends to consider free
>> memory as a wasted resource (why purchase RAM if you are not using it?)
>> so it normally tries to give it some use (cache or whatever). System
>> load is often a better indicator.
>
> Thank you.
>
> From 89.5% (375900k - 39172k) to 98.7% (375900k - 4876k) of the memory
> is lost in my Php code issuing connection to Mysql. Some queries to
> database may return records of ten thousand.
>
> The Php mannual says it has garbage collection and mysql_close is not
> needed. How can the code lead to memory lose like that? Is the code
> wrong and needs to be rewritten?
It's not lost. It's in use for OS-related things. Any memory that PHP
uses would be in the "Used:" accounting, not in the "not listed but not
'free'" lack-of-accounting, including PHP's use of memor for the MySQL
connections.
--
Remember, a 12'x12'x18" raised floor can hold over a thousand gallons of
blood before it starts to seep up through the cracks.
-- Roger Burton West in the Monastery
|
|
|
Re: about memory usage with application written with php and mysql [message #172537 is a reply to message #172532] |
Mon, 21 February 2011 17:28 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 2/21/2011 11:51 AM, lovecreatesbeauty wrote:
> On Feb 21, 9:11?pm, "álvaro G. Vicario"
> <alvaro.NOSPAMTH...@demogracia.com.invalid> wrote:
>> I'm not sure about your exact question but Linux tends to consider free
>> memory as a wasted resource (why purchase RAM if you are not using it?)
>> so it normally tries to give it some use (cache or whatever). System
>> load is often a better indicator.
>
> Thank you.
>
> From 89.5% (375900k - 39172k) to 98.7% (375900k - 4876k) of the memory
> is lost in my Php code issuing connection to Mysql. Some queries to
> database may return records of ten thousand.
>
> The Php mannual says it has garbage collection and mysql_close is not
> needed. How can the code lead to memory lose like that? Is the code
> wrong and needs to be rewritten?
As álvaro said - Linux will use memory for buffers, cache, etc. So will
MySQL. Your figures do not necessarily indicate a problem.
And php.net seems to say a lot of things which are not good programming
practice. One of the keys to good programming is to ALWAYS clean up
after yourself - don't expect someone else to do it for you. This
means, for instance, you should always free your result set when you're
done with it, and close the connection when you're through with MySQL.
I think it's comments like these which encourage poor programming
practices in PHP and leads to sloppy code (and problems).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|