Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-06-08 Thread Matt S Trout
On Fri, May 29, 2009 at 11:49:45AM -0500, Stephen Clouse wrote:
> On Thu, May 28, 2009 at 5:48 PM, Stephen Clouse 
> wrote:
> 
> > Commenting that out, then theoretically (note that this is totally untested
> > at the moment, but I intend to tomorrow):
> >
> 
> Well, it was worth a try, but obviously too much voodoo.  Catalyst complains
> about not being able to find //_DISPATCH.  Something internal gets fried
> with the delayed setup call.
> 
> This, on the other hand, works perfectly, although less memory-efficient --
> one full compile of Catalyst per vhost.  Even so, this should be a win over
> the traditional FastCGI deployment (since the optree will at least still be
> shared within the vhost interpreter pool).

I doubt it.

FastCGI isn't "traditional" for Catalyst - it's what people switched to
because mod_perl almost never has a better memory/performance profile.

Especially since most of the mod_perl cleverness relies on interpreter
cloning, which unshares a huge amount of stuff that -can- be shared across
a fork.

-- 
Matt S Trout Catalyst and DBIx::Class consultancy with a clue
 Technical Director  and a commit bit: http://shadowcat.co.uk/catalyst/
 Shadowcat Systems Limited
  mst (@) shadowcat.co.ukhttp://shadowcat.co.uk/blog/matt-s-trout/

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-06-01 Thread Tomas Doran

Matthias Dietrich wrote:

Hi,

One solution to this would be to keep a hash of log class instances 
per vhost, and then ensure to replace the logger being used at the 
start of each hit - this should do what you're looking for..


yes, I thought I have to do it in such a way.  Where would be the best 
point to get the right logger?


I'm thinking something like this:

{
my %loggers;
after prepare => sub {
my $class = shift;
my $host = $c->req->hoatname
	my $logger = $loggers{host} ||= My::Logger->new( logfile => 
$class->path_to('logs', "$host.log") );

$class->log( $logger );
};
}

(untested)

Cheers
t0m

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-31 Thread Matthias Dietrich

Hi,

One solution to this would be to keep a hash of log class instances  
per vhost, and then ensure to replace the logger being used at the  
start of each hit - this should do what you're looking for..


yes, I thought I have to do it in such a way.  Where would be the best  
point to get the right logger?


matt

--
rainboxx Matthias Dietrich
Freier Software Engineer

rainboxx  |  Tel.: +49 (0) 151 / 50 60 78 64
Tölzer Str. 19|  Mail: m...@rainboxx.de
70372 Stuttgart   |  WWW : http://www.rainboxx.de

XING: https://www.xing.com/profile/Matthias_Dietrich18
GULP: http://www.gulp.de/profil/rainboxx.html





PGP.sig
Description: Signierter Teil der Nachricht
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-29 Thread Stephen Clouse
On Thu, May 28, 2009 at 5:48 PM, Stephen Clouse wrote:

> Commenting that out, then theoretically (note that this is totally untested
> at the moment, but I intend to tomorrow):
>

Well, it was worth a try, but obviously too much voodoo.  Catalyst complains
about not being able to find //_DISPATCH.  Something internal gets fried
with the delayed setup call.

This, on the other hand, works perfectly, although less memory-efficient --
one full compile of Catalyst per vhost.  Even so, this should be a win over
the traditional FastCGI deployment (since the optree will at least still be
shared within the vhost interpreter pool).


PerlOptions +Parent
PerlSwitches -I/path/to/myapp/lib
PerlSetEnv MYAPP_CONFIG foo.conf
SetHandler modperl
PerlResponseHandler MyApp



PerlOptions +Parent
PerlSwitches -I/path/to/myapp/lib
PerlSetEnv MYAPP_CONFIG bar.conf
SetHandler modperl
PerlResponseHandler MyApp


-- 
Stephen Clouse 
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-29 Thread Tomas Doran

Stuart Watt wrote:
True, we did need to keep each application using processes which are 
separate. This was an issue when we used PerlEx (the ActivePerl style 
mod_perl approach) but we now use FastCGI (clients use Windows, etc.) 
and IIS freely creates many processes, and makes it really easy to set 
environment variables for them from its configuration files. The IIS 
FastCGI mechanism was developed closely with Zend, and I guess PHP faced 
the same kind of issue, and this was their solution.


So I guess that IIS starts a different set of FCGI processes per vhost.

Which will fix all your problems nicely as everything exists in it's own 
process space, and each process only serves the vhost it was brought up 
to serve.


I can't see this strategy working so good if you had several hundred 
active vhosts at the same time however...


200x copies of the same application per server won't work so nice...

Or IIS would be tearing down and starting new FCGI processes per request 
if the max processes limit is < no of active vhosts.. That'd be, well, 
CGI then..


So yes, for most uses, this is a 'get out of jail free' card, but 
doesn't in any way solve the core architectural issue at hand.


I'll wikify the config trick for now; we're close to production 
deadlines right now, but I do want to get this out there!


That's great, thank you very much!

Cheers
t0m

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-28 Thread Stephen Clouse
On Thu, May 28, 2009 at 12:00 PM, Tomas Doran  wrote:

> Sorry to let you down, but this mail was written in 2006, and contains the
> plan as it was then.
>
> Unfortunately, nobody has stepped up to the plate to do the requisite work
> to split the application class and context (which is what that mail is
> hinting at).


/sadpanda :(


> The work done in 5.80 makes this _significantly_ easier than it used to be
> if someone wants to step up to help tackle it - I think more work is
> involved munging the test suite than actually hacking Catalyst itself..


Hmmwell, something I might get to eventually, but probably not a project
for Still-Reading-Tutorials Guy.


> It _is_ still possible to have one application instance serving many
> vhosts, and many of the parts are there - supporting this inside your
> application isn't too difficult, but unfortunately you can't yet get it 'out
> of the box'.


It seems to me it could be done almost entirely within mod_perl using some
interpreter pool trickery and by deferring AppClass->setup().  I assume that
is the call in the base package that instantiates everything for the
Catalyst app, yes?

Commenting that out, then theoretically (note that this is totally untested
at the moment, but I intend to tomorrow):

PerlModule AppClass


PerlOptions +Clone
PerlSetVar catalyst_instance foo
SetHandler modperl
PerlResponseHandler AppClass



PerlOptions +Clone
PerlSetVar catalyst_instance bar
SetHandler modperl
PerlResponseHandler AppClass


And then a custom mp handler that does AppClass->setup() with an appropriate
config (based on catalyst_instance) on the first request and then passes off
to AppClass->handle_request.  By deferring the instantiation you restrict
the package globals to the virtual host's interpreter pool (so multiple apps
won't collide), but still gain the optree sharing by cloning from the
top-level interpreter with all the Catalyst code pre-loaded.

I welcome anyone crazy enough to try this before I do :)

-- 
Stephen Clouse 
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-28 Thread Stuart Watt

Tomas Doran wrote:
If you try to run multiple copies of the same application in the same 
perl process, it won't work like you expect - the setting will come 
from the first application loaded..


Your solution just makes it much easier to have multiple deployment 
environments with different configurations, but these environments 
still have to have a different perl interpreter each. 
True, we did need to keep each application using processes which are 
separate. This was an issue when we used PerlEx (the ActivePerl style 
mod_perl approach) but we now use FastCGI (clients use Windows, etc.) 
and IIS freely creates many processes, and makes it really easy to set 
environment variables for them from its configuration files. The IIS 
FastCGI mechanism was developed closely with Zend, and I guess PHP faced 
the same kind of issue, and this was their solution.


I'll wikify the config trick for now; we're close to production 
deadlines right now, but I do want to get this out there!


--S
--
Stuart Watt
ARM Product Developer
Information Balance
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-28 Thread Tomas Doran

Matthias Dietrich wrote:
do you use Log::Log4perl in your Catalyst apps?  Months ago I wrote a 
message to the list about problems with Log::Log4perl and multiple 
instances of Catalyst within one Apache.  Nobody answered and because 
it's currently not very important to me (not in production environment 
yet) I didn't follow-up.


The problem was to separate each VirtualHosts Catalyst into different 
log files which didn't worked.  Catalyst always logged into the file 
from the latest VirtualHost.  Maybe I have some short time tomorrow to 
create a local test case (I use the included server now so I have to 
switch to Apache again).


This is to be expected.

The instance of the logging class to use is stored in class data inside 
your application class.


One solution to this would be to keep a hash of log class instances per 
vhost, and then ensure to replace the logger being used at the start of 
each hit - this should do what you're looking for..


Cheers
t0m


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-28 Thread Tomas Doran

Stuart Watt wrote:
I did a simple tweak to the configuration file management so environment 
variables could be substituted into configuration files. All I added to 
MyApp.pm was:



Then, I could use YAML settings like:

session:
  storage:   '__ENV(TEMP)__/sessions'

It was pretty easy for us to get web servers to set environment 
variables, so this trick allowed us to have multiple systems with 
different database and file directories set pretty straightforwardly.


That's a nice trick, it would be great to see it documented. Do you 
fancy writing up a wiki page, or adding something to the manual, or even 
patching ConfigLoader so that it supports a syntax like this by default?


This may be one approach you could use, but there are likely better 
ones. Especially since I'm still stuck at 5.70 waiting for a good 
opportunity to upgrade without anyone (even my colleagues) noticing. 
This is a 5.70 solution, but should be OK in 5.80, I would guess.


Yes, that'll work in 5.80, but still won't solve the issue at hand.

If you try to run multiple copies of the same application in the same 
perl process, it won't work like you expect - the setting will come from 
the first application loaded..


Your solution just makes it much easier to have multiple deployment 
environments with different configurations, but these environments still 
have to have a different perl interpreter each.


Cheers
t0m

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-28 Thread Tomas Doran

Stephen Clouse wrote:
I have seen hints dropped in places such as 
http://osdir.com/ml/lang.perl.modules.dbix-class/2006-08/msg00188.html 
that Catalyst 5.80 has gained more explicit support for such a 
deployment model under mod_perl, but so far I have come up empty on 
finding references or examples of how to actually do it.


Some guidance would be greatly appreciated.


Hiya.

Sorry to let you down, but this mail was written in 2006, and contains 
the plan as it was then.


Unfortunately, nobody has stepped up to the plate to do the requisite 
work to split the application class and context (which is what that mail 
is hinting at).


The work done in 5.80 makes this _significantly_ easier than it used to 
be if someone wants to step up to help tackle it - I think more work is 
involved munging the test suite than actually hacking Catalyst itself..


It _is_ still possible to have one application instance serving many 
vhosts, and many of the parts are there - supporting this inside your 
application isn't too difficult, but unfortunately you can't yet get it 
'out of the box'.


Cheers
t0m

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-27 Thread Matthias Dietrich

Hi Stuart,

do you use Log::Log4perl in your Catalyst apps?  Months ago I wrote a  
message to the list about problems with Log::Log4perl and multiple  
instances of Catalyst within one Apache.  Nobody answered and because  
it's currently not very important to me (not in production environment  
yet) I didn't follow-up.


The problem was to separate each VirtualHosts Catalyst into different  
log files which didn't worked.  Catalyst always logged into the file  
from the latest VirtualHost.  Maybe I have some short time tomorrow to  
create a local test case (I use the included server now so I have to  
switch to Apache again).


Regards,
 matt

--
rainboxx Matthias Dietrich
Freier Software Engineer

rainboxx  |  Tel.: +49 (0) 151 / 50 60 78 64
Tölzer Str. 19|  Mail: m...@rainboxx.de
70372 Stuttgart   |  WWW : http://www.rainboxx.de

XING: https://www.xing.com/profile/Matthias_Dietrich18
GULP: http://www.gulp.de/profil/rainboxx.html





PGP.sig
Description: Signierter Teil der Nachricht
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-27 Thread Stuart Watt
I did a simple tweak to the configuration file management so environment 
variables could be substituted into configuration files. All I added to 
MyApp.pm was:


__PACKAGE__->config('Plugin::ConfigLoader' =>
   {file => 'MyApp.yaml',
substitutions => {
   ENV => sub {
   my ($c, $v) = @_;
   if (! defined($ENV{$v})) {
   die("Missing environment variable: $v");
   } else {
   return $ENV{$v};
   }
   }
}
   }
);

Then, I could use YAML settings like:

session:
 storage:   '__ENV(TEMP)__/sessions'

It was pretty easy for us to get web servers to set environment 
variables, so this trick allowed us to have multiple systems with 
different database and file directories set pretty straightforwardly.


This may be one approach you could use, but there are likely better 
ones. Especially since I'm still stuck at 5.70 waiting for a good 
opportunity to upgrade without anyone (even my colleagues) noticing. 
This is a 5.70 solution, but should be OK in 5.80, I would guess.


All the best
Stuart


Stephen Clouse wrote:

Hello all,

I am fairly new to Catalyst and am currently evaluating it for use on 
several projects, a couple of them being conversions of an existing 
system to use Catalyst instead of the hacked-together in-house 
framework currently in use.  Those apps have the old 
per-customer/mass-blog-hosting model going -- the exact same app 
deployed with different database/filesystem path configurations 
(currently set using mod_perl configuration directives inside 
 sections in Apache config), previously accomplished with 
Catalyst either with FastCGI deployment or ACCEPT_CONTEXT magic that I 
don't quite understand yet.


I have seen hints dropped in places such as 
http://osdir.com/ml/lang.perl.modules.dbix-class/2006-08/msg00188.html 
that Catalyst 5.80 has gained more explicit support for such a 
deployment model under mod_perl, but so far I have come up empty on 
finding references or examples of how to actually do it.


Some guidance would be greatly appreciated.

--
Stephen Clouse mailto:stephenclo...@gmail.com>>

--
This message was scanned by ESVA and is believed to be clean.
Click here to report this message as spam. 




___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
  


--
Stuart Watt
ARM Product Developer
Information Balance
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Multiple instances of same app with 5.80 under mod_perl

2009-05-27 Thread Stephen Clouse
Hello all,

I am fairly new to Catalyst and am currently evaluating it for use on
several projects, a couple of them being conversions of an existing system
to use Catalyst instead of the hacked-together in-house framework currently
in use.  Those apps have the old per-customer/mass-blog-hosting model going
-- the exact same app deployed with different database/filesystem path
configurations (currently set using mod_perl configuration directives inside
 sections in Apache config), previously accomplished with
Catalyst either with FastCGI deployment or ACCEPT_CONTEXT magic that I don't
quite understand yet.

I have seen hints dropped in places such as
http://osdir.com/ml/lang.perl.modules.dbix-class/2006-08/msg00188.html that
Catalyst 5.80 has gained more explicit support for such a deployment model
under mod_perl, but so far I have come up empty on finding references or
examples of how to actually do it.

Some guidance would be greatly appreciated.

-- 
Stephen Clouse 
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/