简体   繁体   中英

Best way to deploy ruby beaneater background processing in production

I have been using beaneater for background processing in my RoR application. I am using upstart to run beaneater in the background by running a rake task from my upstart srcipt.

exec bundle exec rake RAILS_ENV=production bs:beaneater

And my rake task is

  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

With this way I am able to run as many background processes as I want but

  1. I am unable to automatically spawn new processes, if needed.
  2. The rake task ran from upstart kills silently after burying the task in case of some error.
  3. An admin UI to see details would be a great.

Any recommendation on way to deploy beaneater on production.

Since upstart is mentioned - you must be running some kind of bare metal or virtual server. Thus you're have a limited server capacity and there's little reason to have automatic scaling. There's some exact number of processes that is optimal for your server - you cannot go above that because there'll be stability and performance issues and no reason to go below.

As for restarting failed processes - make sure you've configured respawn

For more advanced options you can use systemd that comes as standard in many modern linuxes.

/etc/systemd/system/yourservice@.service (note the @ in filename, that's for scaling):

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

[Install]
WantedBy=multi-user.target

Set to start at boot and run:

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

For resource monitoring you can make a separate "slice" with all these processes and see summary in systemd-cgtop with cpu/memory/network io etc.

If you really need autoscaling - your path lies into cloud hosting, docker and kubernetes land, but it is much more complicated (and/or expensive, depending on provider).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM