LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > External Applications > Ruby/Rails > A cautionary tale: Cache.reset to reset memcache at the end of your environment

Reply
 
Thread Tools Display Modes
  #1  
Old 03-13-2007, 10:42 AM
fantasydreaming fantasydreaming is offline
Senior Member
 
Join Date: Sep 2006
Posts: 76
Smile A cautionary tale: Cache.reset to reset memcache at the end of your environment

Litespeed attempts to make starting up very fast, and it does so by loading junk in a parent process, then doing the fork. That way, all that disk-scouring to find all the rails files, which takes about 6 seconds of heavy iowait, is only done once.

However it also means any connections you initialize will also be shared among child processes.

Database connections - the lsapi parent process explicitly disconnects after loading, so they'll be re-initialized for each child.

Memcache connections you need to do yourself. I do so at the bottom of my environment.rb (I'm using memcache-client, which sets a global CACHE):
CACHE.reset


Furthermore, if you want to speed things up even more you can load your controller files in the environment, rather than on demand. That way, they'll be pre-loaded for your child processes, and you'll have significantly more shared memory:

if RAILS_ENV=='production'
require_dependency 'application'
Dir.foreach( "#{RAILS_ROOT}/app/models" ) {|f| $logger.d "r #{f}"; silence_warnings{require_dependency f} if f =~ /\.rb$/}
Dir.foreach( "#{RAILS_ROOT}/app/controllers" ) {|f| $logger.d "r #{f}"; silence_warnings{require_dependency f} if f =~ /\.rb$/}
end

If you're using engines (I am), you'll want to throw in your engine directories in there too.

Thanks again to litespeed people for a great project, and for making a free version available. I hope we all consider purchasing a license at some point
Reply With Quote
  #2  
Old 03-13-2007, 12:14 PM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,590
Thanks for the write up.

If you don't mind, I will post it on our Wiki.
Reply With Quote
  #3  
Old 03-26-2007, 12:04 PM
fantasydreaming fantasydreaming is offline
Senior Member
 
Join Date: Sep 2006
Posts: 76
Just a quick reply to this to say that this hasn't totally solved my problems with this So I'll keep ya posted if I figure it out. Something wierd is going on...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 03:03 PM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.