These forums are read-only!
MySQL Ruby Gem (SOLVED) -- Now a Ruby performance problem...
  • So I am a PHP guru, but Ruby and Rails is pretty new to me and I'm trying to get Redmine setup on a 256 slice.

    I've got it setup on Fedora 9 with Apache 2, Passenger, and all the necessary Ruby gems, except I noticed that in Redmine's database.yml file that it said:

    # Get the fast C bindings:
    # gem install mysql
    # (on OS X: gem install mysql -- --include=/usr/local/lib)
    # And be sure to use new-style password hashing:
    # http://dev.mysql.com/doc/refman/5.0/en/old-client.html


    So I tried to install the mysql Ruby gem with "sudo gem install mysql" only to be greeted with the following error:

    Building native extensions. This could take a while...
    ERROR: Error installing mysql:
    ERROR: Failed to build gem native extension.

    /usr/bin/ruby extconf.rb install mysql
    checking for mysql_query() in -lmysqlclient... no
    checking for main() in -lm... yes
    checking for mysql_query() in -lmysqlclient... no
    checking for main() in -lz... yes
    checking for mysql_query() in -lmysqlclient... no
    checking for main() in -lsocket... no
    checking for mysql_query() in -lmysqlclient... no
    checking for main() in -lnsl... yes
    checking for mysql_query() in -lmysqlclient... no
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers. Check the mkmf.log file for more
    details. You may need configuration options.

    Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/bin/ruby
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib


    Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
    Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out


    The mkmf.log file contains:

    find_library: checking for mysql_query() in -lmysqlclient... ---------------

    "gcc -o conftest -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -I/usr/local/inc
    conftest.c: In function âtâ:
    conftest.c:3: error: âmysql_queryâ undeclared (first use in this function)
    conftest.c:3: error: (Each undeclared identifier is reported only once
    conftest.c:3: error: for each function it appears in.)
    checked program was:
    /* begin */
    1: /*top*/
    2: int main() { return 0; }
    3: int t() { void ((*volatile p)()); p = (void ((*)()))mysql_query; return 0
    /* end */
    ...more of the same for other mysql_* functions...


    Any idea what's going wrong here? It looks like it can find the MySQL libraries ok but it just doesn't have those functions defined... which would be very strange. I have all the mysql, mysql-devel, mysql-libs, etc. packages installed.

    On a slightly related note, is the lack of the native MySQL Ruby gem what is causing slow performance with Redmine? Is there anything else a Ruby-newbie should keep in mind for making Rails apps speedy on a 256 slice? Thanks for all your help!

    EDIT: It appears the sluggishness may be swap-related, as with Redmine running the server runs about 30 MB into swap very quickly. Any optimizations I can make to get it out of swap space?
  • when you go to install the mysql gem by this command
    gem install mysql -- --with-mysql-config=/path/to/mysql_config
    note the double "--".

    Also since you are using passenger with apache. Did you install the Ruby Enterprise Edition? that will lower your memory usage a bit and hopefully prevent your server going into a swap.
    http://www.rubyenterpriseedition.com/
  • Thanks, the MySQL gem compiled perfectly. Also, thanks for the Ruby Enterprise tip, that reduced memory usage quite a bit, and it's hovering about 100 MB under swap now.

    However, performance still leaves a lot to be desired. It's *slightly* faster, but still very, very sluggish. Is this typical of Rails apps in general or is there anything I can do to speed it up? Thanks.
  • What is your passenger settings? If its a slow traffic site and you are the only one hitting it then Passanger might be killing off all the ruby processes and when you access it again it has to start some processes back up.
  • The only setting I've changed from the default is the PassengerMaxPoolSize, which I changed to 2 based on the recommendations in the Passenger user guide.

    If I understand the docs correctly, PassengerPoolIdleTime controls how long those 2 processes sit idle without a request before they're shutdown. I understand why it would be a little sluggish on the first access as the Ruby Enterprise process is loaded and all that, but the default value for PassengerPoolIdleTime is 300 seconds, and I'm definitely accessing more pages within 300 seconds and it's still sluggish.

    Thanks again for your help Schultz.

    EDIT: Did a bit more research. I think it's an issue with Ruby, not Passenger. As I loaded each page I watched the top output, and it's sitting in the ruby process for about 8 seconds processing each page. There's virtually no i/o wait, so Ruby's not waiting on anything from disk, and those SQL queries shouldn't take more than a few milliseconds. Then again, it could be an issue with Passenger, as I really don't know much about Passenger's internals and how it does its thing.
  • Posted By: MagicBobertThanks, the MySQL gem compiled perfectly. Also, thanks for the Ruby Enterprise tip, that reduced memory usage quite a bit, and it's hovering about 100 MB under swap now.

    However, performance still leaves a lot to be desired. It's *slightly* faster, but still very, very sluggish. Is this typical of Rails apps in general or is there anything I can do to speed it up? Thanks.


    Most Rails apps the bottlenecks are a result of the applications code, not the database in my experience.
  • Look in your log files and see if anything is taking a large amount of time, like queries and such. The only other thing i could think of is swapping issues. What is the output of free -m ? . the other thing you could try is run a mongrel or thin instance and see if hitting it directly is faster then through passanger.