TransWikia.com

Best way to deploy ruby beaneater background processing in production

Stack Overflow Asked by chetang on February 3, 2021

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.

One Answer

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/[email protected] (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).

Answered by Vasfed on February 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP