High Performance Ruby on Rails and MySQL. David Berube



Similar documents
NoSQL replacement for SQLite (for Beatstream) Antti-Jussi Kovalainen Seminar OHJ-1860: NoSQL databases

Drupal Performance Tuning

Ruby on Rails. a high-productivity web application framework. blog.curthibbs.us/ Curt Hibbs <curt@hibbs.com>

A Model of the Operation of The Model-View- Controller Pattern in a Rails-Based Web Server

The importance of Drupal Cache. Luis F. Ribeiro Ci&T Inc. 2013

Monitoring MySQL database with Verax NMS

HYBRID. Course Packet

NOSQL INTRODUCTION WITH MONGODB AND RUBY GEOFF

GigaSpaces Real-Time Analytics for Big Data

Transaction Monitoring Version for AIX, Linux, and Windows. Reference IBM

MySQL Security for Security Audits

Database Administration with MySQL

The Devil is in the Details. How to Optimize Magento Hosting to Increase Online Sales

Abdullah Radwan. Target Job. Work Experience (9 Years)

Simple Tips to Improve Drupal Performance: No Coding Required. By Erik Webb, Senior Technical Consultant, Acquia

Web Development Frameworks

Easy Deployment of Mission-Critical Applications to the Cloud

Sharding with postgres_fdw

Introduction. AppDynamics for Databases Version Page 1

Web Framework Performance Examples from Django and Rails

Reference Model for Cloud Applications CONSIDERATIONS FOR SW VENDORS BUILDING A SAAS SOLUTION

MOOCviz 2.0: A Collaborative MOOC Analytics Visualization Platform

Why NoSQL? Your database options in the new non- relational world IBM Cloudant 1

the missing log collector Treasure Data, Inc. Muga Nishizawa

Rails Cookbook. Rob Orsini. O'REILLY 8 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

CI Pipeline with Docker

AbleBridge: Project Management 2013 v7.1.0

Top 10 reasons your ecommerce site will fail during peak periods

Outline. Lecture 18: Ruby on Rails MVC. Introduction to Rails

MySQL: Cloud vs Bare Metal, Performance and Reliability

Zynga Analytics Leveraging Big Data to Make Games More Fun and Social

Getting started with your AppDev Microsoft Development Library

Site Audit ( /site_audit) Generated on Fri, 22 Aug :14:

High-Volume Data Warehousing in Centerprise. Product Datasheet

Ruby On Rails. CSCI 5449 Submitted by: Bhaskar Vaish

Pro<DOC/> e-commerce Technology An Introduction

5 Mistakes to Avoid on Your Drupal Website

making drupal run fast

Performance White Paper

TO SQL DB. Manual. Page 1 of 7. Manual. Tel & Fax: info@altiliagroup.com Web:

Test Run Analysis Interpretation (AI) Made Easy with OpenLoad

Quick Start Guide. Ignite for SQL Server. Confio Software 4772 Walnut Street, Suite 100 Boulder, CO CONFIO.

Accelerating Wordpress for Pagerank and Profit

Ruby on Rails is a web application framework written in Ruby, a dynamically typed programming language The amazing productivity claims of Rails is

Monitoring PostgreSQL database with Verax NMS

The CF Brooklyn Service Broker and Plugin

Personal Profile. Experience. Professional Experience

In Memory Accelerator for MongoDB

BeBanjo Infrastructure and Security Overview

Product Review: James F. Koopmann Pine Horse, Inc. Quest Software s Foglight Performance Analysis for Oracle

Optimizing WordPress Performance: Page Speed and Load Times. Doug Yuen

Getting Started with Telerik Data Access. Contents

Building a Scalable News Feed Web Service in Clojure

Professional Joomla! Migration. User Guide. Version 1.1 Date: 25th March Vibaweb Ltd. All rights reserved.

Using MySQL for Big Data Advantage Integrate for Insight Sastry Vedantam

About Me: Brent Ozar. Perfmon and Profiler 101

GETTING STARTED GUIDE. A Microsoft Azure User s Guide to Getting Started with New Relic. Get better visibility into complex cloud environments

Web Applications: Overview and Architecture

Monitoring the Real End User Experience

Growing in web environment at XING

PaaS - Platform as a Service Google App Engine

SCALABLE DATA SERVICES

Rails Application Deployment. July Philly on Rails

ICAB4136B Use structured query language to create database structures and manipulate data

HP OO 10.X - SiteScope Monitoring Templates

Tech Radar - May 2015

Web Performance. Sergey Chernyshev. March '09 New York Web Standards Meetup. New York, NY. March 19 th, 2009

Scaling Pinterest. Yash Nelapati Ascii Artist. Pinterest Engineering. Saturday, August 31, 13

The Learn-Verified Full Stack Web Development Program

MONyog White Paper. Webyog

How To Train Aspnet

2013 Ruby on Rails Exploits. CS 558 Allan Wirth

Structured Data Storage

Sitecore Health. Christopher Wojciech. netzkern AG. Sitecore User Group Conference 2015

KEYSTONE JS FOR DRUPAL DEVELOPERS

Zend and IBM: Bringing the power of PHP applications to the enterprise

PTC System Monitor Solution Training

Introduction: Ruby on Rails

Analytics March 2015 White paper. Why NoSQL? Your database options in the new non-relational world

Getting Started With Your LearnDevNow Learning

There are numerous ways to access monitors:

New Relic & JMeter - Perfect Performance Testing

WHITE PAPER. Domo Advanced Architecture

MySQL és Hadoop mint Big Data platform (SQL + NoSQL = MySQL Cluster?!)

MakeMyTrip CUSTOMER SUCCESS STORY

Transcription:

High Performance Ruby on Rails and MySQL David Berube

Who am I? Freelance software developer Currently working mostly with clients in the entertainment industry, notably including the Casting Frontier Author: Practical Ruby Gems Practical Reporting with Ruby and Rails Practical Rails Plugins (with Nick Plante)

What is Rails? Popular web development framework MVC paradigm Model View Controller Agile, rapid development

Why are Rails apps Slow? Makes assumptions: Selects all fields by default Limited knowledge: can't preload without help. Ruby Oriented culture SQL is bad attitude Test environment different from production environment. Many more possible reasons.

How can I tell what's slow?

Rails development log Gross metrics: percentage of time spent in DB, view, etc Tools: http://github.com/newtonapple/railsdevelopment log analyzer

query_reviewer Ajax popup displays query count, query time for each query on a page

mysql_slow_log http://dev.mysql.com/doc/refman/5.1/en/slowquery log.html

New Relic Awesome solution. Easy to install plugin reports performance and error data. Provides user response time reports, SQL query delay breakdown Has API for custom instrumentation. Per server cost is relatively high, but worth it. (I have no financial interest in New Relic.)

Is it a database problem? Firebug Yslow Ping, tracert, and friends

Specific Rails Problems and Solutions

Do Sorting and Limiting in the Database Do this: @items = Item.find(:all, :order=>'name ASC') @items.each do item # do something...... not this: @items = Item.find(:all) @items.sort_by(&:name).each do item # do something... EXCEPTION: If you need to sort data multiple ways in the same action.

N+1 query problem How many queries does this produce? <%@posts = Post.all @posts.each do p %> <h1><%=p.category.name%></h1> <p><%=p.body%></p> <%end%>

Answer: one query plus one query per row in @posts. Not good.

Eager Loading Fix: @posts = Post.find(:all, :include=>[:category]) Will generate at most two queries no matter how many rows in the posts table.

Deep Eager Loading What if we want to do this? @posts.each do p <h1><%=p.category.name%></h1> <%=image_tag p.author.image.public_filename %> <p><%=p.body%> <%end%> Problem: how do we eager load nested relationships?

Answer: @posts = Post.find(:all, :include=>{ :category=>[], :author=>{ :image=>[]}}

Indirect Eager Loading How many queries does this produce? <%@user = User.find(5) @user.posts.each do p %> <%=render :partial=>'/posts/summary', :locals=>:post=>p%> <%end%>

posts/_summary.html.erb <h1><%=post.user.name%></h1>...snip...

Answer Produces an extra query per row in post looking up the users name. (Rails does not, as of yet, associate child records with their parents.) Solution? Self referential eager loading like this: @user = User.find(5, :include=>{:posts=>[:user]})

Rails Grouping/Aggregates Rails provides a series of grouping and aggregate functions for you all_ages = Person.find(:all, :group=>[:age]) oldest_age = Person.calcuate(:max, :age) See pages 20 32 of Practical Reporting with Ruby and Rails...but if the builtins aren't enough, use custom SQL.

Custom SQL with Rails sql = "SELECT vehicle_model, AVG(age) as average_age, AVG(accident_count) AS average_accident_count FROM persons GROUP BY vehicle_model" Person.find_by_sql(sql).each do row puts "#{row.vehicle_model}, " << "avg. age: #{row.average_age}, " << "avg. accidents: #{row.average_accident_count}" end RESULT: Ford Explorer, avg. age: 43.010, avg. accidents: 0.400 Honda CRX, avg. age: 18.720, avg. accidents: 1.25

Caching Important Simple out of box caching Has many relationships and counter caches Cache Fu MySQL triggers for DB function caching Rails triggers for other caching

Roll your own Rails Caching API Rails 2.1+ Rails.cache.write('test_key', 'value') Rails.cache.read('test_key') #=> 'value' Rails.cache.delete('test_key')

Rails caching API Configuration Pluggable backends: Memory File Drb Memcache Redis (via plugin) Configuration: config.cache_store = :mem_cache_store, 'localhost', '192.168.1.1:1001', { :namespace => 'test' } (from http://thewebfellas.com/blog/2008/6/9/rails 2 1 now with better integrated cac

Use Other Tools Where Appropriate Sphinx Memcached Redis Mongo Cassandra Client side javascript Do you need another server roundtrip?