View Full Version : Rails 2.2 cache_classes problem.
Grzegorz Derebecki
11-21-2008, 05:52 AM
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
Grzegorz Derebecki
11-21-2008, 09:40 AM
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
11-22-2008, 07:02 PM
We will look into it. Is it possible to send a test application that we can reproduce the problem?
Grzegorz Derebecki
11-23-2008, 12:32 AM
We will look into it. Is it possible to send a test application that we can reproduce the problem?
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.
mistwang
11-24-2008, 02:04 PM
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.
Grzegorz Derebecki
11-30-2008, 03:59 PM
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:
Mysql::Error: MySQL server has gone away: SHOW FIELDS FROM `users`
Problem is witch db connections:
#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:
#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.
mistwang
11-30-2008, 05:12 PM
That's great, we will try the fix, does it work with earlier releases of Rails?
Grzegorz Derebecki
11-30-2008, 05:24 PM
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.
mistwang
11-30-2008, 06:21 PM
Tried on 2.1.0, works well.
senihele
12-04-2008, 03:53 PM
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.
Grzegorz Derebecki
12-04-2008, 03:57 PM
just change dispatcher and all will be ok.
BTW: in development it works becous cache_classes is false :P
senihele
12-04-2008, 04:22 PM
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?
Grzegorz Derebecki
12-04-2008, 05:46 PM
how do you run rails? if you use buildin rails support in lsws just change fcgi-bin/RailsRunner.rb
mistwang
12-04-2008, 06:38 PM
Just try patching the fcgi-bin/RailsRunner.rb with the code posted by Grzegorz . It will be included in our next release.
senihele
12-04-2008, 07:01 PM
Perfect - works! Thanks everyone.
brunoaalves
02-04-2009, 09:36 AM
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!
mistwang
02-04-2009, 10:01 AM
maybe there are multiple ruby installations. Make sure the correct one has been used, check configuration under "Ruby" tab.
brunoaalves
02-04-2009, 11:41 AM
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...
mistwang
02-06-2009, 10:44 AM
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.
brunoaalves
02-17-2009, 11:46 AM
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!