A small note to all the FreeBSD folks about Ruby performance.
While trying to tune Mongrel to run faster on FreeBSD I was stumped as
to
why it was so horribly slow compared to Linux. Linux on the same
machine
was getting about 800 req/sec, and FreeBSD was maybe pushing 23 req/sec.
Pathetic.
I managed to tweak the thread model in Mongrel and get FreeBSD up to
about
210 req/sec but still that wasn’t nearly good enough.
Then I found the secret. FreeBSD has two versions of Ruby in the ports
directory: lang/ruby18 and lang/ruby18-nopthreads.
Using the nopthreads version of Ruby immediately gave me 740 req/sec
without
any changes to Mongrel. I have no idea what Ruby is doing in the
pthreads
version (or why in the hell a thread library based on select also uses
pthreads), but this simple change completely solved all my performance
problems.
So, word to the wise: pthreads do not give you performance.
Using the nopthreads version of Ruby immediately gave me 740 req/sec without
any changes to Mongrel. I have no idea what Ruby is doing in the pthreads
version (or why in the hell a thread library based on select also uses
pthreads), but this simple change completely solved all my performance
problems.
Thank you for sharing this. As an avid FreeBSD user I will check this
in relation to ruby. What FreeBSD version are you talking about?
Then I found the secret. FreeBSD has two versions of Ruby in the ports
directory: lang/ruby18 and lang/ruby18-nopthreads.
Using the nopthreads version of Ruby immediately gave me 740 req/sec without
any changes to Mongrel. I have no idea what Ruby is doing in the pthreads
version (or why in the hell a thread library based on select also uses
pthreads), but this simple change completely solved all my performance
problems.
So, word to the wise: pthreads do not give you performance.
Coincidentally, on the same day as your post Eric H. published
details of the software setup at Robot Co-op:
They run on FreeBSD, and he says: “We use the lang/ruby18-nopthreads
port of Ruby because we experienced an incredible load increase with the
default pthread version.”
Interesting. Did you have to deinstall and rebuild any Ruby-related
ports when you did this, or did everything Just Work?
Zed S. wrote:
A small note to all the FreeBSD folks about Ruby performance.
While trying to tune Mongrel to run faster on FreeBSD I was stumped as
to
why it was so horribly slow compared to Linux. Linux on the same
machine
was getting about 800 req/sec, and FreeBSD was maybe pushing 23 req/sec.
Pathetic.
I managed to tweak the thread model in Mongrel and get FreeBSD up to
about
210 req/sec but still that wasn’t nearly good enough.
Then I found the secret. FreeBSD has two versions of Ruby in the ports
directory: lang/ruby18 and lang/ruby18-nopthreads.
Answered it satisfactorily for myself. Held my nose, stopped apache, ran
make, deinstalled the default build of ruby and installed the nopthreads
version. The performace boost seems to be dramatic. I was considering
migrating from a VPS to a dedicated server and I don’t think I’ll have
to for a while. Thanks. Get this on the wiki if it’s not there already.
Steve K. wrote:
Interesting. Did you have to deinstall and rebuild any Ruby-related
ports when you did this, or did everything Just Work?
Zed S. wrote:
A small note to all the FreeBSD folks about Ruby performance.
While trying to tune Mongrel to run faster on FreeBSD I was stumped as
to
why it was so horribly slow compared to Linux. Linux on the same
machine
was getting about 800 req/sec, and FreeBSD was maybe pushing 23 req/sec.
Pathetic…
Then I found the secret. FreeBSD has two versions of Ruby in the ports
directory: lang/ruby18 and lang/ruby18-nopthreads.