We are running Ruby 2.0 in production

(Sam Saffron) #1

Just wanted to let you all know that thanks to @supermathie we are now running Ruby 2.0 with LD_PRELOAD flags

As documented here:

In production


Sam, Why is better than 1.9.3-pX? Performance?

(William Herry) #4

great job, one little question, about when will discourse feature froze

(Sam Saffron) #5

mostly perf, we can’t take advantage of 2.0 specific features cause we will also target 1.9.3 for a while

(Neil Lalonde) #6

This topic might answer your questIon:

(Robin Ward) #7

I tried to reproduce it the other day but couldn’t. Gonna try again now!

(William Herry) #8

thanks, I should search that first

(Karan Misra) #9

This is great! Ruby 2.0 is the way forward anyway

(Sam Saffron) #10

I moved 3 posts to a new topic: Having issues getting started with Discourse on Ruby 2.0

(paul) #11

@sam, I’m trying to found out more about what the ruby-2.0.0-turbo actually does. According to rvm docs, adding a -named ruby won’t actually do anything different until you define what that name does. That means the instructions for building Ruby on the wiki [1] and [2] won’t actually be any different from a normal ruby-2.0.0 install.

Are there some instructions somewhere else that I’m missing, or is this just an oversight in this page? Are the scripts you guys use to build the original base box (discourse-0.8.4) for vagrant open-sourced anywhere, or are the instructions on that wiki [2] pretty much it? If thats the case, then that ruby is probably missing the tcmalloc and whatever other optimizations are included by -turbo.

1: discourse/DEVELOPMENT-OSX-NATIVE.md at master · discourse/discourse · GitHub
2: discourse/DEVELOPER-ADVANCED.md at master · discourse/discourse · GitHub

(Michael Scott Shappe) #12

As I understand it, RVM defines the -turbo extension already. It throws ‘-O3’ at the compiler.

(paul) #13

I checked the rvm source, and there’s no mention of turbo anything. I also asked in #rvm, and rvm does nothing special for the “turbo” named ruby. It just “remembers” a set of patches for you that can then be applied to other versions of ruby, but you have to set them up yourself. There’s no built-in “turbo” patchset.

(Sam Saffron) #14

You know what … I think you are right, I am going to get that sorted … and do some extra benching.

I misread a lot of http://alisnic.net/blog/making-your-ruby-fly/ , the CFLAGS need to be set in env

(Michael Scott Shappe) #15

Oops! And here, I just took y’all at your word! :smile:

(Sam Saffron) #16

I re-ran some benches locally and here are my initial findings on my x64 machine

  • llvm clang 3.0 -O3 is slower than gcc 4.72 -O3 (5%)
  • gcc 4.8 and gcc 4.72 are pretty much the same
  • FLAGS="-O3 -march=native" rvm install 2.0.0 is up to 5% faster for front page perf.

(paul) #17

In my research, it saw it indicated that Ruby 2.0 is compiled with -O3 by default. I’m not an expert on it, but I do see -O3 being set several places in the Ruby 2.0.0 source:


390:    : ${optflags=-O3}

5005:    : ${optflags=-O3}

So I’m not surprised that setting it explicitly would make much difference. I’m curious, though, if there’s a way to compile Ruby with the tcmalloc already build in, rather than needing to rely on the LD_PRELOAD env flag. I think that would be worthy of a -turbo named Ruby.

(Sam Saffron) #18

yeah I follow, but there is no -march=native in rvm afaik.

(Sam Saffron) #19

I am pretty sure there is a way of doing this and the tcmalloc site actually recommends it.

(paul) #20

Looks like its just an addition to LDFLAGS:

(Sam Saffron) #21

This seems to do the trick for me:

sudo ln -s /usr/lib/libtcmalloc_minimal.so.4.1.0 /usr/lib/libtcmalloc_minimal.so
CFLAGS="-O3 -march=native" MAINLIBS="-ltcmalloc_minimal" rvm install 2.0.0-turbo

But I can seem to get stable benches on my VM that prove it is unequivocally faster or slower. Care to run some benches?