【问题标题】:Best way to deploy ruby beaneater background processing in production在生产中部署 ruby​​ beeater 后台处理的最佳方法
【发布时间】:2020-10-19 21:20:58
【问题描述】:

我一直在我的 RoR 应用程序中使用 beaneater 进行后台处理。我正在使用 upstart 通过从我的 upstart srcipt 运行 rake 任务在后台运行 beaneater。

exec bundle exec rake RAILS_ENV=production bs:beaneater

我的 rake 任务是

  task beaneater: :environment do
    @beanstalk = BackgroundWorker.get_beanstalkd
    asynch_tasks = BackgroundWorker.descendants
    asynch_tasks.each do |aClass|
      @beanstalk.jobs.register(aClass.tube_name) do |job|
        aClass.process(job)
      end
    end
    @beanstalk.jobs.process!
  end

通过这种方式,我可以运行任意数量的后台进程,但是

  1. 如果需要,我无法自动生成新进程。
  2. rake 任务从暴发户中运行,在埋入任务后默默杀死 一些错误的情况。
  3. 一个可以查看详细信息的管理 UI 会很棒。

关于在生产环境中部署 beaneater 的任何建议。

【问题讨论】:

    标签: ruby-on-rails deployment background-process production beanstalkd


    【解决方案1】:

    由于提到了upstart - 您必须运行某种裸机或虚拟服务器。因此,您的服务器容量有限,几乎没有理由进行自动 扩展。有一些确切数量的进程最适合您的服务器 - 您不能超过该数量,因为会有稳定性和性能问题,没有理由低于。

    至于重启失败的进程——确保你已经配置了respawn

    对于更高级的选项,您可以使用许多现代 linux 中的标准配置 systemd

    /etc/systemd/system/yourservice@.service(注意文件名中的@,用于缩放):

    [Service]
    ExecStart=bundle exec rake bs:beaneater
    Restart=on-failure
    WorkingDirectory=/your/deploy/path
    Environment='RAILS_ENV=production'
    
    [Install]
    WantedBy=multi-user.target
    

    设置为开机启动并运行:

    systemctl daemon-reload
    systemctl enable yourservice@{1..5}.service
    systemctl start yourservice@{1..5}.service
    

    对于资源监控,您可以为所有这些进程创建一个单独的“切片”,并查看systemd-cgtop 中的摘要,其中包含 cpu/memory/network io 等。

    如果您真的需要自动缩放 - 您的路径在于云托管、docker 和 kubernetes 领域,但它要复杂得多(和/或昂贵,取决于提供商)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-21
      • 2023-02-04
      • 1970-01-01
      • 1970-01-01
      • 2016-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多