I am trying to improve the performance of my pre-beta Rails 3.2 app hosted on Heroku.
Aggressive caching has dramatically improved things, but I still notice a large contribution from "Time spent in Ruby" when looking at my app server response time on New Relic (light blue on the graph).
What parts of a Rails app typically contribute to this 'Ruby time'?
I initially thought this was due to complex conditionals in one of my main controllers, but have simplified this. My views are now very aggressively cached using Russian Doll fragment caching and memcache (wow!).
Could serving of static assets be a cause? (Moving to S3 / CloudFont is on the todo list...)
Thanks!
(I already have delayed_job setup and have moved all that I can into the background. I'm also using Unicorn as my web server.)
UPDATED Performance Tuning
After aggressive caching, I started looking for other ways to improve app performance.
First I added Garbage Collection monitoring as suggesting, finding that GC was not significantly contributing to the Ruby time.
Next I decided to hit my asset serving by adding in a CDN (Cloudfront via the CDNsumo add-on). Interesingly this did actually decrease my Ruby time on NR monitoring. (The CDN was provisioned and then warmed by the last request-test on the far right of the graph below.) Most of my pages have a couple-hundred kb of css & javascript - so not tiny but not massive.
Finally, I upgraded from the 'Basic' starter database to the smallest production db 'Crane'. This had a dramatic effect on performance. After a little caching by PG the app flies. (final 3 request spikes on the graph below).
Take home messages for others trying to tune their Heroku apps:
- Simple performance tuning in multiple areas (ie. caching, CDN, database, Ruby code) has a synergistic effect across the stack.
- Conversely, any single performance drain will be a bottleneck that you cannot overcome even if you tune the other areas (ie. the slow starter Basic or Dev databases on Heroku versus an 'expensive' production database - the slow Basic db was killing my app performance).
- NewRelic is essential in working out where the most gains can be made.