Pure Ruby FastCGI performance bug?

Hello,

I have noticed that, when using the pure Ruby implementation of
FastCGI, sending a response over 8K causes long delays before the
last chunk of data is sent. The C version does not cause any
delay.

At the end of this message is a sample program to show the issue.

If you run the program a few times, usually after the second time, you
may see that around the last 8K of data takes a long time to be sent.
For example, a response of 100K takes about 30 seconds on my machine
when call the fcgi via localhost.

I am able to reproduce this with various RedHat Linux versions using
mod_fastcgi, Apache 1.3 or 2.0, and Ruby 1.8.1 or 1.6.8.

I thought some of you might want to know about this and if it is
reproducible elsewhere.

Best,
Zev Blut

···

#!/usr/local/bin/ruby1.8
FCGI_PURE_RUBY = true # Comment out if you want to test with c version

require ‘fcgi’

RANDOM_CHAR = ((“A”…“Z”).to_a + (“a”…“z”).to_a + (“0”…“9”).to_a).to_s

SIZE = 1024 * 100

def random_char()
rnd = rand(RANDOM_CHAR.size)
RANDOM_CHAR[rnd…rnd]
end

Generate the data string once, to avoid computation during request.

data = ""
SIZE.times do |i|
data<< random_char
end

FCGI.each do |request|
request.out.print "Content-Type: text/plain\r\n"
request.out.print "Content-Length: #{data.size}\r\n"
request.out.print "\r\n"
request.out.print data
request.finish
end

I have noticed that, when using the pure Ruby implementation of
FastCGI, sending a response over 8K causes long delays before the
last chunk of data is sent. The C version does not cause any
delay.

Hm. I’m seeing this too. I’d had enough network issues this week to
have trouble diagnosing it.

Ari

Hello,

This is a reply to a post I made long ago from
[ruby-talk:99910]

MoonWolf updated the fcgi library to 0.8.5 about a month ago.
It appears that Minero Aoki did some work on the pure Ruby
implementation. So, I have rerun the test code I posted and it
appears that the fixes have removed the performance problem!
Hopefully, it works on other environments too.

Great going!

Cheers,
Zev

MoonWolf updated the fcgi library to 0.8.5 about a month ago.
It appears that Minero Aoki did some work on the pure Ruby
implementation. So, I have rerun the test code I posted and it
appears that the fixes have removed the performance problem!
Hopefully, it works on other environments too.

Great going!

It's defintately an improvement, but I'm still seeing a hang at the
end of scripts, where the webserver hangs for many seconds waiting for
data, then times out. The page gets sent to the browser, but the
connection is never closed, making apps block for a long time. Anyone
seeing this with 0.8.5?