This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
after "deploy:symlink", "deploy:restart_workers" | |
## | |
# Rake helper task. | |
# http://pastie.org/255489 | |
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/ | |
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/ | |
def run_remote_rake(rake_cmd) | |
rake_args = ENV['RAKE_ARGS'].to_s.split(',') | |
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RedisHelper | |
# decode Redis value back to Ruby object | |
def self.decode(json) | |
self.new(ActiveSupport::JSON.decode(json)["#{self.name.downcase}"]) | |
end | |
# encode Ruby object for Redis | |
def encoded | |
self.updated_at = nil | |
self.to_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Индексы – допуск к высокой производительности MySQL, их необходимость и важность увеличивается пропорционально росту объема данных в базе. Индексы необходимо создавать для столбцов, по которым: | |
- происходит поиск в части WHERE | |
- идет соединение таблиц при JOIN | |
- выполняется сортировка и группировка записи при GROUP BY и ORDER BY | |
- осуществляется поиск MIN() и MAX() | |
Индексы бывают составными, в этом случае очень важен порядок столбцов. | |
Разбирая вывод EXPLAIN, стоит обратить внимание на столбцы: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Попробуйте http://nginx.org/en/docs/http/ngx_http_upstream_module.html#least_conn | |
Ну или haproxy с "balance leastconn". | |
Конфиги типа таких | |
на сервере, где стоит nginx, который распределяет запросы | |
upstream myserv_production { | |
ip_hash; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel < ActiveRecord::Base | |
has_attached_file :photo, | |
:styles => { :original => "1024x1024>", :thumb => "150x150>" } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
config.around do |example| | |
# For examples using capybara-webkit for example. | |
# Remove this if you don't use it or anything similar | |
if example.metadata[:js] | |
example.run | |
ActiveRecord::Base.connection.execute("TRUNCATE #{ActiveRecord::Base.connection.tables.join(',')} RESTART IDENTITY") | |
else | |
ActiveRecord::Base.transaction do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
curl -LO http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem | |
curl -LO http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem | |
gem install linecache19-0.5.13.gem | |
gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include=$HOME/.rvm/rubies/ruby-1.9.3-p0-falcon/include/ruby-1.9.1/ruby-1.9.3-p0/ | |
rm linecache19-0.5.13.gem | |
rm ruby-debug-base19-0.11.26.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
rvm_current=`rvm current` | |
echo "Installing ruby-debug with $rvm_current ..." | |
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem | |
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem | |
gem install linecache19-0.5.13.gem ruby-debug-base19-0.11.26.gem ruby-debug19 -- --with-ruby-include=$rvm_path/src/$rvm_current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://blog.carbonfive.com/2011/02/02/crank-your-specs/ | |
https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection | |
https://github.com/tmm1/perftools.rb | |
RUBY_HEAP_MIN_SLOTS=500000 | |
RUBY_HEAP_SLOTS_INCREMENT=500000 | |
RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 | |
RUBY_GC_MALLOC_LIMIT=100000000 | |
RUBY_HEAP_FREE_MIN=500000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz | |
> tar -xzvf ImageMagick.tar.gz | |
> ./configure --prefix=/usr/local --with-x=no --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8 --disable-openmp | |
> make | |
> sudo make install | |
> sudo /sbin/ldconfig /usr/local | |
> sudo ln -f /usr/local/bin/Magick-config /usr/bin/Magick-config | |
> sudo PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ gem install rmagick |