[cgiapp] use persisten instance of cgiapp with cgi::fast?
Dietrich Streifert
dietrich.streifert at visionet.de
Tue Jul 20 09:58:57 EDT 2010
Just to share what my investigations revealed:
The main problem of reusing an instance of CGI::Application is that some
variables are not reinitialized at consecutive runs.
This is $instance->{__QUERY_OBJ} which holds the current query object
and $instance->{__HEADER_PROPS} which holds the current set header
properties as set via setHeader and addHeader.
This experiment ended up setting this variables to their initial values.
The code of the fcgi script modifies as follows, with some additionals
process spawning control of FCGI::ProcManager:
#!/usr/bin/perl -wT
#
##
use strict;
use CGI::Fast;
use FCGI::ProcManager;
use MyApp;
my $proc_manager = FCGI::ProcManager->new( {processes => 3} );
$proc_manager->pm_manage();
my $app = MyApp->new();
while (my $q = CGI::Fast->new()) {
$proc_manager->pm_pre_dispatch();
$app->{__HEADER_PROPS} = {};
$app->{__QUERY_OBJ} = $q;
$app->run();
$proc_manager->pm_post_dispatch();
}
This, of course, relies on internal (private/protected) names and should
be used at own risk.
There better should be some init_vars method in CGI::Application which
then offers an official way to reuse the instance. Or even the run
method should call init_vars at first.
And now, without profiling, the response time of the fcgi app is
comparable to the speedy_cgi version.
Thank you for reading along.
Best regards...
Am 19.07.2010 13:16, schrieb Dietrich Streifert:
> Hello All,
>
> I'm currently using speedy_cgi as a persistent perl process and wanted
> to test if fcgi would be an option for me.
>
> I've installed and configured mod_fcgid with apache2 on linux and tested
> the base functions and the fcgi interface successfully.
>
> Then I read the article in
>
>
> http://cgi-app.org/index.cgi?FastChttp://cgi-app.org/index.cgi?FastCGIGI
>
> And managed to run my cgiapp with this method.
>
> As the method implies a new instance of my cgiapp is created for every
> request. With speedy_cgi I used to only create a cgiapp instance once
> and reuse it on request. I consider my cgiapp to be a big one and it
> would benefit a lot from being instantiated once and the instance
> reused often.
>
> So I did the following additions/modifications to the example mentioned
> in the article:
>
> use CGI::Fast;
>
> my $app = MyCGIApplication->new();
> while (my $q = CGI::Fast->new()){
> $app->query($q);
> $app->run();
> }
>
> This basicly worked but as soon as multiple requests to the script are
> initiated or request answers exceed some magic size the clients get
> incomplete answers ie. the page code stops unexpected somewhere between
> head and end.
>
> So my questions are:
>
> What is wrong with my modifications?
> Do I have to flush some buffers in order to ensure complete delivery to
> the client?
> Are there any other possibilities to achieve a persisten reference to my
> cgiapp that does not get initializied at every request? (besides
> mod_perl or speedy_cgi).
>
> Any help would be great.
>
> Best regards...
>
--
Mit freundlichen Grüßen
Dietrich Streifert
--
Visionet GmbH
Firmensitz: Am Weichselgarten 7, 91058 Erlangen
Registergericht: Handelsregister Fürth, HRB 6573
Geschäftsführer: Stefan Lindner
More information about the cgiapp
mailing list