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:
···
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?
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
Even consider using FastCGI…
I think people told sometimes php is quite slow, but I’m not sure
···
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?
i use fastcgi and ruby. the speed is insane. if you do not need to get at
the internals of apache i would reccomend fastcgi. you get alot of stuff for
free, like database connection pooling, too.
-a
···
On Mon, 1 Dec 2003, Leif K-Brooks wrote:
Date: Mon, 01 Dec 2003 20:31:44 GMT
From: Leif K-Brooks eurleif@ecritters.biz
Newsgroups: comp.lang.ruby
Subject: How’s the speed?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?
–
ATTN: please update your address books with address below!
===============================================================================
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================
“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
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.
···
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…
–
Thomas
beast@system-tnt.dk