logo       

Re: PerlChild{Init|Exit}Handler / Apache::DProf: msg#00613

Subject: Re: PerlChild{Init|Exit}Handler / Apache::DProf
Mike Zelina wrote:
This sounds like the reason why Apache::DProf won't work for me
on Win32...  I did get it to not crash in mp2 by changing output
to use PerlIO, but it never created any output in the tmon.out file.

Since DProf uses PerlChildInitHandlers, and win32 doesn't support
that even in mp2, I guess I'm hosed (apart from booting to Linux
of course!).  Are there any events that get thrown when a new thread
is spawned that I can catch within DProf to make it work on all
platforms??

I think PerlChildInitHandler works just fine under win32, however it's called only once when the only process starts. I haven't verified that though, since I don't run win32. In any case that doesn't matter since Apache::DProf needs to be attached to a perl interpreter. So in the forked environment, child_init will do the work as before, in the threaded enviroment we can use the special CLONE block to make things happen on when an interpreter is perl_clone()'d.

perlmod says:

       Ithreads work by cloning the data tree so that no data is shared
       between different threads. These threads can be used using the threads
       module or by doing fork() on win32 (fake fork() support). When a thread
       is cloned all Perl data is cloned, however non-Perl data cannot be
       cloned automatically.  Perl after 5.7.2 has support for the "CLONE"
       special subroutine .  In "CLONE" you can do whatever you need to do,
       like for example handle the cloning of non-Perl data, if necessary.
       "CLONE" will be executed once for every package that has it defined (or
       inherits it).  It will be called in the context of the new thread, so
       all modifications are made in the new area.


Here is a quick command line example:

use constant THREADS => eval {require threads };

if (THREADS) {
    sub CLONE {warn "I was cloned\n"; }
    threads->new(sub {})->detach;
}

under mod_perl that would probably be something like this:

if (Apache::MPM_IS_THREADED) {
    sub CLONE {warn "I was cloned\n"; on_init() }
}
else {
    require Apache::RequestUtil;
    Apache->push_handlers(PerlChildInitHandler => \&on_init);
}

sub on_init { ... }

However I think that 'require threads' might still be needed if CLONE is implemented by threads.xs and not core perl.

This is untested but probably in the right direction.

Once we have a working prototype, I think we should package the if/else into a new single directive, to make things work disregarding whether the mpm is threaded or not.

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




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
linux.arklinux....    user-groups.lin...    kde.usability/2...    ietf.ipp/2002-0...    mail.spam.spamc...    os.netbsd.devel...    audio.cd-record...    text.unicode.de...    php.documentati...    games.fps.halfl...    window-managers...    suse.oracle.gen...    bug-tracking.gn...    video.dvdrip.us...    xfree86.cvs/200...    java.netbeans.m...    network.argus/2...    culture.sf.kill...    debian.ports.al...    freebsd.questio...    qplus.devel/200...    handhelds.palm....   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe