Ad

Tuesday, April 30, 2013

Performance test and debugging for Noobs - Rails, Heroku and Rails

Monday I stopped by the New Relic office for live streaming #RailsConf. Creator #DHH talked about the future of Rails - Rails 4 and multiple caching options, designing pattern details. I saw New Relic last time when they brought the Obama tech team to SF. Not impressed, but today I hit a Heroku bug and was tired of tailing the logs (having to constantly go back to my machine) and Pg Admin to shared Amazon servers... yeah too much overhead for my one-pager. What do I do? Also, what's a better opportunity to learn a tool without having to read the documentations? We all know documentations are important in coding.

For Rails app hosted on Heroku

STEP 1

Deploy to Heroku and select New Relic as an Add-on

STEP 2

Command line $heroku addons:add newrelic in the Rails app directory of your newly deployed app

You may be prompted for heroku.com/verify

That means you have to enter your credit card, no worries, you won't be charged. But you may want to reset your Heroku password to something more secure.

Run $heroku addons:add newrelic again after "verification"

STEP 3

Feel free to run $heroku addons:docs newrelic to open up the documentation
Or visit https://devcenter.heroku.com/articles/newrelic

STEP 4
Follow documentation to add gem to gemfile (gem 'newrelic_rpm') then bundle install

STEP 5
In Rails app directory:

$curl https://raw.github.com/gist/2253296/newrelic.yml > config/newrelic.yml

STEP 6
Modify your newrelic.yml file that you just received in the config directory of your Rails app. Change your app name

app_name:"your app name here"
or use the environment variable format provided

STEP 7
Go to your app refresh a few times, navigate through a few pages and generate some traffic

STEP 8
Log back into Heroku, navigate to your app admin, then the Add-on, select new relic, you will be automatically log into your Dashboard

You just gained access to your full performance and error log for both front end and back end. I was able to get data on page rendering, DOM load, script and database performance. It was awesome. For those who don't like $heroku logs --tail, or simply aren't on the right computer all the time with the right toolbelt. Here's an awesome way to view your stats.

While the stats is a bit of overkill compared to Google Analytics for an average user, but the error log (narrowing down to controller, methods, and specific ruby stack trace) was invaluable even for a noob.

A common noob mistake that I and many people make: forgetting to update the repo, so you will need to
$git add . (or add whatever)
$git commit -m"e.g. adding the newrelic.yml file"
$git push
$git push heroku master










No comments:

Post a Comment

Host an HTML website on Github in 5 minutes HD

Tutorial how to set up web hosting, personal portfolio website on Github in 5 minutes. More content coming to this paid channel including in...