Rails + Heroku + Amazon RDS - Production vs Development - ruby-on-rails

It is my first time working with a Rails app on Heroku. It uses a mysql db hosted on Amazon RDS. At some point I want to move it from development to production. I want to keep developing and adding features. What is the best way to accomplish this?
I see Heroku has some kind of staging app feature. Is that the best option for me to keep a separate app to test? And what about the database? I'm guessing I need to create a separate db on Amazon RDS for development and for production?
I am on a budget so I don't want to have to pay for 2 apps on Heroku and 2 db's on Amazon. Can I create both on the fly each time I do development work and then destroy them when I'm done, or is that too much? If so can I then copy the production data over to the development data? I would do local testing but I feel like I need to make sure it's working on Heroku as well.
I'm just trying to get a general idea of what workflow is best practice or most commonly used. Any comments are appreciated.

Unfortunately, as you're on RDS you're going to have to pay for two. If you were using Heroku Postgres you'd be able to get a simple small PG database for free.
Regarding applications - Heroku apps are free if you use less than 750 'dyno' hours a month (which is a little bit more than one dyno for an entire month), which is normally fine for staging small apps as long as you don't have masses of workers required.
You certainly could create the staging env whenever you need it, but only you know how complex this application is and what sort of overhead that would provide.

Related

Why is Heroku running so much slower than localhost?

I created a simple stock screener (filters out stocks given certain criteria) in Rails. On my localhost the stocks update instantly, but on Heroku it can take anywhere from 10-15 seconds before the stock list is updated.
My Heroku app is here: http://fruthscreener.herokuapp.com/
Github is here: github dot com/anfruth/Fruth_Screener_Rails
The code involved in updating the queries can be found in the user_stocks model and in the stocks controller under def create.
Any ideas why this is happening and suggestions as to how to fix it?
Thank you.
Not slow for me
--
Heroku
The only thing which will slow Heroku down is if your db connection is "off-site"
We've had apps before which ran super slowly due to the case that the database provider was a different host, in a different country.
Heroku runs on AWS, meaning it will run super fast if you have all the dependencies in the same data-center. One of the drawbacks of using one of these powerful "cloud" hosting providers is they need to keep all requests local to help their system run quickly; hence if your DB is "off-site", it will slow it down profusely.
You must remember that Rails apps can't run unless they have a db connection; so if your connectivity is slow, your app's performance is going to be hit hard
-
Postgres
If your app is running slow on Heroku, the best thing to do is to make sure you're using Heroku's postgres database. This is deployed on Heroku's AWS cloud, meaning it's on the same network as your app, hence allowing it to run as quickly as possible
You'll need to change your app's database connection to the new production server like this:
#config/database.yml
production:
.... #-> your Heroku db details here
This will allow you to run heroku run rake db:migrate after you push this new code to Heroku - which should define the db structure for you, allowing you to populate it as you wish
It sounds like you would benefit from using New Relic or another performance management package for Heroku in order to find out what is causing you trouble exactly. The free tier of New Relic should be enough to get you started.
By the way, if your app is a Heroku free tier app (one single web dyno), then your dyno will go to sleep when not in use, and you may be encountering dyno spin-up costs, which are frequently about 5-15 seconds. Repeat the same query several times in several minutes and see if the slowness persists for every request, or only the first one.

Moving Heroku Shared Database

I recently reached the 5mb database limit with heroku, the costs rise dramatically after this point so I'm looking to move the database elsewhere.
I am very new to using VPS and setting up servers from scratch, however, I have done this recently for another app.
I have a couple questions related to this:
Is it possible to create a database on a VPS and point my rails app on heroku to use that database?
If so, what would database.yml actually look like. What would be an example localhost with the database stored outside the app?
These may be elementary questions but my knowledge of servers and programming is very much self taught, so I admit, there may be huge loopholes in things that I "should" already understand.
Note: Other (simpler) suggestions for moving my database are welcomed. Thanks.
OK - for starters, yes you can host a database external to Heroku and point your database.yml at that server - it's simply a case of setting up the hostname to point at the right address, and give it the correct credentials.
However, you need to consider a couple of things:
1) Latency - unless you're hosting inside EC2 East the latency between Heroku and your DB will cause you all sorts of performance issues.
2) Setting up a database server is not a simple task. You need consider how secure it is, how it performs, keeping it up to date, keeping it backed up, and having to worry day and night about it being up. With Heroku you don't need to do this as it's fully managed.
Price wise, are you aware of the new low cost Postgres plans at Heroku? $15/mo will get you 20Gb (shared instance), and $50/mp will get you a terabyte (dedicated instance). To me, that is absurdly cheap as I value my time much more, and I know how many hours I would need to invest in making my own server to save maybe $10 a month.
It would be cheaper to use Amazon RDS, which is officially supported by Heroku and served from the same datacenter (Amazon US-East). If you do want to use a VPS, use an Amazon EC2 instance in US-East for maximum performance. This tutorial shows exactly how to do it with Django in detail. Even if you don't decide to use EC2, refer to that tutorial to see how to properly add external database information to your Heroku application so that Heroku doesn't try to overwrite it.
Still, Heroku's shared database is extremely cost-competitive -- far moreso than most VPSes and with much less setup and maintenance.

Node.js and rails app hosting with a shared MongoDB database and pricing

I have been experimenting a lot with node.js as well as with rails and mongoDB lately. I'd like to know if there's any hosting options out there where I can deploy my apps written in rails and node.js which will share a same MongoDB database?
My rails app will do most of the writing to the mongoDB instance, while the node.js app will only fetch(read) the data from there.
I have heard about heroku, but it seems that it's more focus on mid-large scale deployment while I'm currently only looking for a simple small deployment since this would only be for personal use, and I dont expect too many visitors anyway. I've also heard that Heroku is available for free under certain condition.. Is this true? Also, is google app engine an option for me?
Would like to hear from people who have experience hosting their personal rails/node.js apps with heroku or any other hosting options, including shared hosting as well. Thanks.
http://www.heroku.com/pricing
Hosting free for 1 dyno and 5Mb postgresql shared database. There are two mongo addons, with free 240Mb database. Perfect for a small deployment and tests :)
Also, is google app engine an option for me?
App Engine is kind of its own little world, so you can't install MongoDB on app engine.
Would like to hear from people who have experience hosting their personal rails/node.js apps with heroku or any other hosting options, including shared hosting as well.
Honestly, for small apps, the other option is simply to buy a small VPS. Places like Linode sell them for $20 / month with full access.
You can also use Amazon AWS. They have a free tier for new customers. You can also buy a reserved "Micro" for $23 / year (if you pay in advance). Of course, Amazon will nickel and dime you for everything, so it will probably be more than that. It should stay under $10 / month though. Of course, there are other competitors here like Rackspace.
If you don't want to host the DB, you can also use MongoLab or MongoHQ and pick your cloud provider. They generally offer to host your data in the same DC as your provider.

Deploying Rails App

I have a question about deploying a Rails application. I know the information exists else where, but my issue is that I can't place it cohesively together. Currently I'm on Dreamhost and would like instructions on how to deploy my app there. I feel like I should be using Capistrano in some fashion but I honestly am pretty lost. Any suggestions on deploying easily or a better host that is around the same price point (less than $10 a month).
Any suggestions on deploying easily or a better host that is around the same price point (less than $10 a month).
Have you heard of Heroku yet? You can run a single dyno instance (one running instance of your application) for free, including access to a shared Postgres database service. It's extremely popular among rubyists for good reason.
You should take a look at this screencast from peepcode for details about hosting your app using capistrano. It is about installing phusion-passenger but they also explain how you can host your application on 'Dreamhost'

Tips on deploying Ror

How can I go about deploying a Rails app on a cluster of Amazon EC2 servers? Any recommended guides?
I maintain a RoR app (currently hosted on Heroku) that uses a DB and DelayedJobs). The app has a large footprint, and needs to be distributed on a cluster most likely. Any tips would be appreciated. Are there Amazon AMIs that replicate some of Heroku's features (especially DJ)?
P.S. I'm quite a Ruby newbie.
Any reason it can't stay on Heroku? You can scale Heroku dynos and workers as you see fit, and can upgrade to a dedicated database instance if it really needs it.
I would use a clean (ebs-based) AMI from Alestic or Amazon and configure it myself. It's very difficult to find an appropriate AMI (or several for web-server, app-server, DB-server and make them work together) and a high risk to trust it.

Resources