Isolate-Lockdown extends Isolate sandbox behavior with the goal of generating a monolithic directory to reduce startup time of your application.
Having several gems in Ruby’s
$LOAD_PATH results in slow require. The more bigger your application (with more gems), the longer it will take to start up.
On Rails applications, you can see this performance problem once you deploy a new version of code to your server. When the application restart, it can take several seconds to respond to the first request.
Isolate, RubyGems and Rake (only for extraction)
How to use it
Isolate-lockdown provides a rake task that allow easy execution from command line.
These instructions assume you already followed Isolate instructions for using Isolate in your application.
Since you’re using Isolate, you need to define your dependency on this extension, please add it:
After that, early in your application Rakefile (after
Previous step will make available
isolate:lockdown rake task:
rake isolate:lockdown[folder] # Lockdown isolated gems into folder (defaults 'tmp/lockdown')
Once you execute
isolate:lockdown, it will extract your gems contents into the specified folder, also generating
paths.rb file that will look something like this:
Using the lockdown gems in your application
Now, you need to adapt the startup process of your application to use this generate file.
The following is a simple Rails 3 example:
lockdown = File.expand_path('../../tmp/lockdown/paths.rb', __FILE__) unless File.exist?(lockdown) # using Isolate (development) require 'isolate/now' require 'isolate/lockdown' else # using the lockdown (production) require lockdown end
Avoid executing during development
Please remember that lockdown is aimed to be used or executed during deployment and should not be used during development, as it removes Isolate and itself from the equation.
Not depending on Isolate will render any update to your gem manifest (Isolate) useless. Prior reporting bugs, please remove
tmp/lockdown directory and try again.
Copyright © 2010 Luis Lavena.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.