Why ist fastcgi so slow?


(Andreas S.) #1

Hi,

I am using mod_fastcgi and ruby 1.8 with the following example script:

#!/usr/local/bin/ruby
require 'cgi’
require 'fcgi’
FCGI.each_cgi do |cgi|
cgi.out{ “Test” }
end

This is extremely slow, I get exactly 1.00 requests per second (measured
with ApacheBench). But why?

Andreas


(Ara.T.Howard) #2

Hi,

I am using mod_fastcgi and ruby 1.8 with the following example script:

#!/usr/local/bin/ruby
require 'cgi’
require 'fcgi’
FCGI.each_cgi do |cgi|
cgi.out{ “Test” }
end

This is extremely slow, I get exactly 1.00 requests per second (measured
with ApacheBench). But why?

what is the name of the file? foo.cgi or foo.fcgi? if it is foo.cgi apache
will use the cgi handle and the fcgi module behaves as a normal (slow) cgi
process…

···

On 29 Feb 2004, Andreas Schwarz wrote:

Andreas

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: http://www.ngdc.noaa.gov/stp/
TRY :: for l in ruby perl;do $l -e “print “\x3a\x2d\x29\x0a””;done
===============================================================================


(Andreas S.) #3

Ara.T.Howard wrote:

···

On 29 Feb 2004, Andreas Schwarz wrote:

Hi,

I am using mod_fastcgi and ruby 1.8 with the following example script:

#!/usr/local/bin/ruby
require 'cgi’
require 'fcgi’
FCGI.each_cgi do |cgi|
cgi.out{ “Test” }
end

This is extremely slow, I get exactly 1.00 requests per second (measured
with ApacheBench). But why?

what is the name of the file? foo.cgi or foo.fcgi?

foo.rb, and yes, it is executed by mod_fastcgi.


(Ara.T.Howard) #4

hmm. can you see it running with ‘ps -elf’?? can you show the assoc
httpd.conf sections? the reason i ask it that this performance seems only
explainable if the script we firing up the ruby interpreter each time…

-a

···

On 29 Feb 2004, Andreas Schwarz wrote:

Ara.T.Howard wrote:

On 29 Feb 2004, Andreas Schwarz wrote:

Hi,

I am using mod_fastcgi and ruby 1.8 with the following example script:

#!/usr/local/bin/ruby
require 'cgi’
require 'fcgi’
FCGI.each_cgi do |cgi|
cgi.out{ “Test” }
end

This is extremely slow, I get exactly 1.00 requests per second (measured
with ApacheBench). But why?

what is the name of the file? foo.cgi or foo.fcgi?

foo.rb, and yes, it is executed by mod_fastcgi.

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: http://www.ngdc.noaa.gov/stp/
TRY :: for l in ruby perl;do $l -e “print “\x3a\x2d\x29\x0a””;done
===============================================================================


(Andreas S.) #5

Ara.T.Howard wrote:

Ara.T.Howard wrote:

Hi,

I am using mod_fastcgi and ruby 1.8 with the following example script:

#!/usr/local/bin/ruby
require 'cgi’
require 'fcgi’
FCGI.each_cgi do |cgi|
cgi.out{ “Test” }
end

This is extremely slow, I get exactly 1.00 requests per second (measured
with ApacheBench). But why?

what is the name of the file? foo.cgi or foo.fcgi?

foo.rb, and yes, it is executed by mod_fastcgi.

hmm. can you see it running with ‘ps -elf’??

Yes.

can you show the assoc
httpd.conf sections?

I only added “AddHandler fastcgi-script” to my .htaccess.

the reason i ask it that this performance seems only
explainable if the script we firing up the ruby interpreter each time…

Even then it would be much faster.

···

On 29 Feb 2004, Andreas Schwarz wrote:

On 29 Feb 2004, Andreas Schwarz wrote:


(Andreas S.) #6

Andreas Schwarz wrote:

Ara.T.Howard wrote:

can you show the assoc
httpd.conf sections?

I only added “AddHandler fastcgi-script” to my .htaccess.

No, I had also set the fastcgi options -restart and -autoupdate in my
httpd.conf. After restarting Apache it worked with good speed (but
still a bit slower than a php script calling info()); then I changed the
file foo.rb, it was reloaded because of -autoupdate, and after that it
was again very slow. There seems to be some bug with -restart and/or
-autoupdate; maybe it’s the one described in
http://www.fastcgi.com/archives/fastcgi-developers/2002-July/002175.html.
I will try a more recent version of mod_fastcgi soon.


(Ara.T.Howard) #7

Ara.T.Howard wrote:

Ara.T.Howard wrote:

Hi,

I am using mod_fastcgi and ruby 1.8 with the following example script:

#!/usr/local/bin/ruby
require 'cgi’
require 'fcgi’
FCGI.each_cgi do |cgi|
cgi.out{ “Test” }
end

This is extremely slow, I get exactly 1.00 requests per second (measured
with ApacheBench). But why?

what is the name of the file? foo.cgi or foo.fcgi?

foo.rb, and yes, it is executed by mod_fastcgi.

hmm. can you see it running with ‘ps -elf’??

Yes.

can you show the assoc
httpd.conf sections?

I only added “AddHandler fastcgi-script” to my .htaccess.

really? i needed to


LoadModule fastcgi_module modules/mod_fastcgi.so
FastCgiIpcDir logs/fastcgi


ScriptAlias /fcgi-bin/ “/usr/local/httpd-2.0.47//fcgi-bin/”


<Directory “/usr/local/httpd-2.0.47//fcgi-bin”>
AllowOverride All
Options None
Order allow,deny
Allow from all
SetHandler fastcgi-script


AddHandler fastcgi-script .fcgi

i suppose the only pertinent bits are the first and last ones… did you
compile the fastcgi module in statically? if not it would need loaded…

the reason i ask it that this performance seems only
explainable if the script we firing up the ruby interpreter each time…

Even then it would be much faster.

yeah - for me, using

#!/usr/local/ruby-1.8.0/bin/ruby
require 'cgi’
require ‘fcgi’

FCGI.each_cgi do |cgi|
content = ''
env = []
cgi.env_table.each do |k,v|
env << [k,v]
end
env.sort!
env.each do |k,v|
content << %Q(#{k} => #{v}
\n)
end
cgi.out{content}
end

i get around 20 requests per second from a very slow machine, uploading on a
cable connection, to a machine behind some serious pack sniffing software in a
government firewall… you’ve definitely got something wrong… are you
perhaps using the pure ruby fastcgi version? i seem to recall there is one…

-a

···

On 29 Feb 2004, Andreas Schwarz wrote:

On 29 Feb 2004, Andreas Schwarz wrote:

On 29 Feb 2004, Andreas Schwarz wrote:

===============================================================================
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: http://www.ngdc.noaa.gov/stp/
TRY :: for l in ruby perl;do $l -e “print “\x3a\x2d\x29\x0a””;done
===============================================================================


(Shu-yu Guo) #8

Ara.T.Howard wrote:

i get around 20 requests per second from a very slow machine, uploading on a
cable connection, to a machine behind some serious pack sniffing software in a
government firewall… you’ve definitely got something wrong… are you
perhaps using the pure ruby fastcgi version? i seem to recall there is one…

Yes, there is one, but if you (Ara) are using FCGI#each_cgi, you’re
using it too, since the C version has no function. I recall that there
should be speed hits if you use each_cgi since the CGI object takes a
while to initialize, but even then his case sounds awfully slow…

···


That’s some catch, that Catch-22.
Oh, it’s the best there is.