aws webcast - accelerating application performance using in-memory caching in aws

39
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. Accelerating Application Performance Using In-Memory Caching in AWS Omer Zaki ([email protected]) Shakil Langha ([email protected])

Upload: amazon-web-services

Post on 13-Jan-2015

1.371 views

Category:

Technology


0 download

DESCRIPTION

This webinar covers both introductory as well as advanced topics related to ElastiCache and is intended for current memcached users as well as those already using ElastiCache. During this session we will go over various scenarios and use-cases that can benefit by enabling caching, discuss the features provided by ElastiCache, and review best-practices, design patterns, and anti-patterns related to ElastiCache. The webinar will also include a demo where we enable ElastiCache for a web application and show the resulting performance improvements.

TRANSCRIPT

Page 1: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Accelerating Application Performance

Using In-Memory Caching in AWS

Omer Zaki ([email protected])

Shakil Langha ([email protected])

Page 2: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Agenda

Caching Overview

Memcached

Amazon ElastiCache

Use Cases & Design Patterns

Demo

Page 3: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

A Typical Web Application

Web

Server

DB

Server

Users

Web Server

Database Server

Page 4: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

A Typical Web Application

Web

Server

DB

Server

Step 1: Users hit your web app

Page 5: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

A Typical Web Application

Web

Server

DB

Server

Step 1: Users hit your web app

Step 2: The Web App queries the Database

Page 6: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

A Typical Web Application

Web

Server

DB

Server

Step 1: Users hit your web app

Step 2: The Web App queries the Database

Step 3: The Database returns the Result

Page 7: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

A Typical Web Application

Web

Server

DB

Server

Step 1: Users hit your web app

Step 2: The Web App queries the Database

Step 3: The Database returns the Result

Step 4: The Web App returns the Page

Page 8: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

A Typical Web Application

Web

Server

DB

Server

Step 5: You scale Web and Database Servers

Web

Server

DB

Server

Web

Server

DB

Server

Page 9: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

A Typical Web Application

Web

Server

DB

Server

Step 5: You scale Web and Database Servers

Step 6: Now What?

Web

Server

DB

Server

Web

Server

DB

Server

Page 10: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

A Typical Web Application

Web

Server

DB

Server

Step 5: You scale Web and Database Servers

Step 6: Now What?

Step 7: Use a Cache

Web

Server

Web

Server

DB

Server

Cache

Page 11: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

What is a Cache?

Component that stores frequently accessed data in memory

Requests for data in the cache are returned faster

Benefits:

• Faster responses for cached data

• Reduces load on your database

Page 12: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Why Use a Cache?

For a majority of web applications, workloads are read heavy • Often as high as 80-90% reads vs. writes

Memory is orders of magnitude faster than disk • Latency can be reduced from milliseconds to microseconds

Page 13: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Caching: An Example

Example: Get John Smith’s Phone Number

First Time:

Cache = {}

Step 1: Look in the cache. It’s empty; ‘cache miss’

Step 2: Get the value from the DB; update the cache

Page 14: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Caching: An Example

Example: Get John Smith’s Phone Number

Second Time:

Cache = {‘John Smith’ : ‘206-555-1212’}

Step 1: Look in the cache. Return the result; ‘cache hit’

Step 2: Until John’s number changes, we don’t hit the DB

Page 15: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Caching: An Example

Example: John gets a new phone number – ‘415-555-1212’

Cache Invalidation:

Cache = {‘John Smith’ : ‘206-555-1212’} (out of date)

Step 1: Update Database with John’s new number

Step 2: Update the cache with John’s new number

Cache = {‘John Smith’ : ‘415-555-1212’}

Page 16: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Caching: Pros & Cons

Pros • Speed up applications, especially if they are read-intensive

• Reduce load on your database servers

Cons • Requires a change in application architecture

• Application needs to ensure data in the cache is current

Page 17: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Agenda

Caching Overview

Memcached

Amazon ElastiCache

Use Cases & Design Patterns

Demo

Page 18: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Memcached: Overview

Memcached (read: mem-cache-dee)

Free, open-source, high-performance, in-memory key value store

Developed for LiveJournal in 2003

Used by many of the worlds top websites:

• YouTube, Facebook, Twitter, Pinterest, Tumblr, …

Page 19: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Memcached: Architecture

Servers with key-value associative

arrays

Client software populates the array

and queries it

Clients know about all the servers

Servers don’t communicate with

each other

Least Recently Used

No persistence

Source: http://architects.dzone.com/news/notes-memcached

Page 20: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Memcached: Storing Data

Stores arbitrary data • HTML snippets

• Database query results

• Computed results

Keys are limited to 250 bytes

Values are limited to 1Mb

Page 21: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Agenda

Caching Overview

Memcached

Amazon ElastiCache

Use Cases & Design Patterns

Demo

Page 22: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Amazon ElastiCache Web service that lets you easily create and use cache clusters in the cloud

100% Memcached compatible

Managed, scalable, secure

Pay-as-you-go, and flexible, so you can add capacity when you need it

Page 23: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Amazon ElastiCache: Benefits

Easy to Deploy

Deploy multi-node cache

clusters with a few button

clicks or API calls

Easy to Migrate

100% Memcached compatible

Existing code will work when

you update server lists

Easy to Administer

Automatically replaces failed

nodes and patches software

CloudWatch enables you to monitor cache performance

metrics

Easy to Scale

Add or remove cache nodes

with a few button clicks, or API calls

Easy to Secure

Works well with EC2 and DB Security

groups which means the cache is secure

Page 24: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Agenda

Caching Overview

Memcached

Amazon ElastiCache

Use Cases & Design Patterns

Demo

Page 25: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Common Use Cases

Social networks

Gaming

Media and News Sites

Q&A Portals

E-Commerce

Recommendation Engines

Mobile app back-ends

Page 26: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Sample Deployment: Gaming

Auto-scaling front end

Amazon ElastiCache

Amazon RDS

Amazon S3

Amazon CloudFront

Page 27: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Common Design Patterns

Database offloading

• Allows web apps to scale independent of backend data tier

Session management for transient data

• Increment/decrement high scores for gaming environments

In memory storage for difficult / time consuming tasks

• Picture ids for all pictures tagged with a particular keyword

Page 28: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Anti-Patterns Build application logic assuming cache

hit latency

Put objects into cache without Time-

To-Live set (TTL)

Sequentially sending single operations

to cache (avoiding usage of batched

operations)

Configuring Memcached client to use

Redistribute Failure mode for

ElastiCache cache nodes

Resolving DNS only once.

Failing application request for cache

miss.

Using Memcached as a durable store.

Not designing application error paths

regarding cache operations

• Connection timeouts, operation

timeouts, etc.

Page 29: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Best Practices

Share Memcached Client objects in application

Use TTLs (short TTLs)

Consider Memory for Connections Overhead

Use CloudWatch Alarms / SNS Alerts

Use Consistent Hashing

Use Auto Discovery

Page 30: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Agenda

Caching Overview

Memcached

Amazon ElastiCache

Use Cases & Design Patterns

Demo

Page 31: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Adding Caching to a Web App

Existing Web App running in EC2

• Using RDS MySQL database

Steps

1. Create ElastiCache Cluster with 2 cache nodes

2. Modify the Web App to use Caching

Page 32: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Create Cache Cluster: Cluster Specification

Page 33: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Create Cache Cluster: Security / Parameters

Page 34: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Create Cache Cluster: Cluster Created

Page 35: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Modify Web App to use Caching

Initialization import memcache

CACHE_NODES = ['hostname1:port1',

'hostname2:port2']

mc = memcache.Client(CACHE_NODES)

Key Lookup KEY = "demo.key"

KEY_EXPIRY_SECONDS = 60

value = mc.get(key)

if (not value):

value = getDataFromExistingLogic()

#retrieve from existing app logic -

database, filesystem, other processing

mc.set(key, value, time =

KEY_EXPIRY_SECONDS)

return value

Page 36: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Web App with Caching

Page 37: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Performance Improvement

Performance run using Multi-Mechanize

• Runtime: 600 seconds

• Time-series interval: 5 seconds

• ElastiCache usage configured to start at 200 seconds mark

Page 38: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Performance Improvement

Page 39: AWS Webcast - Accelerating Application Performance Using In-Memory Caching in AWS

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Questions