optimizing production apps on heroku 7.31.13
DESCRIPTION
This deck is from a live presentation on 7/31/13 which featured an in-depth look at optimizing production apps on Heroku. This is the second session in a two part series for production apps on Heroku. Video recording can be found here https://vimeo.com/71442888. Check out vimeo.com/69263217 for the first session on setting up and running production apps. Topics for this presentation include: * Using a CDN to increase app performance * How to manage the asset pipeline * Using heroku-pg-extras to gain visibility into database performance * How to manage database migrations * How to use a database follower for transactional and analytics database reads * How to set up caching with Heroku add-ons * Useful labs features Looking for 1:1 assistance with your production apps, please contact our Customer Success team here - lp.heroku.com/ProductionApps.html?mkt_tok=3RkMMJWWfF9wsRow5%2FmYJoDpwmWGd5mht7VzDtPj1OY6hBkvKrWJK1TtuMFUGpsqOOGbEw0bBg%3D%3DTRANSCRIPT
![Page 1: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/1.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Optimizing Production Apps Optimizing Production Apps on Herokuon HerokuOptimizing Production Apps Optimizing Production Apps on Herokuon Heroku
Ryan Huber, Customer AdvocateRyan Huber, Customer Advocate@ryan_huber@ryan_huber
Greg Nokes, Technical Account ManagerGreg Nokes, Technical Account Manager@tsykoduk@tsykoduk
![Page 2: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/2.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
IntroductionsIntroductions
Ryan HuberCustomer Advocate
@ryan_huber
Greg NokesTechnical Account
Manager@tsykoduk
![Page 3: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/3.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
AgendaAgendaAgendaAgenda Using CDN to increase app performance
Managing Asset Pipeline (RoR specific)
PG Extras - Postgres
Postgres Database Migrations
Postgres Database Followers
Database Caching
Recommended Monitoring Tools
![Page 4: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/4.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
AssumptionsAssumptionsAssumptionsAssumptions Existing Heroku User
General understanding of Heroku / CLI
Have installed Toolbelt & created / pushed apps
General understanding of Postgres / SQL
Have provisioned Postgres databases on Heroku
*** This webinar is being recorded and distributed online ***
![Page 5: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/5.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Asset PipelineAsset PipelineAsset PipelineAsset Pipeline
![Page 6: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/6.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Asset PipelineAsset PipelineAsset PipelineAsset Pipeline
Processes assets for use by Caching
![Page 7: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/7.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Asset PipelineAsset PipelineAsset PipelineAsset Pipeline
Two hard problems in Computer Science:
1. Cache Invalidation
2. Naming Things
3. Off by One errors
![Page 8: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/8.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Asset PipelineAsset PipelineAsset PipelineAsset Pipeline
Helps with Cache Invalidation and Naming Things
![Page 9: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/9.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Asset PipelineAsset PipelineAsset PipelineAsset Pipeline
What about uploading to S3?
![Page 10: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/10.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Asset PipelineAsset PipelineAsset PipelineAsset Pipeline
NO
![Page 11: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/11.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Asset PipelineAsset PipelineAsset PipelineAsset Pipeline
Then you have 2 sets of files to manage
![Page 12: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/12.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Asset PipelineAsset PipelineAsset PipelineAsset Pipeline
Leave them on the Dyno
Use a Edgecache CDN such as:
CDN Sumo
Cloudfront
CDNetworks
Akamai
![Page 13: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/13.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Why Use a CDN? Why Use a CDN? Why Use a CDN? Why Use a CDN?
![Page 14: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/14.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
CDN vs S3CDN vs S3CDN vs S3CDN vs S3Application Assets User Generated Assets
![Page 15: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/15.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
S3 Best PracticesS3 Best PracticesS3 Best PracticesS3 Best Practices
Direct Upload
Pass-through Upload
* If processing is required *
https://devcenter.heroku.com/articles/s3
![Page 16: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/16.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
CDN Best PracticesCDN Best PracticesCDN Best PracticesCDN Best PracticesCache/Pull CDN
Sync/Push CDN
* Automatic Update*
* Manual Update*
Cache/Pull CDN Recommended
CDN Sumo (Heroku Addon)https://addons.heroku.com/
cdn_sumo
![Page 17: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/17.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
PG ExtrasPG ExtrasPG ExtrasPG Extras
http://www.craigkerstiens.com/2012/10/01/understanding-postgres-performance/
http://www.craigkerstiens.com/2013/01/10/more-on-postgres-performance/
![Page 18: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/18.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
PG ExtrasPG ExtrasPG ExtrasPG Extras
A Heroku plugin for awesome pg:* commands that are also great and fun
and super.
![Page 19: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/19.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
PG ExtrasPG ExtrasPG ExtrasPG Extras
There is a lot in there
![Page 20: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/20.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
PG ExtrasPG ExtrasPG ExtrasPG Extras
We will talk about two
1. heroku pg:cache_hit
2. heroku pg:index_usage
![Page 21: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/21.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
heroku pg:cache_hitheroku pg:cache_hitheroku pg:cache_hitheroku pg:cache_hit
Shows the cache hit ratio.
A good measure of database sizing
We like to see it at 99%
![Page 22: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/22.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
heroku pg:index_usageheroku pg:index_usageheroku pg:index_usageheroku pg:index_usage
Shows the index hit ratio on each table
Big, heavily used tables need to have 99 – 100%
![Page 23: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/23.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Postgres Database MigrationPostgres Database MigrationPostgres Database MigrationPostgres Database Migration
![Page 24: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/24.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Dev / Basic vs Production DBsDev / Basic vs Production DBsDev / Basic vs Production DBsDev / Basic vs Production DBs
Dev / Basic* Not suitable for production applications* Expected uptime of 99.5%* Many level features not supported: Fork, follow* Row number limitation: 10K for Dev, 10M for Basic.* The database instance is shared among many other customers
Production* Designed for higher uptime, 99.95%* No row level limitation* You get your own database instance* Fork, follow supported* Suitable for production applications
![Page 25: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/25.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Migrating Dev / Basic DBsMigrating Dev / Basic DBsMigrating Dev / Basic DBsMigrating Dev / Basic DBs
https://devcenter.heroku.com/articles/upgrade-heroku-postgres-with-pgbackups
![Page 26: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/26.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Migrating Production DBsMigrating Production DBsMigrating Production DBsMigrating Production DBs
https://devcenter.heroku.com/articles/heroku-postgres-follower-databases
![Page 27: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/27.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Follower DatabasesFollower DatabasesFollower DatabasesFollower Databases
Starter:
Development
No Fork/Follow
99.5% uptime
![Page 28: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/28.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Follower DatabasesFollower DatabasesFollower DatabasesFollower Databases
Production:
Can Fork/Follow
99.95% uptime
![Page 29: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/29.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Follower DatabasesFollower DatabasesFollower DatabasesFollower Databases
![Page 30: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/30.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Follower DatabasesFollower DatabasesFollower DatabasesFollower Databases
Why?
![Page 31: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/31.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Follower DatabaseFollower DatabaseFollower DatabaseFollower Database
HA
![Page 32: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/32.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Follower DatabaseFollower DatabaseFollower DatabaseFollower Database
Analytics / Reporting
![Page 33: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/33.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Follower DatabasesFollower DatabasesFollower DatabasesFollower Databases
Octopus gem (https://github.com/tchandy/octopus)
![Page 34: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/34.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Overcoming Postgres Connection LimitsOvercoming Postgres Connection LimitsOvercoming Postgres Connection LimitsOvercoming Postgres Connection Limits
![Page 35: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/35.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Overcoming Postgres Connection LimitsOvercoming Postgres Connection LimitsOvercoming Postgres Connection LimitsOvercoming Postgres Connection Limits
Limit the number of connections
https://devcenter.heroku.com/articles/forked-pg-connections
![Page 36: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/36.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Overcoming Postgres Connection LimitsOvercoming Postgres Connection LimitsOvercoming Postgres Connection LimitsOvercoming Postgres Connection Limits
Sometimes that’s not enough
![Page 37: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/37.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Overcoming Postgres Connection LimitsOvercoming Postgres Connection LimitsOvercoming Postgres Connection LimitsOvercoming Postgres Connection Limits
https://github.com/gregburek/heroku-buildpack-pgbouncer
![Page 38: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/38.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Caching for Profit & PerformanceCaching for Profit & PerformanceCaching for Profit & PerformanceCaching for Profit & Performance
![Page 39: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/39.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Caching for Profit & PerformanceCaching for Profit & PerformanceCaching for Profit & PerformanceCaching for Profit & Performance
https://devcenter.heroku.com/articles/memcachier
http://guides.rubyonrails.org/caching_with_rails.html
![Page 40: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/40.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Performance MonitoringPerformance MonitoringPerformance MonitoringPerformance Monitoring
New Relic
Dyno Queuing
Runtime Metrics (https://devcenter.heroku.com/articles/log-
runtime-metrics)
Log2viz (http://log2viz.herokuapp.com/)
Logging
![Page 41: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/41.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
New RelicNew RelicNew RelicNew Relic
https://devcenter.heroku.com/articles/newrelic
Ruby
Java
Python
Node
![Page 42: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/42.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
New Relic: BenefitsNew Relic: BenefitsNew Relic: BenefitsNew Relic: Benefits
https://devcenter.heroku.com/articles/newrelic
![Page 43: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/43.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
New Relic: Pro vs StandardNew Relic: Pro vs StandardNew Relic: Pro vs StandardNew Relic: Pro vs Standard
https://devcenter.heroku.com/articles/newrelic
![Page 44: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/44.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
New Relic: Caveats New Relic: Caveats New Relic: Caveats New Relic: Caveats
https://devcenter.heroku.com/articles/newrelic
![Page 45: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/45.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Dyno QueuingDyno QueuingDyno QueuingDyno Queuing
Processing in the router
Traveling over the network to a dyno
Queuing in the TCP socket backlog
Processing by the web server
Processing by Rack middleware
https://devcenter.heroku.com/articles/newrelic#interpreting-new-relic-request-queueing
![Page 46: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/46.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Runtime MetricsRuntime MetricsRuntime MetricsRuntime Metrics
Resident Memory (memory_rss)
Disk Cache Memory (memory_cache)
Swap Memory (memory_swap)
Total Memory (memory_total)
Pages Written to Disk (memory_pgpgout)
Pages Read from Disk (memory_pgpgin)
CPU Load Avg (1 min, 5 min, 15 min avgs)
https://devcenter.heroku.com/articles/log-runtime-metrics
![Page 47: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/47.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Log2vizLog2vizLog2vizLog2viz
http://log2viz.herokuapp.com/
![Page 48: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/48.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
LoggingLoggingLoggingLogging
https://devcenter.heroku.com/articles/logging
![Page 49: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/49.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
RecapRecapRecapRecap
Cache Assets
PG-Extras to Understand DB Performance
Select the Right DB Plan / Configuration
Leverage App Monitoring Tools
![Page 50: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/50.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
![Page 51: Optimizing production apps on heroku 7.31.13](https://reader035.vdocuments.site/reader035/viewer/2022062513/5551eb95b4c905f56f8b4d9a/html5/thumbnails/51.jpg)
Join the conversation via #herokuJoin the conversation via #heroku
Q&AQ&A
Ryan HuberCustomer Advocate
@ryan_huber
Greg NokesTechnical Account
Manager@tsykoduk