[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How's the speed?

Leif K-Brooks

12/1/2003 8:32:00 PM

I'm considering doing a large web-based project in Ruby (mod_ruby)
instead of PHP. How would the speed of mod_ruby using the cgi library
compare to the speed of PHP?

5 Answers

Ara.T.Howard

12/1/2003 9:16:00 PM

0

Thomas Fini Hansen

12/1/2003 9:33:00 PM

0

On Tue, Dec 02, 2003 at 05:32:09AM +0900, Leif K-Brooks wrote:
> I'm considering doing a large web-based project in Ruby (mod_ruby)
> instead of PHP. How would the speed of mod_ruby using the cgi library
> compare to the speed of PHP?

Depends on what you want to do.. Here's something I wrote some months
ago:

------

Background: We were re-implementing the search on our portals. The
idea being to present the user with just one text field and then try
to find the best matches, even though it was looking through multiple
xreferenced tables. And then ordering them according to how 'well' it
matches.

The problem: When I made a PHP file that did a pretty good job of
searching through multiple tables and collect the results, it was just
too damn slow. I optimised the hell out of it, rewriting query
functions to join the results with the previous on the fly, using
references as much as I could to avoid the copy penalty, ordering the
search so it would take the longest word first on the assumption that
it would generate the least amount of hits and thus give the rest of
the search less 'possibles' to work with.

Improved it by several factors, but it was still not fast. We talked
about caching the result sets so it was only the initial search that
took time, using the cache when the user was flipping through the
results. Still, 3-5 seconds for a, not unreasonable, search was not
satisfying. We were considering changing the database layout to
accommodate more for searching, adding more code to the administrative
side, or writing the core search function in C.

I was already looking into how to use the C MySQL library and how to
make a PHP module, when I thought I'd try seeing how Ruby fared. We'd
talked about trying Ruby, just to see if it was faster or slower. So I
did a pretty much line by line port to Ruby, not considering possible
optimisations too much, just a decent implementation, that didn't even
print out the results, just collected them. The results (the search
goes from 1142 possible matches to 13 results):

PHP: Total: 13 in 3.762 secs

Ruby: Total: 13 in 0.694 secs

(On a 300Mhz I belive, been a while)

The longest time I've managed with Ruby was a search that returned
over 3000 hits in about 4 secs. PHP timed out on that one, which means
it was over 30 seconds. The only searches where PHP is anywhere near
Ruby is the fast ones that doesn't return many rows. Which is already
below 0.5 second.

------

Actually, implementing the core search function in Ruby allowed me to
make it smarter than I could've in PHP. My feeling is that Ruby is a
tad slower on the startup, but many times faster than PHP in throwing
data around. And that's not just becuase Ruby uses pass-by-reference
per default, as I noted, I tried to make PHP do the same. And the Ruby
code was about 3 pages of readable code while the PHP was 7 pages of
highly uptimized and not particularly readable code..

In the end it ended up with the Ruby code putting the result in a
table in PHP serialized format which a frontend script then pulled
out. Since then Ruby has taken many of the 'workhorse' jobs, while PHP
is mostly for frontends.

--
Thomas
beast@system-tnt.dk

gabriele renzi

12/1/2003 9:53:00 PM

0

il Mon, 01 Dec 2003 20:31:44 GMT, Leif K-Brooks
<eurleif@ecritters.biz> ha scritto::

>I'm considering doing a large web-based project in Ruby (mod_ruby)
>instead of PHP. How would the speed of mod_ruby using the cgi library
>compare to the speed of PHP?

Even consider using FastCGI..
I think people told sometimes php is quite slow, but I'm not sure

Robert Klemme

12/2/2003 8:06:00 AM

0


"Thomas Fini Hansen" <beast@system-tnt.dk> schrieb im Newsbeitrag
news:20031201213101.GC18957@saber.xen.dk...
> On Tue, Dec 02, 2003 at 05:32:09AM +0900, Leif K-Brooks wrote:
> > I'm considering doing a large web-based project in Ruby (mod_ruby)
> > instead of PHP. How would the speed of mod_ruby using the cgi library
> > compare to the speed of PHP?
>
> Depends on what you want to do.. Here's something I wrote some months
> ago:
[snip]

Great story! Should be filed somewhere under "Ruby Success Stories".
Which version of PHP where you using? I think they did a major
improvement in performance between v3 and v4...

Cheers

robert

Thomas Fini Hansen

12/2/2003 6:30:00 PM

0

On Tue, Dec 02, 2003 at 05:07:08PM +0900, Robert Klemme wrote:
>
> "Thomas Fini Hansen" <beast@system-tnt.dk> schrieb im Newsbeitrag
> news:20031201213101.GC18957@saber.xen.dk...
> > On Tue, Dec 02, 2003 at 05:32:09AM +0900, Leif K-Brooks wrote:
> > > I'm considering doing a large web-based project in Ruby (mod_ruby)
> > > instead of PHP. How would the speed of mod_ruby using the cgi library
> > > compare to the speed of PHP?
> >
> > Depends on what you want to do.. Here's something I wrote some months
> > ago:
> [snip]
>
> Great story! Should be filed somewhere under "Ruby Success Stories".
> Which version of PHP where you using? I think they did a major
> improvement in performance between v3 and v4...

Well, it was PHP4. I was genuinely surprised too, I had the 'feeling'
that PHP would be the fastest, as Ruby was nicer to work with. PHP
seems to have a bit of an edge i the 'load and parse file' department,
but with mod_ruby, Ruby is back on top. But the most important part is
that Ruby just seems easier to comprehend. Especially the =& operator
(or was it the &= ?), gave me much grief. Using the wrong one wouldn't
give a parse error or anything, just hard to track errors.

The only 'problem' with Ruby is that it makes me want to make things
even smarter and elegant, rather than just getting the job done.

--
Thomas
beast@system-tnt.dk