Javier
Javier

Reputation: 249

Adding Temporary Dyno for Spike in Traffic to my site (Heroku Rails App)

I am expecting a large increase in traffic tomorrow(press, etc) to my website. I want to be able to manage the traffic without it going down. I know that I have to add dyno's and the cost is not too prohibitive because it is only temporary to keep the queue down.

I am using New Relic Add-On to Monitor

This post is really helpful: https://serverfault.com/questions/394602/how-to-prepare-for-a-huge-spike-in-traffic-for-launching-a-website-hosted-on-her

However after reading that post and pouring over heroku docs I have not been able to figure out how I actually do this...

What command can I run or from what interface can I spin up a new dyno to handle the added web traffic? Then, with what command do I run or from what interface do I eliminate that extra dyno when the traffic has return to normal levels?

Heroku talk about a bunch of different types of dyno's etc but I have no idea which one I am supposed to use and then how to actually spin up a new one.

Upvotes: 2

Views: 218

Answers (1)

avinoth
avinoth

Reputation: 430

Heroku has an platform-api gem that will be useful for you in this case. First add the gem to your Gemfile and install it.

gem platform-api

Once installed, setup the heroku client, preferably in an initializer

$heroku = PlatformAPI.connect(ENV['HEROKU_API_KEY', default_headers: {'Accept' => 'application/vnd.heroku+json; version=3'})

You can find how to get an Heroku API KEY here

Now, to the scaling part. I'm guessing you have some internal metrics to decide when to scale (by process count, request count, etc). The below command will scale up the number of dynos you require,

$heroku.formation.update(APP_NAME, PROCESS_NAME, {quantity: DYNO_COUNT})

This will scale the app's specified process to X number of dynos whenever required.

You can use the same command to scale down your number of dynos. Also, below command will help you get the number of dynos currently provisioned for a particular process

info = $heroku.formation.info(APP_NAME, PROCESS_NAME)
info['quantity']

To get the number of ALL dynos provisioned to your app, use

$heroku.app.info(APP_NAME)

EDIT:

In case you prefer it to do manually, then you can do this in the heroku's dashboard itself. Or if you prefer command line, install heroku toolbelt and below is the command for scaling the app.

heroku ps:scale process_name=dyno_count -a app_name

To get the list of dynos provisioned

heroku ps -a app_name

Upvotes: 1

Related Questions