[英]Correct way to monitor ruby background processes (like Resque) in production
[英]Best way to deploy ruby beaneater background processing in production
我一直在我的 RoR 應用程序中使用 beaneater 進行后台處理。 我正在使用 upstart 通過從我的 upstart srcipt 運行 rake 任務在后台運行 beaneater。
exec bundle exec rake RAILS_ENV=production bs:beaneater
我的耙子任務是
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
通過這種方式,我可以運行任意數量的后台進程,但是
關於在生產環境中部署 beeater 的任何建議。
由於提到了upstart
——您必須運行某種裸機或虛擬服務器。 因此,您的服務器容量有限,幾乎沒有理由進行自動擴展。 有一些最適合您的服務器的進程的確切數量 - 您不能高於 go,因為會有穩定性和性能問題,並且沒有理由低於 go。
至於重新啟動失敗的進程 - 確保您已配置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 土地,但它要復雜得多(和/或昂貴,取決於提供商)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.