I've got some experience in deploying on Heroku, and I know how to use a Procfile to declare processes.
I generally use either Thin or Unicorn for the web part (http requests handling), and then manage my background tasks using Delayed Job.
Now I'm about to take a Rails 3.2.8 (Ruby 1.9.3) Application running on Heroku and bring it to a "normal" server, where it will run on PhusionPassenger.
I'm not sure about the way Passenger spawns child processes, and how it handles background queues. I need to be sure that web queues don't get filled with time consuming tasks: the ones I used to run in the background on Heroku.
Is there a way to manage Passenger's queues?
Passenger doesn't handle background queues - typically you'd do exactly as you were doing on heroku and offload those tasks onto delayed job, sidekiq, resque etc.
The only difference would be how you manage those processes. You could keep using a procfile and run them via the foreman gem or you could use something like god or bluepill
Related
Has any one used Capistrano 3.0.0 ?
I'm new to rails and web development in general, and I've never used Capistrano before, and I need to deploy my app on Heroku with Capistrano in order to user sidekiq and redis-server.
Should I use an older version of Capistrano, where I could find more resource to help get started, or is this considered a bad thing ?
Any suggestions or tips would be very much appreciated.
Capistrano and Heroku are not compatible technology.
Heroku provides a git source control remote server. When you want to deploy code onto your Heroku app, you use git to push a copy of the code. This triggers a Heroku deployment through their process.
Capistrano is an SSH based system deployment framework. It allows you to connect via SSH to each server in your environment and issue commands with a large library of built-in functionality. Heroku does not allow SSH access to configure systems.
Do you have deploys/configuration working on Heroku at all? If not, you should start there with the basic Heroku Rails setup documents.
If you do have your web app running, but need Redis and Sidekiq, you will need to:
Provision a Redis database provider, like OpenRedis via a Heroku Addon: http://addons.heroku.com/
Setup Sidekiq in your Rails application (See Sidekiq docs: https://github.com/mperham/sidekiq)
Add a Sidekiq worker process in your Heroku Procfile within your app
Your app will then have a number of web processes from the Procfile running your Rails app front-end and a number of back-end asynchronous workers running Sidekiq.
I have a Rails app hosted on Heroku and I want to add Server Sent Events functionalities, but I can't find any documentation or blog post specific for Heroku.
As not all servers (e.g. WEBrick) support ActionController::Live I was wondering what is the default server on Heroku and whether is possible to configure the environment (i.e. change server) to support SSEs.
Any further advice about the server to use and how to configure would be greatly appreciated.
I think my answer is not so widely helpfull, but you can try.
For the first thing:
create Procfile in rails root within the following content:
web: bundle exec rails server puma -p $PORT -e $RACK_ENV
then add to Gemfile:
gem 'puma'
In above you can switch to thin, but consider link below (and many more details)
http://tenderlovemaking.com/2012/07/30/is-it-live.html
Heroku wouldn't necessarily be the issue here - it's an environment which allows your app to run (on Amazon EC2 I think)
Multi-Threaded Servers
The thing you've got to look for is the server software you use to run your app. Heroku basically takes your server gem & allows it to run with their processors, and other computing power; so it's really whether their platform can play ball with the right server
You're really looking for multi-threaded servers, which you can find here Is puma the ONLY multi-threaded rails 4 http server?
Puma
Rainbows! supports multiple concurrency models, including multithreading
Zbatery - Rack HTTP server without a fork stuck in it
Phusion Passenger 4 has supported multithreading since its beta stages
Thin does have a threaded mode which can be enabled by passing
--threaded or by setting threaded: true in the appropriate configuration file (e.g. bundle exec thin start --threaded)
Net::HTTP::Server, despite the lack of advertising, supports
multithreading; very minimalist
I have the following in the Gemfile of a Rails project, yet workless (https://github.com/lostboy/workless) is not working (it is not starting a Heroku worker dyno when a job is added to the Delayed::Job queue).
gem 'delayed_job_active_record'
gem 'workless'
gem 'daemons'
Unfortunately this is a silent error, so I just ended up figuring it out after quite some time.
As per the gem's instructions: Add your Heroku app name / API key as config vars to your Heroku instance.
heroku config:add HEROKU_API_KEY=yourapikey APP_NAME=yourherokuappname
Get yourapikey from https://dashboard.heroku.com/account and yourherokuappname from https://dashboard.heroku.com/apps
Also, if you are using a Procfile to declare what commands are run by your application's dynos on the Heroku platform, there is NO need for a worker line (worker: bundle exec rake jobs:work) in Procfile -- that would only be need if you were not using workless.
So this is something I ran into setting up a new Heroku account for a friend. No credit card on file. Although their is free time on the account, the account will be blocked from doing the sort of things that might incur charges without credit information on file.
Just FYI for anyone that runs into this and has everything set up correctly.
For people who will have similar problems, if you have some worker which you need to run all the time (not delayed job e.g) and you have some other which you would like to run with workless.
Define the independent worker as a separate process in the Procfile and don't use the word 'worker' in it's name, because of https://github.com/lostboy/workless/blob/master/lib/workless/scalers/heroku_cedar.rb#L18
I need to use both JRuby and MRI for my rails app.
Here's the scenario -
My app uses a background server which handles a lot of threads. I'm having performance
issue with running it on MRI. The background server is started with a rake task and needs
to use the Rails environment.
I'm using Passenger for the Web Server. Since JRuby support for Passenger is quite recent,
I would like to go with using MRI.
Here's something I want -
This uses Ruby 1.9 to start the server :
sudo passenger start -p 80 -e production --user=deploy
and within the same app, this runs the background server -
jruby -S rake background_server:start_daemon RAILS_ENV=production
The problem is, the second command jruby -S rake asks for rebundling the app.
Is there any way I can get this in place?
Not in the same app. you'll need separate applications that run under different rubies if you want this to happen. in SOA architecture, you'd send a message to your background server for it to process a job.
So, in heroku you'd create one application for your web running in MRI; then you'd create an application in JRuby for your background processes. They'd communicate via a shared Redis or shared database.
I would recommend using Trinidad or Puma and keeping it all in JRuby though (as opposed to keep running passenger); it'll be a much simpler architecture.
Unlike Webrick, can Mongrel be used in production? I'm looking for a small web server for Ruby on Rails that can be used locally in case of an emergency and all lines to the main webserver on the Internet are down. I thought I could start it with a batch file like ruby script/server and webrick does.
Thank you for any help.
You might as well use Passenger to do this as getting Mongrel properly tuned is a bit if a fuss. You usually can't use a single Mongrel instance to handle anything other than an extremely light load, so you'll need to configure some kind of proxy balancer at the very least, and from there you'll end up having to monitor the Mongrel processes in case any die or get too bloated and need to be restarted.
Mongrel can be used in production, but it is a lot more work than Passenger.
Mongrel is not supported or being developed any more. As another answer states you can use other products. You could also use Unicorn which also has forking like Passenger but does not have integrated web server. For simple purposes Passenger is probably best.