Web Framework Performance Examples from Django and Rails



Similar documents
Drupal Performance Tuning

Elgg 1.8 Social Networking

django-cron Documentation

Scaling Rails with memcached

Rapid Website Deployment With Django, Heroku & New Relic

Going Beyond SAP ITS Mobile Apps to a Responsive Design Mobile Apps. JK (JayaKumar Pedapudi) Principal Consultant NTT DATA, Inc.

The Django web development framework for the Python-aware

High Performance Ruby on Rails and MySQL. David Berube

WordPress Optimization

Accelerating Wordpress for Pagerank and Profit

SAHARA DIGITAL8 RESPONSIVE MAGENTO THEME

How To Change Your Site On Drupal Cloud On A Pcode On A Microsoft Powerstone On A Macbook Or Ipad (For Free) On A Freebie (For A Free Download) On An Ipad Or Ipa (For

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

INDUSTRIAL AUTOMATION Interactive Graphical SCADA System INSIGHT AND OVERVIEW. IGSS Online Training. Exercise 8: Creating Templates

CS169.1x Lecture 5: SaaS Architecture and Introduction to Rails " Fall 2012"

Varnish the Drupal way

Building a Simple Mobile optimized Web App/Site Using the jquery Mobile Framework

Chapter 8 More on Links, Layout, and Mobile Key Concepts. Copyright 2013 Terry Ann Morris, Ed.D

latest Release 0.2.6

Django Two-Factor Authentication Documentation

Cache All The Things

Evaluation. Chapter 1: An Overview Of Ruby Rails. Copy. 6) Static Pages Within a Rails Application

Migration Guide Software, Database and Version Migration

ultimo theme Update Guide Copyright Infortis All rights reserved

Google Sites: Creating, editing, and sharing a site

Quick Start Guide Mobile Entrée 4

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

TIBCO Spotfire Metrics Modeler User s Guide. Software Release 6.0 November 2013

Top Navigation menu - Tabs. User Guide 1. &

Bubble Code Review for Magento

Building and Deploying Web Scale Social Networking Applications Using Ruby on Rails and Oracle. Kuassi Mensah Group Product Manager

Load testing with. WAPT Cloud. Quick Start Guide

X-POS GUIDE. v3.4 INSTALLATION SmartOSC and X-POS

CREATE A CUSTOM THEME WEBSPHERE PORTAL

Unique promotion code

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

Kentico Site Delivery Checklist v1.1

Pillars of Python: Six Python Web frameworks compared

TESTING AND OPTIMIZING WEB APPLICATION S PERFORMANCE AQA CASE STUDY

SMSNotify Extension. User Documentation. Automated SMS sender and customer relationship tool. SMSNotify User Documentation 1

MAGENTO THEME SHOE STORE

Logging on a Shoestring Budget

Build an ArcGIS Online Application

HGC SUPERHUB HOSTED EXCHANGE

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

Migrating helpdesk to a new server

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

INSTALLATION AND CONFIGURATION MANUAL ENCODER

How To Test Your Web Site On Wapt On A Pc Or Mac Or Mac (Or Mac) On A Mac Or Ipad Or Ipa (Or Ipa) On Pc Or Ipam (Or Pc Or Pc) On An Ip

What about MongoDB? can req.body.input 0; var date = new Date(); do {curdate = new Date();} while(curdate-date<10000)

Configuration Guide - OneDesk to SalesForce Connector

SharePoint 2010 Performance and Capacity Planning Best Practices

Beginning Web Development with Node.js

skype ID: store.belvg US phone number:

Building A Very Simple Web Site

SAHARA FASHION15 RESPONSIVE MAGENTO THEME

Performance Testing Crash Course

Response Time Analysis of Web Templates

Eylean server deployment guide

Bernd Ahlers Michael Friedrich. Log Monitoring Simplified Get the best out of Graylog2 & Icinga 2

Qualys API Limits. July 10, Overview. API Control Settings. Implementation

Predictive Analytics Client

System Requirements Table of contents

SelectSurvey.NET Developers Manual

DjNRO Release 0.9 July 14, 2015

Using Toaster in a Production Environment

Creating a generic user-password application profile

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

BASICS OF WEB DESIGN CHAPTER 2 HTML BASICS KEY CONCEPTS COPYRIGHT 2013 TERRY ANN MORRIS, ED.D

Webapps Vulnerability Report

Integrity Checking and Monitoring of Files on the CASTOR Disk Servers

TrendWorX32 SQL Query Engine V9.2 Beta III

Django-nonrel Documentation

Nginx 1 Web Server Implementation

STeP-IN SUMMIT June 2014 at Bangalore, Hyderabad, Pune - INDIA. Mobile Performance Testing

Configuring the LCDS Load Test Tool

There are numerous ways to access monitors:

4x High Performance for Drupal. Presented by Fabian Franz. Step by Step

Introduction to Ingeniux Forms Builder. 90 minute Course CMSFB-V6 P

MASTERTAG DEVELOPER GUIDE

Monthly Payroll to Finance Reconciliation Report: Access and Instructions

How to Make the Client IP Address Available to the Back-end Server

Building Your First Drupal 8 Company Site

Installation Guide ARGUS Symphony 1.6 and Business App Toolkit. 6/13/ ARGUS Software, Inc.

Using Application Insights to Monitor your Applications

Safewhere*Identify 3.4. Release Notes

RTI v3.3 Lightweight Deep Diagnostics for LoadRunner

Altima Lookbook Free Extension v

Templates Improve Application Development

Developing ASP.NET MVC 4 Web Applications MOC 20486

How to move a SharePoint Server bit environment to a 64-bit environment on Windows Server 2008.

Juris and Juris Suite 2.5 Service Pack 2. Installation Guide

Django Assess Managed Nicely Documentation

PHP on IBM i: What s New with Zend Server 5 for IBM i

Transcription:

Web Framework Performance Examples from Django and Rails QConSF 9th November 2012 www.flickr.com/photos/mugley/5013931959/

Me

Gareth Rushgrove

Curate devopsweekly.com

Blog at morethanseven.net

Text Work at UK Government Digital Service

I am a Civil Servant http://www.flickr.com/photos/benterrett/6852348725/

Developer, Operations, Product Guy

Introduction (what s the problem) http://www.flickr.com/photos/iancarroll/5027441664

Slow(er) languages...

Slow(er) languages...

...don t mean slow applications

...don t have to mean slow applications

Frameworks can help

Frameworks can help

A real example

A sample application

49ms Before

6ms After

- Analyze your application - Know your framework - Cache everywhere - Instrument everything - Don t just think about development This presentation

Analyze (count everything) http://www.flickr.com/photos/iancarroll/5027441664

1. From the browser

YSlow

webpagetest.org

2. From the code

Django debug toolbar

Django debug toolbar

Django debug toolbar

Django debug toolbar

Profiling middleware

rack-mini-profiler

rack-mini-profiler details

Rack Insight

Rack Insight

Rails footnotes

New Relic development mode

3. Logs

Request log analyzer

Mean StdDev Min Max 95 %tile 0.16s 0.26s 0.01s 1.74s 0.01s-1.08s Request log analyzer details

Django timelog

Know your framework (use the parts you need) http://www.flickr.com/photos/iancarroll/5027441664

1. Disable what you don t need

require "rails/all" in config/application.rb Don t import rails

require "action_controller/railtie" require "rails/test_unit/railtie" require "sprockets/railtie" in config/application.rb Just the bits you need

MIDDLEWARE_CLASSES = ( 'django.middleware.common.commonmiddleware', 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', ) in settings.py Django middleware

INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', ) in settings.py Django installed apps

2. Know your ORM

Django select_related()

queryset = Release.objects.all() 11 SQL Queries N+1 problem

queryset = Release.objects.select_related() 1 SQL Query Joins to the rescue

Active Record Include

Release.all 11 SQL Queries N+1 problem

Release.includes(:app).all 1 SQL Query Joins to the rescue

<link href="/assets/application.css?body=1"... <link href="/assets/apps.css?body=1"... <link href="/assets/bootstrap_and_overrides.css?body=1"... <link href="/assets/releases.css?body=1"... <link href="/assets/sample.css?body=1"... <link href="/assets/scaffolds.css?body=1"... to this <link href="/assets/application.css"... 3. Asset compilation in HTML

h1 { padding-top: 40px; } /*! * Bootstrap v2.2.1 * * Copyright 2012 Twitter, Inc * Licensed under the Apache License v2.0 * http://www.apache.org/licenses/license-2.0 * * Designed and built with all the love in the world @twitter by @mdo and @fat. */ article, aside, details, figcaption, figure, footer, header, hgroup, nav, section { display: block; } to this h1{padding-top:40px} article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{displ ay:block} Asset compilation in CSS

# Enable the asset pipeline config.assets.enabled = true # Version of your assets config.assets.version = '1.0' in config/application.rb # compress assets config.assets.compress = true # Don t expands the lines which load the assets config.assets.debug = false in config/environments/production.rb Asset compilation configuration

4. Different runtimes

Different runtimes - JRuby

Different runtimes - PyPy

require 'test_helper' require 'rails/performance_test_help' class ReleaseTest < ActionDispatch::PerformanceTest self.profile_options = { :runs => 10, :metrics => [:wall_time]} def test_release_index get '/releases' end end in test/performance/releases_test.rb 5. Performance tests

rake test:benchmark Started ReleaseTest#test_release_index (110 ms warmup) wall_time: 6 ms Finished in 0.551815 seconds. 1 tests, 0 assertions, 0 failures, 0 errors, 0 skips Rails benchmarker

Cache (everything) http://www.flickr.com/photos/iancarroll/5027441664

1. Built-in caching support

Great documentation 1

Great documentation 2

2. ORM Caching

CACHES = { 'default' : dict( BACKEND = 'johnny.backends.memcached.memcachedcache' LOCATION = ['127.0.0.1:11211'], JOHNNY_CACHE = True, ) } MIDDLEWARE_CLASSES = ( 'johnny.middleware.localstoreclearmiddleware', 'johnny.middleware.querycachemiddleware', ) + MIDDLEWARE_CLASSES in test/performance/releases_test.rb Johnny Cache

First request 4 Queries

Subsequent requests 0 Queries

class Release < ActiveRecord::Base acts_as_cached after_save :expire_cache attr_accessible :app_id belongs_to :app def self.recent includes(:app).al end end Cache-fu

class Release < ActiveRecord::Base acts_as_cached after_save :expire_cache attr_accessible :app_id belongs_to :app def self.recent includes(:app).al end end Add cache behaviour

@releases = Release.cached(:recent) Get cached content

First request 2 Queries

Subsequent requests 0 Queries

http://www.mnot.net/cache_docs/ 3. HTTP is your friend

from django.views.decorators.cache import cache_control @cache_control(public=true, max_age=3600) HTTP headers

class ReleasesController < ApplicationController def index expires_in 60.minute, :public => true in app/controllers/releases_controller.rb HTTP headers

INSTALLED_APPS = INSTALLED_APPS + ( 'varnishapp', ) VARNISH_MANAGEMENT_ADDRS = ( 'localhost:6082', ) VARNISH_WATCHED_MODELS = ('app.release',) in settings.py django-varnish configuration

django-varnish admin

Instrument (monitor all the things) http://www.flickr.com/photos/iancarroll/5027441664

MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ( 'django_statsd.middleware.graphiterequesttimingmiddleware', 'django_statsd.middleware.graphitemiddleware', ) STATSD_PATCHES = [ 'django_statsd.patches.db', 'django_statsd.patches.cache', ] INSTALLED_APPS = INSTALLED_APPS + ( 'django_statsd', ) from settings.py django-statsd

django-statsd on debug toolbar

MIDDLEWARE_CLASSES = ( 'django_mmstats.middleware.mmstatsmiddleware', ) import stats MMSTATS_CLASS = stats.djangostats from settings.py from django_mmstats.base import BaseDjangoStats class DjangoStats(BaseDjangoStats): """Add mmstats fields here, just like Django models!""" from stats.py django-mmstats

mmash

librato-rails

Not just in development (measure in production) http://www.flickr.com/photos/iancarroll/5027441664

1. Logs (again)

Logster

Lograge

Started GET "/" for 127.0.0.1 at 2012-03-10 14:28:14 +0100 Processing by HomeController#index as HTML Rendered text template within layouts/application (0.0ms) Rendered layouts/_assets.html.erb (2.0ms) Rendered layouts/_top.html.erb (2.6ms) Rendered layouts/_about.html.erb (0.3ms) Rendered layouts/_google_analytics.html.erb (0.4ms) Completed 200 OK in 79ms (Views: 78.8ms ActiveRecord: 0.0ms) to this GET /jobs/833552.json format=json action=jobs#show status=200 duration=58.33 view=40.43 db=15.26 Lograge

Logstash

LOGRAGE %{WORD:method}%{SPACE}%{DATA}% {SPACE}action=%{WORD:controller}#% {WORD:action}%{SPACE}status=%{INT:status}% {SPACE}duration=%{NUMBER:duration}%{SPACE} view=%{number:view}(%{space}db=% {NUMBER:db})?%{GREEDYDATA} Logstash plus lograge

LOGRAGE %{WORD:method}%{SPACE}%{DATA}% {SPACE}action=%{WORD:controller}#% {WORD:action}%{SPACE}status=%{INT:status}% {SPACE}duration=%{NUMBER:duration}%{SPACE} view=%{number:view}(%{space}db=% {NUMBER:db})?%{GREEDYDATA} Rails performance data

output { statsd { host => "localhost" tags => [ "lograge" ] timing => [ "<%= @title %>.%{controller}.%{action}.% {method}.duration", "%{duration}" ] } statsd { host => localhost tags => [ "lograge" ] timing => [ "<%= @title %>.%{controller}.%{action}.% {method}.view", "%{view}" ] } } Output to statsd

2. Metrics

Ganglia

Graphite

Riemann

New Relic newrelic.com

Librato Metrics metrics.librato.com

Conclusions (if all you remember is) http://www.flickr.com/photos/iancarroll/5027441664

Tooling helps. A lot.

- A debug toolbar - Transparent caching support - Hooks for instrumentation - Configurable logging Your framework should have

If not... build them

Share everything

The End

www.flickr.com/photos/snugglepup/ Thanks for the amazing photos http://flickr.com/photos/psd/102332391/

Questions? http://flickr.com/photos/psd/102332391/