nginx, fcgi+perl forking a new process per request ...

Grzegorz Nosek grzegorz.nosek at gmail.com
Sat Mar 20 21:14:13 MSK 2010


On sob, mar 20, 2010 at 02:37:07 +0200, Stefan Parvu wrote:
> 
> Here is a short review about a simple FCGI comparation: perl/native
> on Solaris 10U8, using nginx 32bit.
> 
> Thanks to gnosek for pointers about the native version.
> 
> http://systemdatarecorder.org:9009/bugzilla/show_bug.cgi?id=51

Interesting. As for the large response time, you'd generally run a bunch
of fcgiwraps (e.g. by using the -c option) to improve responsiveness.
The memory cost should be negligible compared to a single instance.

Right now all the requests are processed sequentially, so if your CGI
script slept for 5 seconds, you'd get 0.2 req/sec tops plus an
absolutely abysmal response time.

Of course, this also applies to the Perl wrapper. You can implement a
simplistic prefork there by replacing:

-----------------------------
my $pid = fork();

if( $pid == 0 ) {
	&main;
	exit 0;
}
-----------------------------

with:

-----------------------------
for (1 .. HOWEVER_MANY_CHILDREN_YOU_WANT) {
	my $pid = fork();

	if( $pid == 0 ) {
		&main;
		exit 0;
	}
}
-----------------------------

Also, if your real CGI scripts you are going to run are all Perl-based,
you may get better results by converting them to talk FastCGI directly
to save on the overhead of launching Perl and loading its modules once
per request. However, this includes some gotchas and is generally
getting way off topic :)

Best regards,
 Grzegorz Nosek



More information about the nginx mailing list