WomenWhoCodeSydney_PerformanceTipsRoR

Post on 19-Aug-2014

79 views 1 download

Tags:

description

This was a lightning talk presented at Women Who Code Sydney May 2014. A look into some techniques that can be applied to RoR apps (and most apps in general) on how to improve performance. We'll be looking into scaling, caching and other methods to grow from a single server database app to bigger apps :)

transcript

Performance for RoR Apps(some tips)

About Meclairettran

Performance Is Important

Yay!● AirBnb, Netflix, Twitter*, Facebook, Zynga

* Used to have outages, but fixed their performance issues

● Jetstar ticket salesOops!

● Myer Boxing Day 2013● Click Frenzy 2012

Example Stats for SMH

At Peak: 28K requests per minute14th May: 4,000,000 hits to the site

Some Common Problems● Memory leaks● Long running API call(s)● Slow synchronous processes

(e.g. Emails, PayPal)

● Slow database queries● Network issues

Note: not an exhaustive list

What I’ll Cover● Monitoring● Caching● Scaling● Database

MonitoringHow to know there is a performance problem?

+ Response time, rpm, memory usage, CPU usage, error rates

MonitoringWhat else can I do?● Logs (e.g. file server, splunk, loggly, logstash)

● Memory Usage (e.g. unix top command)

● Performance tests (e.g. Apache bench, JMeter, Neoloader)

● Health Checks (e.g. health_check gem, Nagios, Sitescope)

● More calls to the call centre

CachingHow?● Cache store (key-value store)

● Fragment caching (part of the page)

● SQL caching (cache query results)

Removed in Rails4: Action Caching & Fragment Caching

Caching

Before: No Caching

After: With Caching!

Problem: Page making long running/many external requests

Scaling

Load Balancer

www.mysite.com

Cache Cluster

Cache

Static Files

(css, js, images)

Virtual IP

Replication(Active-Passive)

Database● Add an index● Profiling● Batch queries● Eager fetching● Denormalisation● Sharding

Other Techniques● Queuing/Background Jobs● Caching● Dedicated services● Rails engines● C-extensions (gems)● Sprites● Asset pipeline● Cache control headers● Gzip assets● Less HTTP requests● Dedicated Search Service

● Remove unused assets (are all those bootstrap files needed?)

● Static cluster● AWS Auto-scaling● Akamai (edge caching)● YSlow● Local Storage● Smaller Responses● Async JS● Chrome DevTools● JRuby

Further Readinghttps://github.com/ianheggie/health_checkhttp://guides.rubyonrails.org/caching_with_rails.htmlhttp://railscasts.com/episodes/380-memcached-dallihttps://developers.google.com/events/io/sessions/324511365http://railscasts.com/episodes/366-sidekiqhttp://www.slideshare.net/derekmbrown/netflix-strategic-performance-analysishttp://blog.jphpsf.com/2012/04/28/front-end-performance-case-study-github

Questions