[sf-perl] All these Perl web frameworks

Bryan Beeley bryan at beeley.org
Tue Aug 7 14:40:26 PDT 2012

On 08/03/2012 09:14 AM, Mark Grimes wrote:
> Agree, Catalyst is very robust, flexible, and highly recommended, but
> it is a bit of a memory hog. Bryan, can you expand on taking advantage
> of COW? I've been using plack and the FCGI backends, but I'm not sure
> when exactly when it is loading modules vs forking. In order to
> improve the hot deployment, I've been thinking about switching to
> server::starter/startlet and proxying it behind apache, but again I'm
> not sure about load vs fork.

Unfortunately, I don't use FCGI, so I don't really know the answer to 
this.  At work we actually still use mod_perl in Apache 2 (gasp!), 
simply because we have optimized its performance enough that switching 
hasn't seemed worth the effort.  Our Apache instance is sitting behind 
nginx, so there is also that.

The general idea with copy-on-write is that you want to find the place 
in the framework you are using where it forks, and make sure you load 
everything before that gets called.  For Moose-based code this means you 
want to explicitly use modules rather than letting Moose load them for 
you automatically.  For DBIx::Class based code it helps to instantiate 
your schema so that all the result, result source, and result set 
classes are loaded.  In applications that have a lot of static lookup 
tables in the database, you might want to load all of them into memory 
(make sure DBIx::Class::Cursor::Cached cursors get loaded, etc).  We 
pre-load all the Template Toolkit templates into memory by reaching into 
Catalyst, pulling out a template object, and manually calling 
$template_ob->process($template_file, {}, \$output) for all template files.

If I had to guess about FCGI, assuming you are using FCGI::ProcManager, 
I would say load everything that you want to be in COW memory before 
pm_manage was called.  It seems like you would do something similar with 
Starlet/Parallel::Prefork.  This is just a guess though.

For Apache+mod_perl you specify a PerlPostConfigRequire script to do all 
your initialization.

For Starman there is a --preload-app option or the -M option.


More information about the SanFrancisco-pm mailing list