Sidekiq消耗越来越多的内存?

时间:2018-01-25 15:44:57

标签: ruby-on-rails cron sidekiq

所以我有一个rails应用程序,我使用sidekiq 5.0.5和sidekiq-cron 0.4.5。我有3个预定的cron作业,分别每2,3和10分钟运行一次。无论出于何种原因,大约20-30分钟后,由于消耗太多内存,sidekiq被杀死。

如果我打开top并观察记忆,每次作业执行时我都能不断看到它上升2-3%。

有没有人对sidekiq有任何建议或替代方案?这很烦人。我几乎想知道我是否只是在Linux中使用cron作业,只是简单地运行sidekiq来执行一个后台作业,如果它更干净,更快,而不是让sidekiq不断运行并咀嚼更多内存。

我不确定这些是否有必要用于故障排除,但这几乎就是我在应用程序中配置的内容:

# config/sidekiq.yml
development:
  :concurrency: 50
production:
  :concurrency: 50
:queues:
  - default

# config/sidekiq_schedule.yml
job1:
  cron: "*/2 * * * *"
  class: "Refresh1"
  queue: default
  active_job: true

job2:
  cron: "*/2 * * * *"
  class: "Refresh2"
  queue: default
  active_job: true

job3:
  cron: "*/10 * * * *"
  class: "Refresh3"
  queue: default
  active_job: true

# config/initializers/sidekiq.rb
# 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: 52 }

    #Sidekiq scheduler.
    begin
        schedule_file = 'config/sidekiq_schedule.yml'

        if File.exists?(schedule_file) && Sidekiq.server?
                Sidekiq::Cron::Job.load_from_hash! YAML.load_file(schedule_file)
        end
    rescue
        # Schedule file has commented schedules. Keep on moving.
    end

    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

0 个答案:

没有答案