From 22a4580df545a0bd4cf1d055848b0566a447e0c9 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 10 Mar 2013 17:21:56 -0700 Subject: [PATCH] added profile environment for perftools profiling (1.9.3 only) --- Gemfile | 5 ++++ Gemfile.lock | 7 +++++ app/models/topic.rb | 1 + config/application.rb | 2 +- config/database.yml.sample | 10 +++++++ config/environments/profile.rb | 45 +++++++++++++++++++++++++++++ config/initializers/secret_token.rb | 2 +- config/redis.yml.sample | 3 ++ 8 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 config/environments/profile.rb diff --git a/Gemfile b/Gemfile index b1f58366cdd..cb6cc93925c 100644 --- a/Gemfile +++ b/Gemfile @@ -108,3 +108,8 @@ end # If you want to amend mini profiler to do the monkey patches in the railstie # we are open to it. gem 'rack-mini-profiler', git: 'git://github.com/SamSaffron/MiniProfiler' + +# perftools only works on 1.9 atm +group :profile do + gem 'rack-perftools_profiler', require: 'rack/perftools_profiler', platform: :mri_19 +end diff --git a/Gemfile.lock b/Gemfile.lock index 977aba11156..a4346915847 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -307,9 +307,11 @@ GEM omniauth-twitter (0.0.14) multi_json (~> 1.3) omniauth-oauth (~> 1.0) + open4 (1.3.0) openid-redis-store (0.0.2) redis ruby-openid + perftools.rb (2.0.0) pg (0.14.1) polyglot (0.3.3) progress (2.4.0) @@ -325,6 +327,10 @@ GEM rack-openid (1.3.1) rack (>= 1.1.0) ruby-openid (>= 2.1.8) + rack-perftools_profiler (0.6.0) + open4 (~> 1.0) + perftools.rb (~> 2.0.0) + rack (~> 1.0) rack-protection (1.3.2) rack rack-ssl (1.3.3) @@ -514,6 +520,7 @@ DEPENDENCIES pg pry-rails rack-mini-profiler! + rack-perftools_profiler rails rails_multisite! rake diff --git a/app/models/topic.rb b/app/models/topic.rb index 4f90de77ac0..d7b012c0b6f 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -123,6 +123,7 @@ class Topic < ActiveRecord::Base return title unless SiteSetting.title_fancy_entities? # We don't always have to require this, if fancy is disabled + # see: http://meta.discourse.org/t/pattern-for-defer-loading-gems-and-profiling-with-perftools-rb/4629 require 'redcarpet' unless defined? Redcarpet Redcarpet::Render::SmartyPants.render(title) diff --git a/config/application.rb b/config/application.rb index b243c3a779c..d2d3e08213e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,7 +7,7 @@ require './lib/discourse_plugin_registry' if defined?(Bundler) # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(:assets => %w(development test))) + Bundler.require(*Rails.groups(:assets => %w(development test profile))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end diff --git a/config/database.yml.sample b/config/database.yml.sample index 9a73a9b02ea..8cc07833983 100644 --- a/config/database.yml.sample +++ b/config/database.yml.sample @@ -30,3 +30,13 @@ production: timeout: 5000 host_names: - production.localhost # Update this to be the domain of your production site + +profile: + adapter: postgresql + database: discourse_development + min_messages: warning + host: localhost + pool: 5 + timeout: 5000 + host_names: + - "localhost" diff --git a/config/environments/profile.rb b/config/environments/profile.rb new file mode 100644 index 00000000000..17cd7064cc0 --- /dev/null +++ b/config/environments/profile.rb @@ -0,0 +1,45 @@ +Discourse::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # Code is not reloaded between requests + config.cache_classes = true + + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # in profile mode we serve static assets + config.serve_static_assets = true + + # Compress JavaScripts and CSS + config.assets.compress = true + + # stuff should be pre-compiled, allow compilation to make life easier + config.assets.compile = true + + # Generate digests for assets URLs + config.assets.digest = true + + # Specifies the header that your server uses for sending files + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + + config.action_mailer.delivery_method = :sendmail + config.action_mailer.sendmail_settings = {arguments: '-i'} + + # Send deprecation notices to registered listeners + config.active_support.deprecation = :notify + + # I dunno ... perhaps the built-in minifier is using closure + # regardless it is blowing up + config.ember.variant = :development + config.ember.ember_location = "#{Rails.root}/app/assets/javascripts/external_production/ember.js" + config.ember.handlebars_location = "#{Rails.root}/app/assets/javascripts/external/handlebars-1.0.rc.3.js" + config.handlebars.precompile = true + + config.middleware.use ::Rack::PerftoolsProfiler, :default_printer => 'gif' + +end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 00934ec07d0..ce5e46e1115 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -10,7 +10,7 @@ # Discourse::Application.config.secret_token = "SET_SECRET_HERE" # delete all lines below in production -if Rails.env.test? || Rails.env.development? +if Rails.env.test? || Rails.env.development? || Rails.env == "profile" Discourse::Application.config.secret_token = "47f5390004bf6d25bb97083fb98e7cc133ab450ba814dd19638a78282b4ca291" else raise "You must set a secret token in ENV['SECRET_TOKEN'] or in config/initializers/secret_token.rb" if ENV['SECRET_TOKEN'].blank? diff --git a/config/redis.yml.sample b/config/redis.yml.sample index 68d138b5ff6..c3ee44b2726 100644 --- a/config/redis.yml.sample +++ b/config/redis.yml.sample @@ -7,6 +7,9 @@ defaults: &defaults development: <<: *defaults +profile: + <<: *defaults + test: <<: *defaults db: 1