You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2004/11/04 00:02:10 UTC

Re: [mp2 patch] anon subs B::Deparse deployment replacement

Stas Bekman wrote:
> This patch replaces the B::Deparse logic for anonsubs with a different
> approach.

Any comments?

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2 patch] anon subs B::Deparse deployment replacement

Posted by Stas Bekman <st...@stason.org>.
Sorry for taking so long to reply, I got back to work on this code now.

>>>> - i'm not sure if I can use a static global variable as a mutex (see
>>>>   XXX in the patch)
>>
>>
>>> I don't think there is a problem with that. But couldn't the 
>>> modperl_global.*
>>> stuff be used for this instead ?
>>
>>
>> I thought of that.
>>
>> 1) I'm not sure it's a good idea to use a single mutex for several 
>> unrelated tasks. That'll slow things down.
> 
> 
> As far as I can see, each different modperl_global entrie defined with
> the use of MP_GLOBAL_DECL() gets it's own mutex.

that's correct. I've failed to see that behind multiple macros :(

>> 2) I'm not sure how to get hold of that modperl_global variable when 
>> we need it.
> 
> 
> You don't need it. You can just :
> MP_GLOBAL_DECL(anonsub_cnt, int)
> 
> And you then get modperl_global_get_anonsub_cnt() for free.

I don't need it for free, since I need to increment and do locking anyway, 
so I did use the global type, but I've replaced the MP_GLOBAL_DECL with just:

/*** anon handlers code ***/

static modperl_global_t MP_global_anon_cnt;

void modperl_global_anon_cnt_init(apr_pool_t *p)
{
     int *data = (int *)apr_pcalloc(p, sizeof(int));
     *data = 0;
     modperl_global_init(&MP_global_anon_cnt, p, (void *)data, "anon_cnt");
}

int modperl_global_anon_cnt_next(void)
{
     int next;
     /* XXX: inline lock/unlock? */
     modperl_global_lock(&MP_global_anon_cnt);

     next = ++*(int *)(MP_global_anon_cnt.data);

     modperl_global_unlock(&MP_global_anon_cnt);

     return next;
}

since this is all is needed. What do you think about XXX? should I replace 
those calls with copy-n-pasted locking code? I see they aren't MP_INLINE 
so I'm not sure whether the compiler will inline those for us.

>> [...]
>> as for APR_ANYLOCK, why doug has used the perl locking routines in 
>> first place?
> 
> 
> Only reason I can see is that if you use Perl's locking routines, when they
> are not needed (i.e. no-ithreads), they are #defined as no-ops, while 
> apr_anylock
> stuff does have a small overhead even if you pick the apr_anylock_none 
> type (one
> pointer dereferencing + integer cmp).

so it's the best to stick with perl locking functions then.

Thanks Philippe!


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2 patch] anon subs B::Deparse deployment replacement

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> 
>>Stas Bekman wrote:
>>
>>>Stas Bekman wrote:
>>>
>>>>This patch replaces the B::Deparse logic for anonsubs with a different
>>>>approach.
>>> 
>>>Any comments?
>>
>>Sorry, I thought I had replied to that one.
>>
>>Stas Bekman wrote:
>>
>>>- i'm not sure if I can use a static global variable as a mutex (see
>>>   XXX in the patch)
> 
>>I don't think there is a problem with that. But couldn't the 
>>modperl_global.*
>>stuff be used for this instead ?
> 
> I thought of that.
> 
> 1) I'm not sure it's a good idea to use a single mutex for several 
> unrelated tasks. That'll slow things down.

As far as I can see, each different modperl_global entrie defined with
the use of MP_GLOBAL_DECL() gets it's own mutex.

> 2) I'm not sure how to get hold of that modperl_global variable when we 
> need it.

You don't need it. You can just :
MP_GLOBAL_DECL(anonsub_cnt, int)

And you then get modperl_global_get_anonsub_cnt() for free.

> 
> [...]
> as for APR_ANYLOCK, why doug has used the perl locking routines in first 
> place?

Only reason I can see is that if you use Perl's locking routines, when they
are not needed (i.e. no-ithreads), they are #defined as no-ops, while apr_anylock
stuff does have a small overhead even if you pick the apr_anylock_none type (one
pointer dereferencing + integer cmp).

-- 
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2 patch] anon subs B::Deparse deployment replacement

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:
> Stas Bekman wrote:
> 
>> Stas Bekman wrote:
>>
>>> This patch replaces the B::Deparse logic for anonsubs with a different
>>> approach.
>>
>>  
>> Any comments?
> 
> 
> Sorry, I thought I had replied to that one.
> 
> Stas Bekman wrote:
> 
>> - i'm not sure if I can use a static global variable as a mutex (see
>>    XXX in the patch)

> I don't think there is a problem with that. But couldn't the 
> modperl_global.*
> stuff be used for this instead ?

I thought of that.

1) I'm not sure it's a good idea to use a single mutex for several 
unrelated tasks. That'll slow things down.

2) I'm not sure how to get hold of that modperl_global variable when we 
need it.

>> - should we do mutex locking only for threaded mpm? (see XXX in the
>>    patch) in which case, it's probably going to be too expensive to
>>    test modperl_threaded_mpm or not?).
> 
> 
> Well, first, you modperl_threaded_mpm isn't expensive anymore:
> 
>   static int MP_threaded_mpm = 0;
>   int modperl_threaded_mpm(void)
>   {
>       return MP_threaded_mpm;
>   }
> 
> But, really, we should be able to reuse either some of the modperl_global.*
> stuff for this or the APR_ANYLOCK stuff so that we can get mutex locking
> for threaded mpms and near 0-overhead for prefork.

as for modperl_global_* please see above.

as for APR_ANYLOCK, why doug has used the perl locking routines in first 
place?

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2 patch] anon subs B::Deparse deployment replacement

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Stas Bekman wrote:
> Stas Bekman wrote:
> 
>>This patch replaces the B::Deparse logic for anonsubs with a different
>>approach.
>  
> Any comments?

Sorry, I thought I had replied to that one.

Stas Bekman wrote:
> - i'm not sure if I can use a static global variable as a mutex (see
>    XXX in the patch)

I don't think there is a problem with that. But couldn't the modperl_global.*
stuff be used for this instead ?

> - should we do mutex locking only for threaded mpm? (see XXX in the
>    patch) in which case, it's probably going to be too expensive to
>    test modperl_threaded_mpm or not?).

Well, first, you modperl_threaded_mpm isn't expensive anymore:

   static int MP_threaded_mpm = 0;
   int modperl_threaded_mpm(void)
   {
       return MP_threaded_mpm;
   }

But, really, we should be able to reuse either some of the modperl_global.*
stuff for this or the APR_ANYLOCK stuff so that we can get mutex locking
for threaded mpms and near 0-overhead for prefork.

> if all anonsub handlers are
>    compiled at run-time, there will be no overhead what so over at
>    run-time. so probably this can be just documented.
> - when PerlScope is utilized we need to croak if the handler wasn't
>    compiled+registered before perl_clone, since if this happens we may
>    have one interpreter that compiles and registers the anon-sub
>    handler but another one is run
> - we need more tests

-- 
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5