You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by John Zhang <jo...@yahoo.com> on 2007/12/15 00:05:24 UTC

Memory issue in apache modules

When my module processes requests, I see a consistent
memory increase.  It is like the memories were never
released.  I am using the apr_* functions to allocate
memory (most of the time from the request->pool).  My
understanding is that memories will be reclaimed by
apache after the request is processed (so I do not
need to free/delete).  Anyone has any ideas?  Does
this have anything to do with keep alive?

Thanks,
John

Re: Memory issue in apache modules

Posted by John Zhang <jo...@yahoo.com>.
--- Eric Covener <co...@gmail.com> wrote:
> 
> It should level out as each thread in the process
> has had a chance to
> run and allocate some memory for a range of
> requests.  MaxMemFree can
> be used to return the heap memory that would
> otherwise be used by
> subsequent requests on that thread.
> 
Thanks Eric,
    But I see consistent memory increase when I load
the SAME page repeatedly.  So something is wrong with
my module.  But I do not know what.

Thanks again.
John

Re: Memory issue in apache modules

Posted by Eric Covener <co...@gmail.com>.
On Dec 14, 2007 6:05 PM, John Zhang <jo...@yahoo.com> wrote:
> When my module processes requests, I see a consistent
> memory increase.  It is like the memories were never
> released.  I am using the apr_* functions to allocate
> memory (most of the time from the request->pool).  My
> understanding is that memories will be reclaimed by
> apache after the request is processed (so I do not
> need to free/delete).  Anyone has any ideas?  Does
> this have anything to do with keep alive?

It should level out as each thread in the process has had a chance to
run and allocate some memory for a range of requests.  MaxMemFree can
be used to return the heap memory that would otherwise be used by
subsequent requests on that thread.


-- 
Eric Covener
covener@gmail.com

Re: Is there are any way to know if the request is regular (http) or SSL (https) in a module?

Posted by John Zhang <jo...@yahoo.com>.
--- Graham Dumpleton <gr...@gmail.com>
wrote:

> On 18/12/2007, Sander Temme <sc...@apache.org>
> wrote:
> >
> > On Dec 17, 2007, at 6:36 PM, Eric Covener wrote:
> >
> > >> I would like to know the request type in my
> module
> > >> (handler/filter), is there any way to know that
> (HTTP
> > >> vs HTTPS)?
> > >
> > > apr_table_get(r->subprocess_env, "HTTPS")  might
> be  what you want
> >
> > That gets set in the Fixup hook, relatively late
> in the request
> > processing process.  You could call
> ap_http_scheme(r) to run the
> > request scheme hook, which will return "https" if
> SSL is disabled or
> > optional on the vhost that accepted the request.
> 
> Or better still, use the function registered by the
> ssl module for the purpose:
> 
> #if AP_SERVER_MAJORVERSION_NUMBER >= 2
> APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec
> *));
> static APR_OPTIONAL_FN_TYPE(ssl_is_https)
> *wsgi_is_https = NULL;
> #endif
> 
>    ...
> 
>    if (!wsgi_is_https)
>         wsgi_is_https =
> APR_RETRIEVE_OPTIONAL_FN(ssl_is_https);
> 
>     if (wsgi_is_https &&
> wsgi_is_https(r->connection))
>         apr_table_set(r->subprocess_env, "HTTPS",
> "1");
> 
> Ie., HTTPS is set by the above sort of process, but
> as pointed out
> that is done only in fixup phase, but you can call
> the ssl_is_https()
> function direct if in earlier phase.
> 
Thanks everyone!  All very useful to me!

Re: Is there are any way to know if the request is regular (http) or SSL (https) in a module?

Posted by Graham Dumpleton <gr...@gmail.com>.
On 18/12/2007, Sander Temme <sc...@apache.org> wrote:
>
> On Dec 17, 2007, at 6:36 PM, Eric Covener wrote:
>
> >> I would like to know the request type in my module
> >> (handler/filter), is there any way to know that (HTTP
> >> vs HTTPS)?
> >
> > apr_table_get(r->subprocess_env, "HTTPS")  might be  what you want
>
> That gets set in the Fixup hook, relatively late in the request
> processing process.  You could call ap_http_scheme(r) to run the
> request scheme hook, which will return "https" if SSL is disabled or
> optional on the vhost that accepted the request.

Or better still, use the function registered by the ssl module for the purpose:

#if AP_SERVER_MAJORVERSION_NUMBER >= 2
APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
static APR_OPTIONAL_FN_TYPE(ssl_is_https) *wsgi_is_https = NULL;
#endif

   ...

   if (!wsgi_is_https)
        wsgi_is_https = APR_RETRIEVE_OPTIONAL_FN(ssl_is_https);

    if (wsgi_is_https && wsgi_is_https(r->connection))
        apr_table_set(r->subprocess_env, "HTTPS", "1");

Ie., HTTPS is set by the above sort of process, but as pointed out
that is done only in fixup phase, but you can call the ssl_is_https()
function direct if in earlier phase.

Graham

Re: Is there are any way to know if the request is regular (http) or SSL (https) in a module?

Posted by Sander Temme <sc...@apache.org>.
On Dec 17, 2007, at 6:36 PM, Eric Covener wrote:

>> I would like to know the request type in my module
>> (handler/filter), is there any way to know that (HTTP
>> vs HTTPS)?
>
> apr_table_get(r->subprocess_env, "HTTPS")  might be  what you want

That gets set in the Fixup hook, relatively late in the request  
processing process.  You could call ap_http_scheme(r) to run the  
request scheme hook, which will return "https" if SSL is disabled or  
optional on the vhost that accepted the request.

S.

-- 
Sander Temme
sctemme@apache.org
PGP FP: 51B4 8727 466A 0BC3 69F4  B7B8 B2BE BC40 1529 24AF




Re: Is there are any way to know if the request is regular (http) or SSL (https) in a module?

Posted by Eric Covener <co...@gmail.com>.
On Dec 17, 2007 9:23 PM, John Zhang <jo...@yahoo.com> wrote:
> I would like to know the request type in my module
> (handler/filter), is there any way to know that (HTTP
> vs HTTPS)?

apr_table_get(r->subprocess_env, "HTTPS")  might be  what you want


-- 
Eric Covener
covener@gmail.com

Is there are any way to know if the request is regular (http) or SSL (https) in a module?

Posted by John Zhang <jo...@yahoo.com>.
I would like to know the request type in my module
(handler/filter), is there any way to know that (HTTP
vs HTTPS)?

Thanks,
John


Re: Memory issue in apache modules

Posted by John Zhang <jo...@yahoo.com>.
--- Joe Lewis <jo...@joe-lewis.com> wrote:
> Your buckets can still be created using the
> request->pool .  My created
> buckets in my output filter are done that way.  Have
> you tried it?  You
> still use the request->connection->bucket_alloc for
> the other parameter,
> but the request->pool for the memory pool to be
> used.
Thanks Joe!


Re: Memory issue in apache modules

Posted by Joe Lewis <jo...@joe-lewis.com>.
John Zhang wrote:
> --- Ray Morris <su...@bettercgi.com> wrote:
>
>   
>>> I am using the apr_* functions to allocate
>>> memory (most of the time from the request->pool).
>>>       
>>    If there are few places where you allocate from
>> othr than the reqquest pool, I'd look at those
>> first.
>>     
>
> I used the bucket/brigade for my data that requires
> the use of request->connection->bucket_alloc.  I read
> a very old post stating that when keep alive is on
> (which is true in my case), then the memory associated
> with the connection will not be freed?  But no answer
> to that post.  Is that a valid concern?

That is a valid concern.  Unfortunately, I do not have an answer to
that, as I have not dug into the apache code itself.  I apologize that I
cannot contribute to an answer in this particular case.

> If so , how
> can I reclaim the connection-related memory or use a
> different memory pool?
>   

Your buckets can still be created using the request->pool .  My created
buckets in my output filter are done that way.  Have you tried it?  You
still use the request->connection->bucket_alloc for the other parameter,
but the request->pool for the memory pool to be used.

Joe
-- 
Joseph Lewis <http://sharktooth.org/>
"Divide the fire, and you will sooner put it out." - Publius Syrus

Re: Memory issue in apache modules

Posted by John Zhang <jo...@yahoo.com>.
--- Ray Morris <su...@bettercgi.com> wrote:

> > I am using the apr_* functions to allocate
> > memory (most of the time from the request->pool).
> 
>    If there are few places where you allocate from
> othr than the reqquest pool, I'd look at those
> first.

I used the bucket/brigade for my data that requires
the use of request->connection->bucket_alloc.  I read
a very old post stating that when keep alive is on
(which is true in my case), then the memory associated
with the connection will not be freed?  But no answer
to that post.  Is that a valid concern?  If so , how
can I reclaim the connection-related memory or use a
different memory pool?

Thanks,
John


Re: Memory issue in apache modules

Posted by Ray Morris <su...@bettercgi.com>.
> I am using the apr_* functions to allocate
> memory (most of the time from the request->pool).

   If there are few places where you allocate from
othr than the reqquest pool, I'd look at those first.
--
Ray B. Morris
support@bettercgi.com

Strongbox - The next generation in site security:
http://www.bettercgi.com/strongbox/





On 12/14/2007 05:05:24 PM, John Zhang wrote:
> When my module processes requests, I see a consistent
> memory increase.  It is like the memories were never
> released.  I am using the apr_* functions to allocate
> memory (most of the time from the request->pool).  My
> understanding is that memories will be reclaimed by
> apache after the request is processed (so I do not
> need to free/delete).  Anyone has any ideas?  Does
> this have anything to do with keep alive?
> 
> Thanks,
> John
>