Welcome to HostingForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Apache & PHP5 - httpd not releasing memory?

 
   Web Hosting Problem Solving Community! (Home) -> Apache RSS
Next:  Localhost Query  
Author Message
Grant Cox

External


Since: Feb 15, 2008
Posts: 2



(Msg. 1) Posted: Fri Feb 15, 2008 10:40 pm
Post subject: Apache & PHP5 - httpd not releasing memory?
Archived from groups: alt>apache>configuration (more info?)

We have a server for a PHP web application, running on a VM with a
dedicated 6GB memory. The web application activity is virtually all
for end users (small requests), but occasionally reports are generated
by administrators.

These reports are very large - collating hundreds of thousands of
database rows across a couple dozen tables. In the appropriate PHP
requests we have ini_set('memory_limit', '1024M'); , as already some
reports are using >700MB (measured with memory_get_usage() ).

The problem is that the httpd processes involved in this do not
release their memory after the request completes. If I view the
running processes with "top", the affected httpd processes peak to
1.3GB reserved memory, and even hours later still retain this. We
have had the whole VM go down a couple of times because more than 5
reports were generated without each httpd process releasing the memory
- causing the whole system to start thrashing. At this time we we can
see the VM is maxing all 8 cores and all 6GB memory - just swapping
memory due to the redundant httpd processes that are using it all.


So first of all, is this a bug, or is it intended that each process
does not release memory after a request completes? Secondly, when we
want the possibility of many concurrent requests (e.g. end users, so
MaxClients > 100 ), but also the ability for administrators to
generate reports (ie RLimitMEM cannot be low), what would be the best
setup to avoid running out of memory? If I put MaxRequestsPerChild to
1 then it works (as each httpd process is killed after each request),
but I expect this would negatively impact performance for end users...

I am currently thinking the best idea is to have two separate apache
configurations - one with a "normal" setup for the end users and one
with low MaxRequestsPerChild and MaxClients just for the admin
functions. But this also seems a bit hacky - the perfect solution
would be for apache to automatically release any memory held >100MB.
Is anything like this possible?

 >> Stay informed about: Apache & PHP5 - httpd not releasing memory? 
Back to top
Login to vote
Kees Nuyt

External


Since: Oct 25, 2006
Posts: 78



(Msg. 2) Posted: Sat Feb 16, 2008 11:05 am
Post subject: Re: Apache & PHP5 - httpd not releasing memory? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Fri, 15 Feb 2008 22:40:00 -0800 (PST), Grant Cox
<grant.cox DeleteThis @gmail.com> wrote:

>We have a server for a PHP web application, running on a VM with a
>dedicated 6GB memory. The web application activity is virtually all
>for end users (small requests), but occasionally reports are generated
>by administrators.
>
>These reports are very large - collating hundreds of thousands of
>database rows across a couple dozen tables. In the appropriate PHP
>requests we have ini_set('memory_limit', '1024M'); , as already some
>reports are using >700MB (measured with memory_get_usage() ).
>
>The problem is that the httpd processes involved in this do not
>release their memory after the request completes. If I view the
>running processes with "top", the affected httpd processes peak to
>1.3GB reserved memory, and even hours later still retain this. We
>have had the whole VM go down a couple of times because more than 5
>reports were generated without each httpd process releasing the memory
>- causing the whole system to start thrashing. At this time we we can
>see the VM is maxing all 8 cores and all 6GB memory - just swapping
>memory due to the redundant httpd processes that are using it all.
>
>
>So first of all, is this a bug, or is it intended that each process
>does not release memory after a request completes? Secondly, when we
>want the possibility of many concurrent requests (e.g. end users, so
>MaxClients > 100 ), but also the ability for administrators to
>generate reports (ie RLimitMEM cannot be low), what would be the best
>setup to avoid running out of memory? If I put MaxRequestsPerChild to
>1 then it works (as each httpd process is killed after each request),
>but I expect this would negatively impact performance for end users...
>
>I am currently thinking the best idea is to have two separate apache
>configurations - one with a "normal" setup for the end users and one
>with low MaxRequestsPerChild and MaxClients just for the admin
>functions. But this also seems a bit hacky - the perfect solution
>would be for apache to automatically release any memory held >100MB.
>Is anything like this possible?

I solved a similar problem by not executing the large
reports in the context of the webserver, but performing
them one by one in batch.

This works as follows:
- User submits a request
- Request and its parameters are stored
in a "job" database, job status "waiting"
- PHP launches a dispatch process,
which runs independent of the webserver.
- User can query the jobstatus
(waiting, running, completed, abended, ...)
- Once the job is complete, links are
displayed in the job status for
- stdout / stderr of the job script
- download of output file(s)

The dispatch process:
0 detect dispatcher already active:
exit this new dispatcher
1 reads the job database
2 no more jobs: exit dispatcher
3 retrieves one job description,
set job status to "running"
4 calls the script which produces
the required report
5 on exit of the script, maintains
job status in the database
"completed" / "abend"
6 puts links to
stdout/stderr and download files
in the database
7 back to 1

I use schtasks in Windows XP / Vista to launch the
dispatcher job.

HTH
--
( Kees
)
c[_] If you want a picture of the future of Usenet,
imagine a foot stuck in a human mouth -- forever. (Avram Grumer) (#2Cool

 >> Stay informed about: Apache & PHP5 - httpd not releasing memory? 
Back to top
Login to vote
Grant Cox

External


Since: Feb 15, 2008
Posts: 2



(Msg. 3) Posted: Sat Feb 16, 2008 6:46 pm
Post subject: Re: Apache & PHP5 - httpd not releasing memory? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi Kees,

Thanks for the suggestion. This application does already have a
number of background daemon processes to do similar tasks - and as
these run as PHP directly they do not suffer the same memory issue.
However, to support this asynchronism for the reports would mean
rewriting some aspects of the web application - and I'd prefer
something a little simpler at the moment. It's certainly something to
keep in mind though, particularly if these reports become popular
enough that a queue is necessary.

I have been playing around with having two apache instances for the
moment - one of which has the following settings:
Listen 81

StartServers 2
MinSpareServers 1
MaxSpareServers 1
ServerLimit 3
MaxClients 3
MaxRequestsPerChild 1

So this should mean a maximum of three requests at a time (ie 3GB max
memory), and each httpd process will only serve one request -
releasing memory afterwards. This second apache instance listens on
port 81, which is not open through the firewall, and in the main
apache configuration there is a ProxyPass so that report requests go
to the second instance.

ProxyPass /reports http://application.server.com:81/reports
ProxyPassReverse /reports http://application.server.com:81/reports


I am still surprised that there is no setting to put a maximum memory
cap on all httpd processes (rather than a per-process cap), and that
apache will happily thrash the system whilst sitting on gigabytes of
unused reserved memory... But at least this solution appears to work
well, and is transparent.



On Feb 16, 11:43 pm, Kees Nuyt <k.n....RemoveThis@nospam.demon.nl> wrote:
>
> I solved a similar problem by not executing the large
> reports in the context of the webserver, but performing
> them one by one in batch.
>
> This works as follows:
> - User submits a request
> - Request and its parameters are stored
> in a "job" database, job status "waiting"
> - PHP launches a dispatch process,
> which runs independent of the webserver.
> - User can query the jobstatus
> (waiting, running, completed, abended, ...)
> - Once the job is complete, links are
> displayed in the job status for
> - stdout / stderr of the job script
> - download of output file(s)
>
> The dispatch process:
> 0 detect dispatcher already active:
> exit this new dispatcher
> 1 reads the job database
> 2 no more jobs: exit dispatcher
> 3 retrieves one job description,
> set job status to "running"
> 4 calls the script which produces
> the required report
> 5 on exit of the script, maintains
> job status in the database
> "completed" / "abend"
> 6 puts links to
> stdout/stderr and download files
> in the database
> 7 back to 1
>
> I use schtasks in Windows XP / Vista to launch the
> dispatcher job.
>
> HTH
> --
> ( Kees
> )
> c[_] If you want a picture of the future of Usenet,
> imagine a foot stuck in a human mouth -- forever. (Avram Grumer) (#2Cool
 >> Stay informed about: Apache & PHP5 - httpd not releasing memory? 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
httpd not releasing memory after requests - Hi, It looks like the issue of memory leaks have come up in the past, but I have a problem that seems specific to one WinXP machine running apache 2.2.4 and php 5.2.4(another machine with a similar configuration does behave this way). Every request of..

Apache httpd possible memory leak causing swapping on sola.. - Hi We are having problems with httpd increasing in memory size until the server begins to swap and then causes slow response times. This cures itself when httpd is restarted (obviously not an ideal situation!) The size of each httpd process begins at..

WIN2K, Apache v2.0.5 & PHP5 - hi Everyone, I posted the article below already in comp.language.php but I think it won't heard to post it in this NG as well. I installed Apache V 2.0.53 on Windows 2000 pro SP4 (including latest Windows patches). Installed PHP version is V 5.0.4 ..

How do I get apache to know a "php5" extension? - I'm a little new to apache and linux.. I know in IIS I just add an application mapping.

configuring php5 on apache 1.3 - Hello, I'm installing roundcube webmail on a FreeBSD jail usinng ports. The install went fine, configuring apache 1.3 also went well with one exception, i've got LoadModule and AddModule lines for php5, but the index.php file isn't being processed...
   Web Hosting Problem Solving Community! (Home) -> Apache All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]