Rails 2.2 cache_classes problem.

#1
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
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 :(
 

mistwang

LiteSpeed Staff
#5
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
At this point, we do really know where to start to trouble shoot this problem.
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.
 
#8
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.
 
#10
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:
#12
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?
 
#16
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!
 
#18
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:

mistwang

LiteSpeed Staff
#19
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
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!
 
Top