Options for optimizing a large Ruby system

Hi everybody:

I’ve written a large e-commerce system in Ruby, and it works fine but
it’s slow. After poking around the code a bit, I think that the big
bottleneck comes from loading all the required files. The system is
extremely OO – more than 100 separate classes – and there’re a lot
of classes that need to be loaded in with “require” statements before
a single line is executed.

So now I’m looking around for ways to speed things up. Using modruby
is probably an option, but I’m unsure as to whether that’ll do what I
need … I know it keeps the Ruby interpreter in memory, but I really
need something that might keep loaded classes in memory. Does modruby
do that, or is that too much to ask? And failing that, what do people
think would be the next best option for me to pursue?

Thanks in advance,

Francis

sera@fhwang.net (Francis Hwang) writes:

So now I’m looking around for ways to speed things up. Using modruby
is probably an option, but I’m unsure as to whether that’ll do what I
need … I know it keeps the Ruby interpreter in memory, but I really
need something that might keep loaded classes in memory. Does modruby
do that, or is that too much to ask? And failing that, what do people
think would be the next best option for me to pursue?

I have that same problem, and mod_ruby does help. There’s still the
lag the first time the code is loaded, but from then on it runs just
fine.

Breaking the app up slightly helps, but unfortunately I made the
mistake of persisting state using instances of my own classes: this
leads to a problem when running multiple mod_ruby processes and the
one that picks up a session doesn’t have the same set of classes
loaded as the one the previously saved that session: it raises
exceptions during the deserialization.

I’m still working on the start-up overhead, though, so if you come up
with any wonderful ideas please share them

Dave

So now I'm looking around for ways to speed things up. Using modruby
is probably an option, but I'm unsure as to whether that'll do what I

Take a look at fastcgi: http://www.fastcgi.com/
Basically your ruby code stays in memory and talks to your web server
(apache, iis, etc) via a socket. This way you have clean separation
between the web serving process and the ruby cgi process (i.e. no need
for a bloated httpd just to serve up images or static text).

A fastcgi program will generally get its database connections and
other initialization tasks and then just go into a while loop
accepting requests from the server.

We use fastcgi with ruby and are quite happy with it.

Also see this: http://www.dmst.aueb.gr/dds/pubs/conf/2002-SANE-DynCont/html/dyncont.html
fastcgi does very well.

regards,
-joe

sera@fhwang.net (Francis Hwang) wrote in message news:7b561b93.0209041416.73b9be3a@posting.google.com

Hi everybody:

I’ve written a large e-commerce system in Ruby, and it works fine but
it’s slow. After poking around the code a bit, I think that the big
bottleneck comes from loading all the required files. The system is
extremely OO – more than 100 separate classes – and there’re a lot
of classes that need to be loaded in with “require” statements before
a single line is executed.

So now I’m looking around for ways to speed things up. Using modruby
is probably an option, but I’m unsure as to whether that’ll do what I
need … I know it keeps the Ruby interpreter in memory, but I really
need something that might keep loaded classes in memory. Does modruby
do that, or is that too much to ask? And failing that, what do people
think would be the next best option for me to pursue?

Since the interpreter loads a given “require ‘file’” once, I believe a
mod_ruby process will also load the file once.

I’d suggest trying mod_ruby, and be sure to keep “before” and "after"
numbers!

Cheers,

Patrick

If you receive off-line responses, could you please post them to the
group. I need to know how to hadle this situation also. Thank you.

//ed

You could try a web application server. I just released ocelot (I will
be changing the name with the next release to avoid the conflict pointed
out by Peter Gulutzan a few days ago, see ocelot.scarecrowtech.com). It
(and I assume other app servers) work by starting up a Ruby instance and
loading up your project which stays in memory for the life of the server
instance (you will not have to reload your classes on each request). You
can use the proxy module of Apache and a couple of rules to use it as a
front end and let it handle all your static content. It does
essentially what was described in an earlier post for fastcgi (I have
not used fastcgi, just going on what someone else posted). The downside
is you will have to modify your app to use the servlet API instead of
CGI, this is not hard but will be extra work (you do pick up session
management for free though).

If you do not use something like fastcgi or an app server you can also
run your own copy of Ruby with your app and listen for requests on a
port. Then use a CGI stub app to send request to it and return them to
the browser (I used this method for my first prototypes of ocelot and it
works pretty well, but you are going to add overhead with all the extra
connections). This is basically what fastcgi does for you so I guess
all it buys is a finer level of control (fastcgi is probably more
optimized for this job as well). I am pretty sure that this is the
method used by Red Hat’s Interchange server, so there is some precedent
for using it in your situation (you should also be able to get the C
code to their CGI stub app, using a C app for the stub would be a good
idea since it will have to be loaded for each request).

Steven Stanfield

···

On Thu, 5 Sep 2002 07:25:33 +0900 sera@fhwang.net (Francis Hwang) wrote:

Hi everybody:

I’ve written a large e-commerce system in Ruby, and it works fine but
it’s slow. After poking around the code a bit, I think that the big
bottleneck comes from loading all the required files. The system is
extremely OO – more than 100 separate classes – and there’re a lot
of classes that need to be loaded in with “require” statements before
a single line is executed.

So now I’m looking around for ways to speed things up. Using modruby
is probably an option, but I’m unsure as to whether that’ll do what I
need … I know it keeps the Ruby interpreter in memory, but I really
need something that might keep loaded classes in memory. Does modruby
do that, or is that too much to ask? And failing that, what do people
think would be the next best option for me to pursue?

Thanks in advance,

Francis

Is there a reason why autoload just won’t cut it?

– Nikodemus

···

On Thu, 5 Sep 2002, Dave Thomas wrote:

I’m still working on the start-up overhead, though, so if you come up

Joseph McDonald joe@vpop.net wrote in message news:155365737642.20020904165944@vpop.net

So now I’m looking around for ways to speed things up. Using modruby
is probably an option, but I’m unsure as to whether that’ll do what I

Take a look at fastcgi: http://www.fastcgi.com/

Do you have a mirror of the ruby fast cgi bindings? Eli Green’s site
has been down for some time…

thanks,

Patrick

Nikodemus Siivola tsiivola@cc.hut.fi writes:

I’m still working on the start-up overhead, though, so if you come up

Is there a reason why autoload just won’t cut it?

That is a very good idea… It never occurred to be that autoload would
work with Marshal.load, but of course it does.

Many thanks

Dave

When we are dealing with a “large” Ruby system, with a lot of live
objects, doesn’t the Ruby standard mark-and-sweep GC create a potential
overhead problem?

Regards,

Bill

i’ve got a copy at http://liber.sf.net/fastcgi.rb
but i’m not sure if it’s the most recent version.

···

On Thu, Sep 05, 2002 at 10:27:34PM +0900, Patrick May wrote:

Joseph McDonald joe@vpop.net wrote in message news:155365737642.20020904165944@vpop.net

Take a look at fastcgi: http://www.fastcgi.com/

Do you have a mirror of the ruby fast cgi bindings? Eli Green’s site
has been down for some time…


Brandt

Does anyone know how much FastCGI actually boosts performance?

I’m working on an Apache-based application, and started out using
FastCGI. But I switched to mod_ruby because:

  • my code becomes simpler
  • installation and configuration are easier
  • my application needs to control the HTTP response codes; and
  • developers are starting to switch to Apache 2.0; mod_ruby is
    available for Apache 2.0 now, but FastCGI isn’t

Nonetheless, I’d be interested in learning more about the performance
difference.

···

On Thu, Sep 05, 2002 at 10:27:34PM +0900, Patrick May wrote:

Joseph McDonald joe@vpop.net wrote in message news:155365737642.20020904165944@vpop.net

So now I’m looking around for ways to speed things up. Using modruby
is probably an option, but I’m unsure as to whether that’ll do what I

Take a look at fastcgi: http://www.fastcgi.com/


Matt Gushee
Englewood, Colorado, USA
mgushee@havenrock.com
http://www.havenrock.com/

Matt Gushee mgushee@havenrock.com wrote in message news:20020905143015.GA4536@swordfish

But I switched to mod_ruby because:

  • my code becomes simpler

I am looking into integrating FastCGI support with the Narf web
libraries. When I do, one will be able to use the same API for cgi
scripts, mod_ruby, and fastcgi. I.E. from the perspective of one
using Narf using fastcgi will be as simple (the same) as writing a
cgi-script.

This integration is currently vaporware, but is on my to do list.

~ Patrick May

Brandt Kurowski brandt@kurowski.net wrote in message news:20020905141354.GH1517@highway.kurowski.net

i’ve got a copy at http://liber.sf.net/fastcgi.rb
but i’m not sure if it’s the most recent version.

Thanks! When I integrate fastcgi into narf, I will throw this into
our project base so that we have a place to accept patches, etc.

~ Patrick

Interesting. What’s Narf?

···

On Fri, Sep 06, 2002 at 09:49:32AM +0900, Patrick May wrote:

Matt Gushee mgushee@havenrock.com wrote in message news:20020905143015.GA4536@swordfish

But I switched to mod_ruby because:

  • my code becomes simpler

I am looking into integrating FastCGI support with the Narf web
libraries. When I do, one will be able to use the same API for cgi
scripts, mod_ruby, and fastcgi. I.E. from the perspective of one
using Narf using fastcgi will be as simple (the same) as writing a
cgi-script.


Matt Gushee
Englewood, Colorado, USA
mgushee@havenrock.com
http://www.havenrock.com/

Matt Gushee mgushee@havenrock.com wrote in message news:20020906005316.GH4604@swordfish

Matt Gushee mgushee@havenrock.com wrote in message news:20020905143015.GA4536@swordfish

But I switched to mod_ruby because:

  • my code becomes simpler

I am looking into integrating FastCGI support with the Narf web
libraries. When I do, one will be able to use the same API for cgi
scripts, mod_ruby, and fastcgi. I.E. from the perspective of one
using Narf using fastcgi will be as simple (the same) as writing a
cgi-script.

Interesting. What’s Narf?

http://narf-lib.sourceforge.net

Narf is an alternative CGI api that builds off of Wakou Aoyama’s
standard cgi.rb. There were a number of changes we wanted to see in
the CGI api, but it didn’t seem to make sense to try and push all
those changes onto the standard api. So we created an experimental
fork of CGI.

Narf is alpha right now. There is code, it does work, but there are
still bugs and we are doing alot of refactoring as we flesh out the
organization of the code. For example, recently we renamed the
modules to Web instead of CGI, so that they can co-exist more
peacefully alongside Wakou’s code.

There should be another alpha release soon; we am sorting out some
build dependencies, and when that is done will be another release.

~ Patrick (and perhaps by proxy, Tom Clarke)

···

On Fri, Sep 06, 2002 at 09:49:32AM +0900, Patrick May wrote: