Re: Memory Pool

2010-10-12 Thread Ben Noordhuis
Martin, if you are working in a constrained environment, then you are
probably better off using something like libmicrohttpd[1] or
libevent's evhttp interface[2]. Apache has a rather heavy resource
footprint.

[1] http://www.gnu.org/software/libmicrohttpd/
[2] http://monkey.org/~provos/libevent/doxygen/evhttp_8h.html


Re: Memory Pool

2010-10-12 Thread Martin Townsend

 On 11/10/2010 20:48, Nick Kew wrote:

On Mon, 11 Oct 2010 15:14:02 +0100
Martin Townsend  wrote:


   Hi,

I have created a pool from the child pool for storing warning messages
that can live across requests, the final request will insert the
warnings into the response.  How do I ensure that this pool is cleared
at the end of the final request?

That doesn't really make sense.  What is "the final request"?

If it's requests in a connection, use the connection pool.
Otherwise, you're looking at a time-based solution such
as garbage collection.



Thanks for the reply and Apologies, I should have put a bit more detail 
in.  I'm working on a module for an embedded platform where we can use 
the web server to configure the firmware.  The interface between the 
module and firmware allows the firmware to send back warning messages 
for side effects of configuration changes.  The time taken for the 
configuration change will likely outlive the connection timeout.  I 
could increase this timeout but I would like to keep it short as you can 
only connect to the web server from a local network and then I can keep 
the number of child processes low.


These warnings are inserted into a response as a table within a DIV HTML 
element by my output filter.  So what usually happens is that the first 
request is a POST with the configure command, an input filter parses 
this and sends the configure to the firmware, the firmware then may send 
back warning messages.  Theses are collected and stored in a list.  The 
next request (which I wrongly referred to as the final request) will 
then have the warning table inserted into the response to which the 
client can then use javascript to display as an overlay.


I've implemented a solution where I use a sub pool from the child pool 
which is now cleared using a flag which I set when the warnings are 
processed by the output filter.  The next (initial) request will then 
pick up the flag and clear the pool.  What I was hoping for, is a hook 
at a point after the data had been sent but the flag works well.


--
Martin Townsend
Power*Oasis*
Suite 1, Unit 41
Shrivenham Hundred Business Park
Majors Road
Watchfield
Swindon
Wilts SN6 8TZ

Mobile: 07884 444658
Skype: mtownsend1973


Re: Memory Pool

2010-10-11 Thread Nick Kew
On Mon, 11 Oct 2010 15:14:02 +0100
Martin Townsend  wrote:

>   Hi,
> 
> I have created a pool from the child pool for storing warning messages 
> that can live across requests, the final request will insert the 
> warnings into the response.  How do I ensure that this pool is cleared 
> at the end of the final request?

That doesn't really make sense.  What is "the final request"?

If it's requests in a connection, use the connection pool.
Otherwise, you're looking at a time-based solution such
as garbage collection.

-- 
Nick Kew


Re: Memory Pool

2010-10-11 Thread Ben Noordhuis
On Mon, Oct 11, 2010 at 16:40, Martin Townsend
 wrote:
> use, or should I set a flag and then use a hook like fix-ups that will check
> this flag and then call  apr_pool_clear()?

This. You can use a request note for a flag.


Re: Memory Pool

2010-10-11 Thread Martin Townsend

 On 11/10/2010 15:36, Ben Noordhuis wrote:

On Mon, Oct 11, 2010 at 16:14, Martin Townsend
  wrote:

I have created a pool from the child pool for storing warning messages that
can live across requests, the final request will insert the warnings into
the response.  How do I ensure that this pool is cleared at the end of the
final request?

By calling apr_pool_clear() or apr_pool_destroy()?


-
No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1120 / Virus Database: 422/3189 - Release Date: 10/10/10



Thanks for the response, the problem I have is where do I call 
apr_pool_clear(), if I call it from the output filter then the warnings 
will be freed before they are sent in the response.  Is there a hook 
that I could use, or should I set a flag and then use a hook like 
fix-ups that will check this flag and then call  apr_pool_clear()?


--
Martin Townsend
Power*Oasis*
Suite 1, Unit 41
Shrivenham Hundred Business Park
Majors Road
Watchfield
Swindon
Wilts SN6 8TZ

Mobile: 07884 444658
Skype: mtownsend1973


Re: Memory Pool

2010-10-11 Thread Ben Noordhuis
On Mon, Oct 11, 2010 at 16:14, Martin Townsend
 wrote:
> I have created a pool from the child pool for storing warning messages that
> can live across requests, the final request will insert the warnings into
> the response.  How do I ensure that this pool is cleared at the end of the
> final request?

By calling apr_pool_clear() or apr_pool_destroy()?


Memory Pool

2010-10-11 Thread Martin Townsend

 Hi,

I have created a pool from the child pool for storing warning messages 
that can live across requests, the final request will insert the 
warnings into the response.  How do I ensure that this pool is cleared 
at the end of the final request?


Cheers,
Martin.

--
Martin Townsend
Power*Oasis*
Suite 1, Unit 41
Shrivenham Hundred Business Park
Majors Road
Watchfield
Swindon
Wilts SN6 8TZ

Mobile: 07884 444658
Skype: mtownsend1973


Re: A question about cross request memory/pool usage

2009-02-22 Thread Weiming Yin
Hi, Nick

On Fri, Feb 20, 2009 at 3:42 PM, Nick Kew  wrote:

>
> On 20 Feb 2009, at 03:14, Weiming Yin wrote:
>
>  Hi
>>
>
> [answering here, but in future please post questions like this to the
> modules dev list]
>
>
>> I am writing an Apache module, I wanna setup some configure variable in
>> the module via a http request. The variable saved into a apr_hash_t in my
>> own module configure. But in the next request (the fixup handler), the one
>> with saved into the apr_hash_t is disappeared. I don't know why, is the
>> memory pool usage issue?
>>
>
> Most likely your requests are running in different processes, though you
> don't
> give enough information to be certain.
>
>  ...
>> var_t *var = apr_palloc(r->pool, sizeof(var_t));
>> apr_hash_set(cfg->var_hash, var->key, APR_HASH_KEY_STRING, var);
>>
>
> That's problematic for several reasons.   r->pool doesn't have the lifetime
> you want.
> The server pool does, but allocating from it in a request is a memory leak
> and not
> thread-safe.  Likewise setting cfg->hash there is not thread-safe.


I tested the r->server->process->pool, but I got a very strange result.
Sometimes (or some requests) it gives me some right result (the module
remember the variables into the hash), but sometimes it not. I donot know
why.


>
>
> Would this be a good time to mention that my book has a Chinese
> translation?


Your book, the new one? Which one, I got a Chinese translated  on my hand.
I can find some friends to ask them if the have time and we can translate
the book into Chinese.


>
> --
> Nick Kew
>
> Application Development with Apache - the Apache Modules Book
> http://www.apachetutor.org/
>



-- 
Weiming Yin


Re: Local Memory pool

2008-07-24 Thread Jason Fister
I am sending this again hoping someone would respond.

Thanks in advance.

Jason

On Tue, Jul 22, 2008 at 11:42 AM, Jason Fister <[EMAIL PROTECTED]>
wrote:

> Hello all,
>
> In my apache module, I receive, process and return large amounts of data.
> The size of the data could be as large as 100's of megabytes. I allocate
> memory from the request pool and let apache clean up the memory after each
> request is served.
>
> Although, apache is supposed to reclaim memory after each request is
> served, I would like to explicitly clean up memory after processing each
> request. This is because of the fact that size of data associated with each
> requests and a large number of clients calling in to the module.
>
> After doing some research this is what I am thinking about doing. In my
> module_handler
>
> apr_allocator_t *local_allocator = NULL;
> apr_pool_t *localPool = NULL;
>
> apr_allocator_create(&local_allocator);
> apr_pool_create_ex(&localPool, NULL, NULL, local_allocator);
> ...
> ...
> allocate memory from this local pool
> ...
> ...
>
> apr_pool_destroy(localPool);
> apr_allocator_destroy(local_allocator);
>
> return OK;
>
>
> Do you guys see any problem with this approach?
>
>
> Jason Fister
>


Local Memory pool

2008-07-22 Thread Jason Fister
Hello all,

In my apache module, I receive, process and return large amounts of data.
The size of the data could be as large as 100's of megabytes. I allocate
memory from the request pool and let apache clean up the memory after each
request is served.

Although, apache is supposed to reclaim memory after each request is served,
I would like to explicitly clean up memory after processing each request.
This is because of the fact that size of data associated with each requests
and a large number of clients calling in to the module.

After doing some research this is what I am thinking about doing. In my
module_handler

apr_allocator_t *local_allocator = NULL;
apr_pool_t *localPool = NULL;

apr_allocator_create(&local_allocator);
apr_pool_create_ex(&localPool, NULL, NULL, local_allocator);
...
...
allocate memory from this local pool
...
...

apr_pool_destroy(localPool);
apr_allocator_destroy(local_allocator);

return OK;


Do you guys see any problem with this approach?


Jason Fister