Rails 2.2 cache_classes problem.

Discussion in 'Ruby/Rails' started by Grzegorz Derebecki, Nov 21, 2008.

  1. Grzegorz Derebecki

    Grzegorz Derebecki New Member

    Rails 2.2 is almost done. I'm testing rc release and in railties/lib/initializer they add

    require_dependency

    As far as i remember litespeed lsapi has problem with this. Let me explain:

    When we turn on (in production mode) config.cache_classes = true
    Then rails 2.2 will load all models, helpers, controllers only once at first start. But it generate strange errors like:

    i will show some exemples:
    undefined method `limit' for nil:NilClass
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session/active_record_store.rb:73:in `data_column_size_limit'
    ----------------------------------------------------------------------
    undefined method `zero?' for "1":String
    [RAILS_ROOT]/app/controllers/movies/home_controller.rb:17:in `index'

    movies/home_controller.rb: 17:
    @review = current_movie.random_review unless current_movie.reviews_count.zero?

    >> Movie.first.reviews_count.class
    Fixnum (it is INTEGER in DB then don't know why it is changed to STRING)

    ----------------------------------------------------------------------
    undefined method `all_hashes' for nil:NilClass
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:564:in `select'


    ----------------------------------------------------------------------

    This errors are only if cache_classes = true but without this it is imposible to run rails application fast.

    Rails 2.1 and before didn't used require_dependency to load all classes but some time ago i was traing use it and has simillar isuses (errors in strange places) http://litespeedtech.com/support/forum/showthread.php?t=1712
  2. Grzegorz Derebecki

    Grzegorz Derebecki New Member

    New information

    I make some test to figure who is guilty :)

    I change LSAPI to FASTCGI and my application works now ok with rails 2.2.2 and config.cache_classes = true.

    This meen the problem is with lsapi :(
  3. mistwang

    mistwang LiteSpeed Staff

    We will look into it. Is it possible to send a test application that we can reproduce the problem?
  4. Grzegorz Derebecki

    Grzegorz Derebecki New Member

    sorry but i can't do it (it is big webside http://fdb.pl)

    i know it is hard to find bug i can test your results when you try fix it.
  5. mistwang

    mistwang LiteSpeed Staff

    I don't mean to get your site code. Just wondering if it is possible to quickly create a simple application to reproduced this problem with Rails 2.2.

    At this point, we do really know where to start to trouble shoot this problem.
  6. Grzegorz Derebecki

    Grzegorz Derebecki New Member

    I had solution for described problem.

    1. I use dispatcher.lsapi not RailsRunner.rb.

    When i switched to RailsRunner my webpage starts working ok on lsapi BUT...
    when i restart server there was errors:

    Code:
    Mysql::Error: MySQL server has gone away: SHOW FIELDS FROM `users`
    Problem is witch db connections:

    Code:
    #Close all DB connections established during initialization
    ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
    
    while LSAPI.accept != nil
            Dispatcher.dispatch
    end
    
    When lsapi starts ruby process and forks them first request get error with connection to db (about server gone) so i make litle change in dispatcher:


    Code:
    #Close all DB connections established during initialization
    ActiveRecord::Base.connection.disconnect! and @reconnect = true if defined?(ActiveRecord::Base)
    
    while LSAPI.accept != nil
            if defined?(ActiveRecord::Base) and @reconnect
              ActiveRecord::Base.connection.reconnect!
              @reconnect = false
            end
            Dispatcher.dispatch
    end
    
    it reconnect only at first request ofcorse.
  7. mistwang

    mistwang LiteSpeed Staff

    That's great, we will try the fix, does it work with earlier releases of Rails?
  8. Grzegorz Derebecki

    Grzegorz Derebecki New Member

    i tested it only with 2.2 but it should works ok in all rails version becouse disconnect! and reconnect! are implemented long time and nothing else is used here.
  9. mistwang

    mistwang LiteSpeed Staff

    Tried on 2.1.0, works well.
  10. senihele

    senihele New Member

    I also had this problem, when I upgraded to rails 2.2.2 on my production server - 503 error - a very unpleasant surprise. When I manually ran the site with Mongrel, I had no problems. I changed the Rails context to development everything worked again. Since the site sees very limited testing right now, I can live with this for the moment, but I hope the issue is resolved quickly.
    Last edited: Dec 4, 2008
  11. Grzegorz Derebecki

    Grzegorz Derebecki New Member

    just change dispatcher and all will be ok.

    BTW: in development it works becous cache_classes is false :p
  12. senihele

    senihele New Member

    Yeah - I saw that, that's why I changed to development mode. Thanks for the tip, I would have been lost without it. I'm not sure how to switch dispatchers? Is there any downside to switching?
  13. Grzegorz Derebecki

    Grzegorz Derebecki New Member

    how do you run rails? if you use buildin rails support in lsws just change fcgi-bin/RailsRunner.rb
  14. mistwang

    mistwang LiteSpeed Staff

    Just try patching the fcgi-bin/RailsRunner.rb with the code posted by Grzegorz . It will be included in our next release.
  15. senihele

    senihele New Member

    Perfect - works! Thanks everyone.
  16. brunoaalves

    brunoaalves New Member

    I'm trying to use the v3.3.24 but without sucess with rails 2.2.2 . Although I have the rails 2.2.2 gem installed, in ../lsws/logs/stderr.log I keep getting the following error:

    "Missing the Rails 2.2.2 gem. Please `gem install -v=2.2.2 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed."

    I can run ruby script/console without problems.

    I can run the webrick server (using ruby script/server) without any problems.

    I've the same code running in another machine with v3.3.23 so I though it could be a bug from the v3.3.24.

    any ideas?

    Thanks in advance!
  17. mistwang

    mistwang LiteSpeed Staff

    maybe there are multiple ruby installations. Make sure the correct one has been used, check configuration under "Ruby" tab.
  18. brunoaalves

    brunoaalves New Member

    Hi mistwang,

    I have multiple rails instalations

    Gem rails installed (via gem list)
    rails (2.2.2, 2.1.2, 2.1.1, 2.1.0, 2.0.2, 1.2.3)

    And with the command "whereis ruby" it returns:

    ruby: /usr/bin/ruby /usr/bin/ruby1.8 /usr/lib/ruby /usr/lib64/ruby

    Which configuration of the ruby did you mean? The "Ruby Path" in the Ruby Rails tab?

    it is set to /usr/bin/ruby

    I've tried with /usr/bin/ruby1.8 but without success...
    Last edited: Feb 4, 2009
  19. mistwang

    mistwang LiteSpeed Staff

    I am not sure what is wrong.
    Maybe a permission problem? RailsRunner.rb will not be started by root.
    Also check if Rails require a special environment variable.
  20. brunoaalves

    brunoaalves New Member

    Hi Mistwang,

    The solution I found was freeze the rails gem (rake rails:freeze:gems), so litespeed uses the Rails gem included in the project.

    Thanks for the help!

Share This Page