Re: mod_perl memory

Mårten Svantesson <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
Torsten Förtsch skrev:
> On Thursday 18 March 2010 04:13:04 Pavel Georgiev wrote:
>> How would that logic (adding subpools and using them) be applied to my
>>  simplified example:
>>
>> for (;;) {
>>    $request->print("--$this->{boundary}\n");
>>    $request->print("Content-type: text/html; charset=utf-8;\n\n");
>>    $request->print("$data\n\n");
>>    $request->rflush;
>> }
>>
>> Do I need to add an output filter?
>>
> No, this one does not grow here.
> 
> sub {
>   my ($r)=@_;
> 
>   my $ba=$r->connection->bucket_alloc;
>   until( -e '/tmp/stop' ) {
>     my $pool=$r->pool->new;
>     my $bb2=APR::Brigade->new($pool, $ba);
>     $bb2->insert_tail(APR::Bucket->new($ba, ("x"x70)."\n"));
>     $bb2->insert_tail(APR::Bucket::flush_create $ba);
>     $r->output_filters->pass_brigade($bb2);
>     $pool->destroy;
>   }
> 
>   my $bb2=APR::Brigade->new($r->pool, $ba);
>   $bb2->insert_tail(APR::Bucket::eos_create $ba);
>   $r->output_filters->pass_brigade($bb2);
> 
>   return Apache2::Const::OK;
> }
> 
> Torsten Förtsch
> 

I have never worked directly with the APR API but in the example above couldn't you prevent the request pool from growing by explicitly reusing the 
bucket brigade?

Something like (not tested):

sub {
   my ($r)=@_;

   my $ba=$r->connection->bucket_alloc;
   my $bb2=APR::Brigade->new($r->pool, $ba);
   until( -e '/tmp/stop' ) {
     $bb2->insert_tail(APR::Bucket->new($ba, ("x"x70)."\n"));
     $bb2->insert_tail(APR::Bucket::flush_create $ba);
     $r->output_filters->pass_brigade($bb2);
     $bb2->cleanup();
   }

   $bb2->insert_tail(APR::Bucket::eos_create $ba);
   $r->output_filters->pass_brigade($bb2);

   return Apache2::Const::OK;
}


-- 
   MÃ¥rten Svantesson
   Senior Developer
   Travelocity Nordic
   +46 (0)8 505 787 23
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.