Skip to content

Instantly share code, notes, and snippets.

@rajbacharya
Forked from anonymous/Errors Recieved
Created October 26, 2017 07:18
Show Gist options
  • Select an option

  • Save rajbacharya/03e1b4ffe3fd977b1c6621cb9c576828 to your computer and use it in GitHub Desktop.

Select an option

Save rajbacharya/03e1b4ffe3fd977b1c6621cb9c576828 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jul 14, 2016.
    10 changes: 10 additions & 0 deletions Errors Recieved
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@

    With the size: attribute in your configure_* blocks removed =
    ERROR: heartbeat: ERR max number of clients reached
    app[worker.1]: 3 TID-ormcs1tts ERROR: ERR max number of clients reached


    with the size attribute = " Sidekiq seems to run normally but mailers not moving from in enqueued.



    2 changes: 2 additions & 0 deletions Procfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    web: bundle exec puma -e production -C config/puma.rb
    worker: bundle exec sidekiq -e production -C config/sidekiq.yml
    30 changes: 30 additions & 0 deletions Puma.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@


    workers Integer(ENV['WEB_CONCURRENCY'] || 2)
    threads_count = Integer(ENV['MAX_THREADS'] || 1)
    threads threads_count, threads_count

    preload_app!

    rackup DefaultRackup
    port ENV['PORT'] || 3000
    environment ENV['RACK_ENV'] || 'development'

    # Because we are using preload_app, an instance of our app is created by master process (calling our initializers) and then memory space
    # is forked. So we should close DB connection in the master process to avoid connection leaks.
    # https://github.com/puma/puma/issues/303
    # http://stackoverflow.com/questions/17903689/puma-cluster-configuration-on-heroku
    # http://www.rubydoc.info/gems/puma/2.14.0/Puma%2FDSL%3Abefore_fork
    # Dont have to worry about Sidekiq's connection to Redis because connections are only created when needed. As long as we are not
    # queuing workers when rails is booting, there will be no redis connections to disconnect, so it should be fine.
    before_fork do
    puts "Puma master process about to fork. Closing existing Active record connections."
    ActiveRecord::Base.connection.disconnect!
    end

    on_worker_boot do
    # Worker specific setup for Rails 4.1+
    # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
    ActiveRecord::Base.establish_connection
    end

    28 changes: 28 additions & 0 deletions Sidekiq Initializer
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    if Rails.env.production?

    Sidekiq.configure_client do |config|
    config.redis = { url: ENV['REDIS_URL'], size: 2 }
    end

    Sidekiq.configure_server do |config|
    config.redis = { url: ENV['REDIS_URL'], size: 20 }


    Rails.application.config.after_initialize do
    Rails.logger.info("DB Connection Pool size for Sidekiq Server before disconnect is: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
    ActiveRecord::Base.connection_pool.disconnect!

    ActiveSupport.on_load(:active_record) do
    config = Rails.application.config.database_configuration[Rails.env]
    config['reaping_frequency'] = ENV['DATABASE_REAP_FREQ'] || 10 # seconds
    # config['pool'] = ENV['WORKER_DB_POOL_SIZE'] || Sidekiq.options[:concurrency]
    config['pool'] = 16
    ActiveRecord::Base.establish_connection(config)

    Rails.logger.info("DB Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
    end
    end
    end


    end
    35 changes: 35 additions & 0 deletions production & Application RB
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    Production - Envirorment


    config.action_mailer.default_url_options = { :host => 'domain.herokuapp.com'}
    Rails.application.routes.default_url_options[:host] = 'domain.herokuapp.com'


    ActionMailer::Base.delivery_method = :smtp
    config.action_mailer.perform_deliveries = true
    config.action_mailer.raise_delivery_errors = false
    config.action_mailer.default :charset => "utf-8"
    config.action_mailer.smtp_settings = {
    :port => '587',
    :address => 'smtp.mandrillapp.com',
    ....
    }
    config.action_controller.include_all_helpers = true
    ActionMailer::Base.default :from => "App<[email protected]>"

    config.active_job.queue_name_prefix = "app"
    config.active_job.queue_name_delimiter = "_"






    Application. RB

    config.active_job.queue_adapter = :sidekiq





    9 changes: 9 additions & 0 deletions sidekiq.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    :verbose: true

    development:
    :concurrency: 5
    production:
    :concurrency: 20

    :queues:
    - default