50
Jason Ragsdale Sr. Technical Yahoo Yahoo! Web Speed & Scalability Friday, November 12, 2010

Tulsa tech fest 2010 - web speed and scalability

Embed Size (px)

Citation preview

Page 1: Tulsa tech fest 2010  - web speed and scalability

Jason RagsdaleSr. Technical Yahoo

Yahoo!

Web Speed & Scalability

Friday, November 12, 2010

Page 2: Tulsa tech fest 2010  - web speed and scalability

• How to build a bigger, faster, and more reliable website

• You will learn the concepts of Speed and Scalability

• Specific Examples of Caching, Load Balancing and testing tools.

Introduction

Friday, November 12, 2010

Page 3: Tulsa tech fest 2010  - web speed and scalability

• What is Scalability?

• Avoiding Failure

• High Availability?!?!?

• Monitoring

• Release Cycles

• Fault Tolerance

• Load Balancing

• Static Content

• Caching

• Yslow & PageSpeed

Agenda

Friday, November 12, 2010

Page 4: Tulsa tech fest 2010  - web speed and scalability

• Horizontal Scalability

• Capacity can be increased just by adding more hardware/software

• Best solution

• Does not guarantee that you are safe

• Up (Vertical) Scalability

• Capacity can be increased by adding more Disk Storage, RAM , Processors

• Expensive

• Should only be used if Horizontal will not work for you

What is Scalability?

Friday, November 12, 2010

Page 5: Tulsa tech fest 2010  - web speed and scalability

• Capital investment will be made

• The system will be more complex

• Maintenance costs will increase

• Time will be required to act

Scalability Considerations

Friday, November 12, 2010

Page 6: Tulsa tech fest 2010  - web speed and scalability

• Good Planning

• Have a plan for whatever you are about to do to your system, and most importantly, have a roll-back plan if and when things do not work the way you expected.

Avoiding Failure

Friday, November 12, 2010

Page 7: Tulsa tech fest 2010  - web speed and scalability

• Functional and Unit Testing

• Automated test do not catch everything that can go wrong, but they are very good at catching bugs introduced by changes elsewhere in your code base

• Unit Testing (PHPUnit, Simpletest)

• Function Testing (selenium)

Avoiding Failure

Friday, November 12, 2010

Page 8: Tulsa tech fest 2010  - web speed and scalability

• Control Change (Version Control)

• USE IT!!!! There is no better way even as a single developer to keep your codebase safe from bad changes

Avoiding Failure

Friday, November 12, 2010

Page 9: Tulsa tech fest 2010  - web speed and scalability

• /trunk/

• Used for all mainline development

• /branches

• Used to do development that needs to be separate from the trunk code

• /tags/

• Holds copies of production ready code

• Do not use Version Control as a backup solution, backup your VCS separately

Version Control in Action

Friday, November 12, 2010

Page 10: Tulsa tech fest 2010  - web speed and scalability

• What is “five nines” 99.999%?

• Do the math, 60 seconds * 60 minutes * 24 hours * 365 days

• 31,536,000 seconds of uptime a year

• 99.999 * 31536000 = 315.36 seconds of downtime a year

High Availability?!?!?!

Friday, November 12, 2010

Page 11: Tulsa tech fest 2010  - web speed and scalability

• Understand the goodness of “Planned maintenance periods”

• There are things you will need to do to your systems on a periodic basis I.E. Database Cleanup, Disk Defrag, Software/Hardware Upgrades

High Availability?!?!?!

Friday, November 12, 2010

Page 12: Tulsa tech fest 2010  - web speed and scalability

• You can stagger your maintenance periods if you have enough servers so you have no customer downtime, just a reduction in capacity

High Availability?!?!?!

Friday, November 12, 2010

Page 13: Tulsa tech fest 2010  - web speed and scalability

• No matter how stable your code is or how reliable your hardware, you will have failure

Monitoring

Friday, November 12, 2010

Page 14: Tulsa tech fest 2010  - web speed and scalability

• Top Down (Business Monitors)

• Monitor the application as the customer interacts with it

Monitoring Methods

Friday, November 12, 2010

Page 15: Tulsa tech fest 2010  - web speed and scalability

Monitoring Methods

• Bottom Up (System Monitors)

• Most commonly used

• Monitors the base components of your application like

• Disk Space

• Network speed

• Database Statistics

• By no means bad, but without Business Monitoring you will not be able to catch all failures

Friday, November 12, 2010

Page 16: Tulsa tech fest 2010  - web speed and scalability

• SNMP Support

• Can support most systems out there

• Extensibility

• Ability to plugin custom monitoring packages

• Flexible notifications

• Handle notifying operators and escalating issues if they are not looked into

• Custom reaction

• In the event of errors that can not be diagnosed by computers, need to be able to notify a human to do further investigation

Criteria For A Monitoring System

Friday, November 12, 2010

Page 17: Tulsa tech fest 2010  - web speed and scalability

• Complex scheduling

• Ability to set the monitoring frequency and timing per monitoring item

• Maintenance scheduling

• Monitors should never be taken offline, they need to be smart enough to know when a maintenance period is in effect

• Event acknowledgment

• Ability to understand when a event needs to be paged to a human at 2am, and when it shouldn't

• Service dependencies

• You need to monitor all points between your monitoring system and the client. This includes Firewalls, Routers, Switches

Criteria For A Monitoring System

Friday, November 12, 2010

Page 18: Tulsa tech fest 2010  - web speed and scalability

• Basic Release Cycle

• Development

• Things are expected to break

• Staging

• QA and bug fixing a build before release

• Production

• Only serious bug fixes are pushed

Release Cycles

Friday, November 12, 2010

Page 19: Tulsa tech fest 2010  - web speed and scalability

• Keep in mind that reality has priority over “Best Practice”

• You can and will have to release from development… it happens

Release Cycles

Friday, November 12, 2010

Page 20: Tulsa tech fest 2010  - web speed and scalability

router

switch

www-1-1 www-1-2

Intertubes

router

switch

www-1-1 www-1-2

Intertubes

router

switch

Fault Tolerance

Friday, November 12, 2010

Page 21: Tulsa tech fest 2010  - web speed and scalability

• Load Balancing is NOT HA

• Balancing is meant to spread the workload of requests across the cluster

Load Balancing

Friday, November 12, 2010

Page 22: Tulsa tech fest 2010  - web speed and scalability

• Round robin

• One request per server in a uniform rotation

Balancing Approaches

Friday, November 12, 2010

Page 23: Tulsa tech fest 2010  - web speed and scalability

• Least connections

• The faster the machine processes requests the more it will receive

Balancing Approaches

Friday, November 12, 2010

Page 24: Tulsa tech fest 2010  - web speed and scalability

• Predictive

• Usually based on Round robin or Least connections with some custom code

Balancing Approaches

Friday, November 12, 2010

Page 25: Tulsa tech fest 2010  - web speed and scalability

• Available resources

• Not a good choice, bad performance

Balancing Approaches

Friday, November 12, 2010

Page 26: Tulsa tech fest 2010  - web speed and scalability

• Random

• Pure random distribution of requests

• Weighted random

• Random with a preference to specific machines

Balancing Approaches

Friday, November 12, 2010

Page 27: Tulsa tech fest 2010  - web speed and scalability

• Static content examples

• Images

• CSS

• JS

• Any non dynamic element

Static Content

Friday, November 12, 2010

Page 28: Tulsa tech fest 2010  - web speed and scalability

• Serving these items from a dedicated server fees up your web process for actual dynamic code, intern increasing your capacity and response speed

• On you static server you can use lightHTTP, which is very quick at serving static content compared to apache (Although apache 2.2.x is much better than 1.3.x)

Static Content

Friday, November 12, 2010

Page 29: Tulsa tech fest 2010  - web speed and scalability

• Layered / Transport Cache

• “Transparent”

• Placed in-front of your hardware and caches requests before they hit your webserver

Types of Caching

Friday, November 12, 2010

Page 30: Tulsa tech fest 2010  - web speed and scalability

• Integrated (Look-Aside) Cache

• Computational Reuse technique

• Used where the cost of storing the results of a computation and later finding them again is less expensive than performing the computation again

Types of Caching

Friday, November 12, 2010

Page 31: Tulsa tech fest 2010  - web speed and scalability

• Write-Thru Caches

• Application is responsible for updating the Cache and Datastore when changes are made

• Write-Back Caches

• All data changes are made to the cache

• Cache layer is responsible for modifying the backend datastore

Types of Caching

Friday, November 12, 2010

Page 32: Tulsa tech fest 2010  - web speed and scalability

• Distributed Cache

• Using several machines to cache data, distributing the data and load

• Memcached can do this very simply

Types of Caching

Friday, November 12, 2010

Page 33: Tulsa tech fest 2010  - web speed and scalability

• It is a high-performance, distributed object caching system

Memcahed

Friday, November 12, 2010

Page 34: Tulsa tech fest 2010  - web speed and scalability

• It is simple to setup and use

• # ./memcached -d -m 2048 -l 10.0.0.40 -p 11211

Memcahed

Friday, November 12, 2010

Page 35: Tulsa tech fest 2010  - web speed and scalability

• It is not designed to be redundant

• If you loose data you memcache will repopulate the data as it is accessed

Memcahed

Friday, November 12, 2010

Page 36: Tulsa tech fest 2010  - web speed and scalability

• It provides no security to your cache

• “Memcached is the soft, doughy underbelly of your application. Part of what makes the clients and server lightweight is the complete lack of authentication. New connections are fast, and server configuration is nonexistent. If you wish to restrict access, you may use a firewall, or have memcached listen via unix domain sockets.”

Memcahed

Friday, November 12, 2010

Page 37: Tulsa tech fest 2010  - web speed and scalability

• Alternative PHP Cache

• The Alternative PHP Cache (APC) is a free and open opcode cache for PHP. It was conceived of to provide a free, open, and robust framework for caching and optimizing PHP intermediate code.

• Just enabling APC will transparently cache your code as you use it, no code changes required on your side

• Provides a cheap caching layer that can be shared on a between all apache processes on one machine

APC and why it’s your friend

Friday, November 12, 2010

Page 38: Tulsa tech fest 2010  - web speed and scalability

• Based on 13 principles from http://developer.yahoo.com/performance/rules.html

• 1.) Make fewer HTTP requests

• 80% of the end-user response time is spent on the front-end. Most of this

YSlow

Friday, November 12, 2010

Page 40: Tulsa tech fest 2010  - web speed and scalability

• Make fewer HTTP requests

• Use a CDN

• Add an Expires header

• Gzip components

YSlow

Friday, November 12, 2010

Page 41: Tulsa tech fest 2010  - web speed and scalability

• Put CSS at the top

• Put JS at the bottom

• Avoid CSS expressions

• Make JS and CSS External

YSlow

Friday, November 12, 2010

Page 42: Tulsa tech fest 2010  - web speed and scalability

• Reduce DNS lookups

• Minify JS

• Avoid redirects

• Remove duplicate scripts

• Configure Etags

• Make AJAX cachable

YSlow

Friday, November 12, 2010

Page 43: Tulsa tech fest 2010  - web speed and scalability

• http://code.google.com/speed/page-speed

• The Page Speed family consists of several products. Web developers can use the Page Speed extension for Firefox/Firebug to analyze performance issues while developing web pages. Apache web hosters can use mod_pagespeed, a module for the Apache™ HTTP Server that automatically optimizes web pages and their resources at serving time.

PageSpeed

Friday, November 12, 2010

Page 44: Tulsa tech fest 2010  - web speed and scalability

• Adds client-side latency instrumentation.

• Improves cacheability.

• Removes unnecessary whitespace in HTML.

• Combines multiple <head> elements & CSS files into one.

• Moves CSS into the <head> element.

• Removes unnecessary attributes in HTML tags.

• Inlines small external CSS & Javascript files.

mod_page_speed

Friday, November 12, 2010

Page 45: Tulsa tech fest 2010  - web speed and scalability

• Moves large inline <style> & <script> tags into external files for cacheability.

• Removes unnecessary quotes in HTML tags.

• Removes HTML comments.

• Minifies CSS.

• Rescales, and compresses images; inlines small ones.

• Minifies Javascript.

mod_page_speed

Friday, November 12, 2010

Page 46: Tulsa tech fest 2010  - web speed and scalability

# enable expirationsExpiresActive On# expire GIF images after a month in the client's cacheExpiresByType image/gif A2592000ExpiresByType image/jpeg A2592000ExpiresByType text/css A2592000ExpiresByType application/x-javascript A2592000

# disable ETagsFileETag None

Example apache 2.x performance config

Friday, November 12, 2010

Page 47: Tulsa tech fest 2010  - web speed and scalability

# Gzip Compression

# Insert filterSetOutputFilter DEFLATE

# Netscape 4.x has some problems...BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problemsBrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fineBrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48# the above regex won't work. You can use the following# workaround to get the desired effect:BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress imagesSetEnvIfNoCase Request_URI \\.(?:gif|jpe?g|png|mp3)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong contentHeader append Vary User-Agent env=!dont-vary

Example apache 2.x performance config

Friday, November 12, 2010

Page 48: Tulsa tech fest 2010  - web speed and scalability

Questions?

Friday, November 12, 2010

Page 49: Tulsa tech fest 2010  - web speed and scalability

• YSlow: http://developer.yahoo.com/yslow/

• Rules: http://developer.yahoo.com/performance/rules.html

• Scalable Internet Architectures

• By Theo Schlossnagle

• APC: http://us3.php.net/apc

• Memcahed: http://www.danga.com/memcached/

• Selenium: http://www.openqa.org/selenium/

• Simpletest: http://simpletest.org/

• PHPUnit: http://www.phpunit.de/

Links & Information

Friday, November 12, 2010

Page 50: Tulsa tech fest 2010  - web speed and scalability

• http://joind.in/talk/view/2355

Please Complete An Evaluation Form

Friday, November 12, 2010