# Rubys web performance

**URL:** <https://rubytalk.org/t/rubys-web-performance/12219>\
**Category:** ruby-talk\
**Created:** [20 June 2004 16:50 UTC](https://rubytalk.org/t/rubys-web-performance/12219 "2004-06-20T16:50:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florian\_Weber1](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Florian\_Weber1](https://rubytalk.org/u/Florian_Weber1)\
**Post date:** [20 June 2004 16:50 UTC](https://rubytalk.org/t/rubys-web-performance/12219/1 "2004-06-20T16:50:01Z")

</div>

hi!

i have to admit that im kinda disappointed by ruby because of its  
poor web performance i've experienced so far.

i have a fairly complex application written in php. it does all kinds  
of complex stuff, front controller, complex template system, interceptors,  
etc. even without any kind of acceleration which does any kind of caching  
for files, classes, etc, the app takes never longer than 0.2 seconds per  
request.

when i have a simple app in rails now, which basically only takes about 100 rows  
from one tables, puts it in objects and displays those in the view, the request  
takes 0.2 seconds with mod\_ruby (all classes cached!) and with cgi  
0.7 seconds.

on both systems (php and ruby) i measured without the invocation overhead.  
on the start of the script i set a variable to the current time and and the end  
i displayed the difference of the current time to the variable.

so basically the overhead created by cgi having to start a new ruby interpreter  
each time is ignored.

i know that rails is not really optimized for performance yet, especially since  
its not even released. however it feels like 0.55 seconds out of the 0.7 are  
spend with the compilation of the ruby classes, before i even execute any..

any ideas why? thanks a lot for feedback!

ciao!  
florian

---

<div class="post-metadata">

**Author:** ![Lothar\_Scholz2](https://avatars.discourse-cdn.com/v4/letter/l/f14d63/32.png) [@Lothar\_Scholz2](https://rubytalk.org/u/Lothar_Scholz2)\
**Post date:** [20 June 2004 17:15 UTC](https://rubytalk.org/t/rubys-web-performance/12219/2 "2004-06-20T17:15:40Z")

</div>

Hello Florian,

> hi!

> i have to admit that im kinda disappointed by ruby because of its  
> poor web performance i've experienced so far.

> i have a fairly complex application written in php. it does all kinds  
> of complex stuff, front controller, complex template system,  
> interceptors,  
> etc. even without any kind of acceleration which does any kind of  
> caching  
> for files, classes, etc, the app takes never longer than 0.2 seconds per  
> request.

> when i have a simple app in rails now, which basically only takes about  
> 100 rows  
> from one tables, puts it in objects and displays those in the view, the  
> request  
> takes 0.2 seconds with mod\_ruby (all classes cached!) and with cgi  
> 0.7 seconds.

> on both systems (php and ruby) i measured without the invocation  
> overhead.  
> on the start of the script i set a variable to the current time and and  
> the end  
> i displayed the difference of the current time to the variable.

> so basically the overhead created by cgi having to start a new ruby  
> interpreter  
> each time is ignored.

> i know that rails is not really optimized for performance yet,  
> especially since  
> its not even released. however it feels like 0.55 seconds out of the  
> 0.7 are  
> spend with the compilation of the ruby classes, before i even execute  
> any..

I don't know rails but if you work with a non cgi architecture, like  
FCGI, webrick, mod\_ruby. Write an init page that requires all files  
(not just the toplevel ones) that will be loaded.

I don't know if it is possible to change the GC behaviour because GC's  
are done much to often in a normal environment, so if this has an  
significant percentage, change the settings in "gc.c" and recompile  
ruby.

> **···**
>
> --  
> Best regards, emailto: scholz at scriptolutions dot com  
> Lothar Scholz [http://www.ruby-ide.com](http://www.ruby-ide.com)  
> CTO Scriptolutions Ruby, PHP, Python IDE 's

---

<div class="post-metadata">

**Author:** ![Laurent\_Julliard4](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Laurent\_Julliard4](https://rubytalk.org/u/Laurent_Julliard4)\
**Post date:** [20 June 2004 23:58 UTC](https://rubytalk.org/t/rubys-web-performance/12219/3 "2004-06-20T23:58:16Z")

</div>

just one thing: How did youm measured time?  
IIRC you should be using Process.times.utime but actually don't  
remember why 😕

> **···**
>
> il Mon, 21 Jun 2004 01:50:01 +0900, Florian Weber \<[csshsh@structbench.com](mailto:csshsh@structbench.com)\> ha scritto::

---

<div class="post-metadata">

**Author:** ![Florian\_Weber1](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Florian\_Weber1](https://rubytalk.org/u/Florian_Weber1)\
**Post date:** [20 June 2004 19:23 UTC](https://rubytalk.org/t/rubys-web-performance/12219/4 "2004-06-20T19:23:00Z")

</div>

> I don't know rails but if you work with a non cgi architecture, like  
> FCGI, webrick, mod\_ruby. Write an init page that requires all files  
> (not just the toplevel ones) that will be loaded.

that means that mod\_ruby and fcgi actually dont cache all the  
loaded classes? i thought exactly thats what it does. when i profile  
my ruby test, the execution via mod\_ruby takes just about as  
long as the execution under cgi minus the time it takes to load  
the classes.

so here it seems like really all the classes are cached..

however im still wondering why my heavy php app, where  
classes are not cached, no accelerator is used, etc is even a bit  
faster than a super simple ruby example where classes are cached..

---

<div class="post-metadata">

**Author:** ![Andreas\_S2](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@Andreas\_S2](https://rubytalk.org/u/Andreas_S2)\
**Post date:** [20 June 2004 21:03 UTC](https://rubytalk.org/t/rubys-web-performance/12219/5 "2004-06-20T21:03:15Z")

</div>

Florian Weber wrote:

> > I don't know rails but if you work with a non cgi architecture, like  
> > FCGI, webrick, mod\_ruby. Write an init page that requires all files  
> > (not just the toplevel ones) that will be loaded.
> 
> that means that mod\_ruby and fcgi actually dont cache all the  
> loaded classes? i thought exactly thats what it does.

You are right.

> however im still wondering why my heavy php app, where  
> classes are not cached, no accelerator is used, etc is even a bit  
> faster than a super simple ruby example where classes are cached..

I don't know rails, but all the ruby web frameworks I looked at were  
extremely memory and CPU intensive. If you use the relational DB like it  
is supposed to, without a generic OO mapping layer, and a simple  
templating system like Kwartz, you will see that performance is similar  
to PHP.

---

<div class="post-metadata">

**Author:** ![Florian\_Weber1](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Florian\_Weber1](https://rubytalk.org/u/Florian_Weber1)\
**Post date:** [20 June 2004 21:29 UTC](https://rubytalk.org/t/rubys-web-performance/12219/6 "2004-06-20T21:29:40Z")

</div>

> I don't know rails, but all the ruby web frameworks I looked at were  
> extremely memory and CPU intensive. If you use the relational DB like it  
> is supposed to, without a generic OO mapping layer, and a simple  
> templating system like Kwartz, you will see that performance is similar  
> to PHP.

well, even when i dont do any orm or database stuff at all its fairly  
slow. in general it feels like the compilation of the classes and modules  
is the bottleneck..

---

<div class="post-metadata">

**Author:** ![Kirk\_Haines](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kirk\_Haines](https://rubytalk.org/u/Kirk_Haines)\
**Post date:** [21 June 2004 16:28 UTC](https://rubytalk.org/t/rubys-web-performance/12219/7 "2004-06-21T16:28:25Z")

</div>

The disadvantage to running something as a CGI is that there is a parsing  
step every time, and a lot of the Ruby libraries are written in Ruby, not C,  
so that is a lot of Ruby lines to parse.

The advantage to something like Kwartz is that it is written in C, so it  
fundamentally pretty fast.

However, if you run some framework that gives you persistence of code, you  
eliminate the code parsing step, and even with heavy apps that are doing a  
lot of database interaction and producing a lot of HTML, performance can be  
pretty good under Ruby.

David is successfully running Basecamp under Rails, so his performance  
benchmarks can't be too bad, and I am running a variety of sites and  
applications under Iowa with very reasonable performance. Server hardware  
and Ruby version are relevant when talking about speed. On an 800 Mhz PIII  
devel box under Linux with Ruby 1.8.1 I range from a high of about .3  
seconds/request for a heavy page with about 30k of HTML with data queried  
from a database and formatted, cookies checked, and some other data  
manipulations down to lows in the thousandths of a second for pages with  
less than about 4k of HTML, with some minor dynamic content but no database  
queries. Note that these are the times for the Ruby code itself to run and  
don't include the overhead for the webserver.

Because of the amount of time that threads spend waiting on other resources,  
even with the heavy .3 seconds/request pages, though, I can handle 15-20 of  
those per second on this hardware while more typical pages end up  
benchmarking around 30-35 per second and the really lightweight ones around  
70/second. For comparison, the requests that deliver 30-35/second via FCGI  
or mod\_ruby, if I instead use CGI, drop to around 6-7/second. These per  
second number are all for the complete transaction with the webserver and  
the applications, not just the Ruby portion.

These performance numbers, for me, are well within the acceptable range, and  
memory usage does not seem to be a problem, either.

Kirk Haines

> **···**
>
> On Mon, 21 Jun 2004 06:03:15 +0900, Andreas Schwarz wrote
> 
> > \> however im still wondering why my heavy php app, where  
> > \> classes are not cached, no accelerator is used, etc is even a bit  
> > \> faster than a super simple ruby example where classes are cached..
> > 
> > I don't know rails, but all the ruby web frameworks I looked at were  
> > extremely memory and CPU intensive. If you use the relational DB  
> > like it is supposed to, without a generic OO mapping layer, and a simple  
> > templating system like Kwartz, you will see that performance is similar  
> > to PHP.

---

<div class="post-metadata">

**Author:** ![Andreas\_S2](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@Andreas\_S2](https://rubytalk.org/u/Andreas_S2)\
**Post date:** [20 June 2004 22:13 UTC](https://rubytalk.org/t/rubys-web-performance/12219/8 "2004-06-20T22:13:15Z")

</div>

Florian Weber wrote:

> in general it feels like the compilation of the classes and modules  
> is the bottleneck..

Of course, but there is a solution: use fastcgi. Try PHP as CGI, it will  
be as slow as a ruby CGI.

---

<div class="post-metadata">

**Author:** ![Andreas\_S2](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@Andreas\_S2](https://rubytalk.org/u/Andreas_S2)\
**Post date:** [21 June 2004 16:53 UTC](https://rubytalk.org/t/rubys-web-performance/12219/9 "2004-06-21T16:53:13Z")

</div>

Kirk Haines wrote:

> > \> however im still wondering why my heavy php app, where  
> > \> classes are not cached, no accelerator is used, etc is even a bit  
> > \> faster than a super simple ruby example where classes are cached..
> > 
> > I don't know rails, but all the ruby web frameworks I looked at were  
> > extremely memory and CPU intensive. If you use the relational DB  
> > like it is supposed to, without a generic OO mapping layer, and a simple  
> > templating system like Kwartz, you will see that performance is similar  
> > to PHP.
> 
> The disadvantage to running something as a CGI is that there is a parsing  
> step every time, and a lot of the Ruby libraries are written in Ruby, not C,  
> so that is a lot of Ruby lines to parse.

I don't think he was talking about parsing speed there; he wrote that  
"classes are cached".

> The advantage to something like Kwartz is that it is written in C, so it  
> fundamentally pretty fast.

No, it generates Ruby code.

> Because of the amount of time that threads spend waiting on other resources,  
> even with the heavy .3 seconds/request pages, though, I can handle 15-20 of  
> those per second on this hardware while more typical pages end up  
> benchmarking around 30-35 per second and the really lightweight ones around  
> 70/second.

Sounds not bad, maybe I should have a look at it.

> **···**
>
> > On Mon, 21 Jun 2004 06:03:15 +0900, Andreas Schwarz wrote

---

<div class="post-metadata">

**Author:** ![Florian\_Weber1](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Florian\_Weber1](https://rubytalk.org/u/Florian_Weber1)\
**Post date:** [20 June 2004 22:28 UTC](https://rubytalk.org/t/rubys-web-performance/12219/10 "2004-06-20T22:28:29Z")

</div>

not really. like i said, i didnt measure the overhead created by the fact  
that cgi has to start up a interpreter each time. i just stop from the start  
of the script to the end. directly within the script..

i just tried something:

#!/usr/local/bin/ruby

start = Time.now  
require 'yaml'  
require 'logger'  
t = Time.now - start

print "Content-type: text/html\r\n\r\n"  
print "%.3f sec.\n" % t.to\_f

this alone takes already at least 0.13 seconds (via cgi)

when i run it just via the shell it takes 0.09 seconds, which i think  
is already quite a lot... no?

ciao!  
florian

> **···**
>
> On Jun 21, 2004, at 0:13 Uhr, Andreas Schwarz wrote:
> 
> > Florian Weber wrote:
> > 
> > > in general it feels like the compilation of the classes and modules  
> > > is the bottleneck..
> > 
> > Of course, but there is a solution: use fastcgi. Try PHP as CGI, it will  
> > be as slow as a ruby CGI.

---

<div class="post-metadata">

**Author:** ![Kirk\_Haines](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kirk\_Haines](https://rubytalk.org/u/Kirk_Haines)\
**Post date:** [21 June 2004 17:05 UTC](https://rubytalk.org/t/rubys-web-performance/12219/11 "2004-06-21T17:05:28Z")

</div>

> I don't think he was talking about parsing speed there; he wrote that  
> "classes are cached".

Maybe I misunderstood. My impression was that he was talking about the  
startup time of a CGI being longer under Ruby than PHP, but that it's a bit  
of an apples and oranges comparison since most of the Ruby libs are written  
in Ruby and a lot of the PHP libs are .so's written in C.

I was just saying that if one eliminates that from the equation using some  
sort of persistence for the Ruby code, then the comparison gets much better.

> \> The advantage to something like Kwartz is that it is written in C, so it  
> \> fundamentally pretty fast.
> 
> No, it generates Ruby code.

Guh, you're right. To many parsing systems in my head. LOL. Thanks. I  
think that I was thinking of Clearsilver.

Thanks,

Kirk Haines

---

<div class="post-metadata">

**Author:** ![Andreas\_S2](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@Andreas\_S2](https://rubytalk.org/u/Andreas_S2)\
**Post date:** [20 June 2004 22:38 UTC](https://rubytalk.org/t/rubys-web-performance/12219/12 "2004-06-20T22:38:15Z")

</div>

Florian Weber wrote:

> > Florian Weber wrote:
> > 
> > > in general it feels like the compilation of the classes and modules  
> > > is the bottleneck..
> > 
> > Of course, but there is a solution: use fastcgi. Try PHP as CGI, it  
> > will  
> > be as slow as a ruby CGI.
> 
> not really. like i said, i didnt measure the overhead created by the  
> fact  
> that cgi has to start up a interpreter each time. i just stop from the  
> start  
> of the script to the end. directly within the script..
> 
> i just tried something:
> 
> #!/usr/local/bin/ruby
> 
> start = Time.now  
> require 'yaml'  
> require 'logger'  
> t = Time.now - start
> 
> print "Content-type: text/html\r\n\r\n"  
> print "%.3f sec.\n" % t.to\_f
> 
> this alone takes already at least 0.13 seconds (via cgi)

Where's the problem? You have to load the files only once, so it doesn't  
matter how long it takes to parse them. CGI is no use for "real"  
applications, use fastcgi, webrick or mod\_ruby.

> **···**
>
> > On Jun 21, 2004, at 0:13 Uhr, Andreas Schwarz wrote:

---

<div class="post-metadata">

**Author:** ![David\_Garamond2](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@David\_Garamond2](https://rubytalk.org/u/David_Garamond2)\
**Post date:** [21 June 2004 07:03 UTC](https://rubytalk.org/t/rubys-web-performance/12219/13 "2004-06-21T07:03:56Z")

</div>

Florian Weber wrote:

> i just tried something:
> 
> #!/usr/local/bin/ruby
> 
> start = Time.now  
> require 'yaml'  
> require 'logger'  
> t = Time.now - start
> 
> print "Content-type: text/html\r\n\r\n"  
> print "%.3f sec.\n" % t.to\_f
> 
> this alone takes already at least 0.13 seconds (via cgi)
> 
> when i run it just via the shell it takes 0.09 seconds, which i think  
> is already quite a lot... no?

try php cgi with several php extensions pre-loaded in php.ini, it can take up to 0.30-0.40 second on my machine (the overhead is mainly in opening \*.so files).

> **···**
>
> --  
> dave

---

<div class="post-metadata">

**Author:** ![Lothar\_Scholz2](https://avatars.discourse-cdn.com/v4/letter/l/f14d63/32.png) [@Lothar\_Scholz2](https://rubytalk.org/u/Lothar_Scholz2)\
**Post date:** [21 June 2004 17:35 UTC](https://rubytalk.org/t/rubys-web-performance/12219/14 "2004-06-21T17:35:24Z")

</div>

Hello Kirk,

> Guh, you're right. To many parsing systems in my head. LOL. Thanks. I  
> think that I was thinking of Clearsilver.

Did you try Clearsilver ?  
If yes, can you recommend it ?

> **···**
>
> > Thanks,
> 
> > Kirk Haines
> 
> --  
> Best regards, emailto: scholz at scriptolutions dot com  
> Lothar Scholz [http://www.ruby-ide.com](http://www.ruby-ide.com)  
> CTO Scriptolutions Ruby, PHP, Python IDE 's

---

<div class="post-metadata">

**Author:** ![Florian\_Weber1](https://avatars.discourse-cdn.com/v4/letter/f/85e7bf/32.png) [@Florian\_Weber1](https://rubytalk.org/u/Florian_Weber1)\
**Post date:** [20 June 2004 22:55 UTC](https://rubytalk.org/t/rubys-web-performance/12219/15 "2004-06-20T22:55:25Z")

</div>

> Where's the problem? You have to load the files only once, so it doesn't  
> matter how long it takes to parse them. CGI is no use for "real"  
> applications, use fastcgi, webrick or mod\_ruby.

well, but i think thats exactly the point why ruby is really hard to use  
for general web stuff..

there are barely any hosters who support fastcgi, webrick or mod\_ruby.  
especially since the last one is not usable for shared hosting. so you  
have to rely on cgi..

and anyways, why does it take ruby so long to load the files and compile  
it when the same would only take a fragment of it with php?

---

<div class="post-metadata">

**Author:** ![Kent\_S2](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kent\_S2](https://rubytalk.org/u/Kent_S2)\
**Post date:** [21 June 2004 18:41 UTC](https://rubytalk.org/t/rubys-web-performance/12219/16 "2004-06-21T18:41:42Z")

</div>

I'm using Clearsilver with ruby-fcgi module to implement a commercial web-site. It's very nice template engine indeed. So far I'm very pleasant with the performance.

Cheers,  
Kent.

> **···**
>
> On Jun 21, 2004, at 1:35 PM, Lothar Scholz wrote:
> 
> > Hello Kirk,
> > 
> > \> Guh, you're right. To many parsing systems in my head. LOL. Thanks. I  
> > \> think that I was thinking of Clearsilver.
> > 
> > Did you try Clearsilver ?  
> > If yes, can you recommend it ?
> > 
> > \> Thanks,
> > 
> > \> Kirk Haines
> > 
> > --  
> > Best regards, emailto: scholz at scriptolutions dot com  
> > Lothar Scholz [http://www.ruby-ide.com](http://www.ruby-ide.com)  
> > CTO Scriptolutions Ruby, PHP, Python IDE 's

---

<div class="post-metadata">

**Author:** ![Aredridel1](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@Aredridel1](https://rubytalk.org/u/Aredridel1)\
**Post date:** [20 June 2004 23:00 UTC](https://rubytalk.org/t/rubys-web-performance/12219/17 "2004-06-20T23:00:58Z")

</div>

> and anyways, why does it take ruby so long to load the files and compile  
> it when the same would only take a fragment of it with php?

In short, PHP is optimized for ease of computer parsing.

Ruby is optimized for human parsing.

---

<div class="post-metadata">

**Author:** ![Andreas\_S2](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@Andreas\_S2](https://rubytalk.org/u/Andreas_S2)\
**Post date:** [20 June 2004 23:18 UTC](https://rubytalk.org/t/rubys-web-performance/12219/18 "2004-06-20T23:18:14Z")

</div>

Florian Weber wrote:

> > Where's the problem? You have to load the files only once, so it  
> > doesn't  
> > matter how long it takes to parse them. CGI is no use for "real"  
> > applications, use fastcgi, webrick or mod\_ruby.
> 
> well, but i think thats exactly the point why ruby is really hard to use  
> for general web stuff..
> 
> there are barely any hosters who support fastcgi, webrick or mod\_ruby.  
> especially since the last one is not usable for shared hosting. so you  
> have to rely on cgi..

I agree, ruby support on shared servers is poor. This is one of the  
reasons why I'm using a virtual server from [www.vdserver.de](http://www.vdserver.de).

> and anyways, why does it take ruby so long to load the files and compile  
> it when the same would only take a fragment of it with php?

Did you really try PHP CGI with source files of comparable size (don't  
forget that every file you require could itself require other files)?

I don't know exactly how the parsing mechanism in PHP and Ruby differs,  
and I don't know if there is actually a difference in performance; but  
I wouldn't be surprised if PHP was faster, because the language is  
\*much\* simpler to parse than Ruby. However, I don't think it's really a  
problem.

---

<div class="post-metadata">

**Author:** ![Laurent\_Julliard4](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Laurent\_Julliard4](https://rubytalk.org/u/Laurent_Julliard4)\
**Post date:** [20 June 2004 23:58 UTC](https://rubytalk.org/t/rubys-web-performance/12219/19 "2004-06-20T23:58:16Z")

</div>

I just thought of this: does rails uses ERB or ERuby ?  
The first one is basically a pure ruby version of the latter, maybe if  
that is the one used you may seicth to the C one and get some better  
performance..

> **···**
>
> il Mon, 21 Jun 2004 07:55:25 +0900, Florian Weber \<csshsh@structbench.com\> ha scritto::
> 
> > and anyways, why does it take ruby so long to load the files and compile  
> > it when the same would only take a fragment of it with php?

---

<div class="post-metadata">

**Author:** ![Patrick\_May1](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@Patrick\_May1](https://rubytalk.org/u/Patrick_May1)\
**Post date:** [21 June 2004 12:13 UTC](https://rubytalk.org/t/rubys-web-performance/12219/20 "2004-06-21T12:13:15Z")

</div>

Florian Weber \<csshsh@structbench.com\> wrote in message news:

> there are barely any hosters who support fastcgi, webrick or mod\_ruby.  
> especially since the last one is not usable for shared hosting. so you  
> have to rely on cgi..

Try Kattare.com, they've told me they do mod\_ruby hosting.

Cheers,

Patrick

[Next page](https://rubytalk.org/t/rubys-web-performance/12219.md?page=2)
