WEBrick and FastCGI response

Reply-To:
Name: Jim Freeze
Phone: (859) 396-5439
Web-Pages: http://www.freeze.org http://www.freebsdportal.com

I have been playing with webrick and fastcgi. I used ab
to measure the performance and see if fastcgi was helping out.
My results are:

test.cgi - webrick & fastcgi
Concurrency Level: 1
Time taken for tests: 44.546 seconds
Complete requests: 100
Requests per second: 2.24 [#/sec] (mean)
Time per request: 445.46 [ms] (mean)

test.rthml - webrick & fastcgi
Concurrency Level: 1
Time taken for tests: 10.200 seconds
Complete requests: 100
Requests per second: 9.80 [#/sec] (mean)
Time per request: 102.00 [ms] (mean)

test.cgi - webrick w/o fastcgi
oncurrency Level: 1
Time taken for tests: 43.583 seconds
Complete requests: 100
Requests per second: 2.29 [#/sec] (mean)
Time per request: 435.83 [ms] (mean)

test.rhtml - webrick w/o fastcgi
Concurrency Level: 1
Time taken for tests: 10.221 seconds
Complete requests: 100
Requests per second: 9.78 [#/sec] (mean)
Time per request: 102.21 [ms] (mean)

I used the standard HTTPServer and only changed between
the following require lines to use webrick with and without
the server

require ‘webrick’ # w/o fastcgi
#require 'webrick/fcgi’a # w/ fastcgi

Am I using fcgi correctly or is it just not having an affect
for these samples?

Thanks

···


Jim Freeze

Hello,

···

On Thu, 27 May 2004 14:18:02 +0900, Jim Freeze jim@freeze.org wrote:

Am I using fcgi correctly or is it just not having an affect
for these samples?

If your response data is larger than 8K you may want to make sure that
you are running the C version of FastCGI. See [ruby-talk: 99910] for
more information.

Best,
Zev

Hello Jim,

Reply-To:
Name: Jim Freeze
Phone: (859) 396-5439
Web-Pages: http://www.freeze.org http://www.freebsdportal.com

Am I using fcgi correctly or is it just not having an affect
for these samples?
Thanks

Maybe it is helpful to see your test.cgi/test.rhtml.
I also you like to know your CPU/Memory combination, because it seems
to be really slow on modern systems.

···

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

Hi Jim,

Jim Freeze wrote:

Reply-To:
Name: Jim Freeze
Phone: (859) 396-5439
Web-Pages: http://www.freeze.org http://www.freebsdportal.com

I have been playing with webrick and fastcgi. I used ab
to measure the performance and see if fastcgi was helping out.
My results are:

test.cgi - webrick & fastcgi
Concurrency Level: 1
Time taken for tests: 44.546 seconds
Complete requests: 100
Requests per second: 2.24 [#/sec] (mean)
Time per request: 445.46 [ms] (mean)

test.rthml - webrick & fastcgi
Concurrency Level: 1
Time taken for tests: 10.200 seconds
Complete requests: 100
Requests per second: 9.80 [#/sec] (mean)
Time per request: 102.00 [ms] (mean)

test.cgi - webrick w/o fastcgi
oncurrency Level: 1
Time taken for tests: 43.583 seconds
Complete requests: 100
Requests per second: 2.29 [#/sec] (mean)
Time per request: 435.83 [ms] (mean)

test.rhtml - webrick w/o fastcgi
Concurrency Level: 1
Time taken for tests: 10.221 seconds
Complete requests: 100
Requests per second: 9.78 [#/sec] (mean)
Time per request: 102.21 [ms] (mean)

I used the standard HTTPServer and only changed between
the following require lines to use webrick with and without
the server

require ‘webrick’ # w/o fastcgi
#require 'webrick/fcgi’a # w/ fastcgi

Am I using fcgi correctly or is it just not having an affect
for these samples?

I tried the same thing. Came to the same conclusion. I tried emailing
Ari, but haven’t got any response. I am also not sure if I use it
correctly. I would like to know a way how I can query if I am actually
using the c fastcgi version.

Here is what I wanted to send to the list a couple of weeks ago, but
never did. Something else came up and I am not sure I even finished the
mail. Nevertheless here it is:

···

Hi folks,

I have tried to contact Ari (the maintainer of webrick-fcgi) with this,
but he still hasn’t answered in a couple of days. Maybe he is not able
to at the moment. My questions are better asked on the list anyway.

I am trying to get webrick-fcgi to work on the Cygwin platform. What I
am not really sure about, is how to find out if it really works the way
it should and how to configure it properly.

fcgi.rb

require ‘fcgi’
require ‘webrick/fcgi’

include WEBrick

dir = File::dirname(File::expand_path(FILE)) + ‘/test’

puts dir

s = WEBrick::HTTPServer.new(
:BindAddress => “0.0.0.0”,
:Port => 8088,
:DocumentRoot => dir,
:Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG),
:CGIPathEnv => ENV[‘PATH’] # Especially for Cygwin
)

mount subdirectories

trap(“INT”){ s.shutdown }
s.start

my test script for cgi/fcgi (from rubygarden)

test.cgi and test.fcgi

#!/usr/bin/env 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

when I access this script with http://localhost:8088/test.cgi I get the
output, but when I access http://localhost:8088/test.fcgi I am asked if
I want to download the file. How can I get the fcgi file to execute
properly or better yet make custom mappings (*.rb files get executed by
fcgi).

Benchmarking gives me:
$ /usr/sbin/ab http://localhost:8088/test.cgi | grep Request
Requests per second: 3.21 [#/sec] (mean)

this probably means that fcgi is never invoked cause my computer AMD
2600+ should be a little faster.

Maybe someone can explain how this module is used correctly?

Thanks
Sascha

require ‘webrick’ # w/o fastcgi
#require 'webrick/fcgi’a # w/ fastcgi

Am I using fcgi correctly or is it just not having an affect
for these samples?

It’s sadly a little more complicated than that. The Webrick FCGI module
(I assume you’re using the one from theinternetco.net) that I wrote is
one to be a FCGI server process, which means you need Apache or another
FCGI-enabled webserver to handle the requests:

Here’s the fastcgi script that starts my app:

require 'webrick/fcgi'
require 'elf'
 
logger = Logger.new($stderr)
$logger = logger
 
require 'db-connection'
 
fc = WEBrick::FCGIServer.new(:Logger => logger)
fc.mount('/', WEBrick::HTTPServlet::FileHandler, File.dirname(__FILE__))
fc.mount('/o', Elf::ClassLoaderServlet)
fc.mount('/creditcards/batch', Elf::CreditCards::BatchServlet)
fc.mount('/forms', Elf::FormServlet)
fc.mount('/new', Elf::FactoryServlet)
fc.start

And I save that as an executable .rbx script file, and I have apache set
to start any .rbx as a fastcgi process.

It shouldn’t give you many perfomance boosts, since it actually runs
-more- code than webrick, but the advantage lies in integration with an
existing web system, and the automatic process start.

(I didn’t want to manage starting webrick daemons at system boot, and I
have tens of scripts already, so having them all running at the same
time is unneccesary, since the loading is very uneven.)

Basically, webrick/fcgi is a replacement for HTTPServer, to speak FCGI
instead of HTTP.

I’m also planning a cleanup release that fixes some things, and after
that, I plan to make Instiki work as a fastcgi (which has issues due to
assumptions about / being the root of the app, so I’ll have to do some
fancy URL rewriting), and making a third release after Instiki works.

Ari

Wow. That seems awfully slow, especially for your hardware.

I did this test on a PIII 800 Mhz w/ 512Mb running Gentoo Linux that was
also running a full X desktop with Eclipse and a bunch of other stuff open
at the time.

The test content was 4454 bytes long. All concurrency levels were 1. I ran
each test over 100 requests, and did it 3 times. The number reported are
the results of the third run.

Webrick serving content via a cgi:
6.26 requests per second

Webrick serving the exact same content as a static HTML file:
54.90 requests per second

Iowa behind Apache 1.3.29 using a mod_ruby handler for communication,
serving the same static content:
72.12 requests per second

Iowa, same configuration, serving the original content which includes
several components and dynamic content generation:
35.70 requests per second

Same combination, but with FastCGI instead of mod_ruby:
37.70 requests per second (interesting, since in some earlier tests, the
FCGI combo was 1-2 requests per second slower).

I was a bit surprised the Iowa was faster than Webrick at serving the static
content, though I suppose by allowing Apache to handle the front end of the
interaction with the browser, Iowa gets to skip out on a lot of the work
that Webrick has to do before the content gets delivered.

I’m eager to run this same test with Webrick/Iowa integration. I’m hopeful
that it will be close to the Apache/Iowa via mod_ruby combination.

Kirk Haines

···

On Thu, 27 May 2004 14:18:02 +0900, Jim Freeze wrote

test.rhtml - webrick w/o fastcgi
Concurrency Level: 1
Time taken for tests: 10.221 seconds
Complete requests: 100
Requests per second: 9.78 [#/sec] (mean)
Time per request: 102.21 [ms] (mean)

Hello,

···

On Thu, 27 May 2004 20:42:00 +0900, Sascha Ebach se@hexatex.de wrote:

I would like to know a way how I can query if I am actually using the c
fastcgi version.

To make it load the C version change your require statement to:
require ‘fcgi.so’

Best,
Zev

Thanks, I’ll take a look at it. However, the response data is only 2k.
The test files I am using are the ones that come in the
download of webrick.

···

On Thursday, 27 May 2004 at 15:13:50 +0900, Zev Blut wrote:

Hello,

On Thu, 27 May 2004 14:18:02 +0900, Jim Freeze jim@freeze.org wrote:

Am I using fcgi correctly or is it just not having an affect
for these samples?

If your response data is larger than 8K you may want to make sure that
you are running the C version of FastCGI. See [ruby-talk: 99910] for
more information.


Jim Freeze
You can create your own opportunities this week. Blackmail a senior
executive.

Hello Jim,

Reply-To:
Name: Jim Freeze
Phone: (859) 396-5439
Web-Pages: http://www.freeze.org http://www.freebsdportal.com

Am I using fcgi correctly or is it just not having an affect
for these samples?
Thanks

Maybe it is helpful to see your test.cgi/test.rhtml.

These files are the tests that come with the webrick download.

I also you like to know your CPU/Memory combination, because it seems
to be really slow on modern systems.

1.5GHz G4, 768MB Ram (Powerbook)

···

On Thursday, 27 May 2004 at 17:47:41 +0900, Lothar Scholz wrote:


Jim Freeze

Hi Ari,

Thanks for clearing that up. I am looking forward for a future release
and more documentation

Sascha

Whoa whoa whoa. There is just too many fcgi’s floating around here. :slight_smile:

I read about fcgi working with webrick, so I thought cool,
I’ll try it. So I downloaded it. It didn’t have an install,
but the install location looked obvious – I put it under
webrick/.

Then I noticed that it needed the ruby bindings to fcgi, so
I downloaded Matz’ ruby bindings to fcgi and tried to install.
That didn’t work because it couldn’t find the fcgi.h include
file. So I downloaded the C version of fcgi, built it and
installed it. Now Matz’ ruby bindings to fcgi installed
correctly.

So I assumed that the only fcgi core was a C version.
What is this about a ruby version of fcgi?

Next, I assumed that fcgi would work in webrick if I
just required webric/fcgi in my httpservlet. Now I see
people adding ‘require fcgi’ to the already existing
‘require cgi’ in their .cgi files. Is this really necessary?
What about the .rhtml files (ie, those run by erb).

Is erb launched for every request, or is this already handled?

···

On Thursday, 27 May 2004 at 20:56:03 +0900, Zev Blut wrote:

Hello,

On Thu, 27 May 2004 20:42:00 +0900, Sascha Ebach se@hexatex.de wrote:

I would like to know a way how I can query if I am actually using the c
fastcgi version.

To make it load the C version change your require statement to:
require ‘fcgi.so’


Jim Freeze
“First things first – but not necessarily in that order”
– Dr. Who, “Doctor Who”

Zev
I tried to run the code you posted in [ruby-talk: 99910] (albeit a simpler hello world
version) and I got an Internal Server Error. I can’t seem to
debug this currently.

···

On Thursday, 27 May 2004 at 22:15:00 +0900, Jim Freeze wrote:

On Thursday, 27 May 2004 at 15:13:50 +0900, Zev Blut wrote:

If your response data is larger than 8K you may want to make sure that
you are running the C version of FastCGI. See [ruby-talk: 99910] for
more information.

Thanks, I’ll take a look at it. However, the response data is only 2k.


Jim Freeze

Certainly. Also, see my next message for a perhaps interesting
discussion I’d like to open.

Ari

···

On Fri, May 28, 2004 at 02:54:45AM +0900, Sascha Ebach wrote:

Hi Ari,

Thanks for clearing that up. I am looking forward for a future release
and more documentation

Hello Jim,

Hello,

>I would like to know a way how I can query if I am actually using the c
>fastcgi version.

To make it load the C version change your require statement to:
require 'fcgi.so'

Whoa whoa whoa. There is just too many fcgi's floating around here. :slight_smile:

I read about fcgi working with webrick, so I thought cool,
I'll try it. So I downloaded it. It didn't have an install,
but the install location looked obvious -- I put it under
webrick/.

Then I noticed that it needed the ruby bindings to fcgi, so
I downloaded Matz' ruby bindings to fcgi and tried to install.
That didn't work because it couldn't find the fcgi.h include
file. So I downloaded the C version of fcgi, built it and
installed it. Now Matz' ruby bindings to fcgi installed
correctly.

So I assumed that the only fcgi core was a C version.
What is this about a ruby version of fcgi?

Next, I assumed that fcgi would work in webrick if I
just required webric/fcgi in my httpservlet. Now I see
people adding 'require fcgi' to the already existing
'require cgi' in their .cgi files. Is this really necessary?
What about the .rhtml files (ie, those run by erb).

Is erb launched for every request, or is this already handled?

I'm not sure about this. But the C version of FCGI belongs to the
client side, not the webrick server. Remember that FCGI's are
independent servers. So in your code you should 'require fcgi' and let
the 'webric/fcgi' to the server. But this is only a guess.

Maybe i find some time to look at it tonight, if nobody else can give
an answer, it's also on my own TODO list, so we can share our
experience.

···

On Thursday, 27 May 2004 at 20:56:03 +0900, Zev Blut wrote:

On Thu, 27 May 2004 20:42:00 +0900, Sascha Ebach <se@hexatex.de> wrote:

--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's

Hello,

Zev
I tried to run the code you posted in [ruby-talk: 99910] (albeit a
simpler hello world
version) and I got an Internal Server Error. I can’t seem to
debug this currently.

I am not sure that this is so important now that Aredridel has identified
your problem. But, there are lots of things that can go wrong. My first
set of questions are if you have fastcgi properly set up.

I am assuming you are running the fcgi package from
http://raa.ruby-lang.org/project/fcgi/ ?
What web server are you running?
If it is Apache do you have mod_fastcgi installed?
Can you run the sample code in the ruby-fcgi package’s README?
What happens when you type require ‘fcgi’ in irb?

These should hopefully be a start to getting fcgi working in your
environment.

Best,
Zev

···

On Thu, 27 May 2004 22:43:03 +0900, Jim Freeze jim@freeze.org wrote: