Memcached and the Rise of the Dynamic Web

25
September 2009 Presented by: Bill Takacs – Director, Product Management

Transcript of Memcached and the Rise of the Dynamic Web

September 2009

Presented by:

Bill Takacs – Director, Product Management

2 : Copyright 2009 Gear6 Inc.

Agenda

•!Rise of the dynamic web!

•!The web architecture!

•!The evolution of a dynamic site and Memcached!

•!Gear6 solution!

3 : Copyright 2009 Gear6 Inc.

The Web: What’s Changed?

•!Population!

•!Tra"c!

•!Content and applications!

4 : Copyright 2009 Gear6 Inc.

Web Growth: Population

Forrester: 2.2 billion people online globally by 2013

5 : Copyright 2009 Gear6 Inc.

Web Growth: Traffic

Cisco: “Annual global IP traffic

will exceed two-thirds of a zettabyte

(667 exabytes) in four years” [by 2013]

Source: Cisco Visual Networking Index,

9 June 2009

6 : Copyright 2009 Gear6 Inc.

Web Growth: Application & Content

Entertainment!

Social Networking!

Media!

Communication!

Community-generated content!

Growth can be painful

(VERY)

But growth can be

painful

8 : Copyright 2009 Gear6 Inc.

Web Architecture

CDN!

Clients

Internet Storage

Net

Interface

Proxy

Load

Balancer

Web Stack

Web

Serv

ers#

Ap

ache, N

gin

x,

Lig

http

d!

Ap

p

Serv

ers!

PH

P, Ja

va, R

ails

, C,

Perl, P

yth

on!

Data

base!

MySQ

L,

Postg

reSQ

L !

!! Most sites (over 65%) based on LAMP or JAVA

!! Industry standard servers replaced proprietary SMP

!! Shift to Dynamic Content puts strain on origin sites

9 : Copyright 2009 Gear6 Inc.

What to do?

10 : Copyright 2009 Gear6 Inc.

New Caching Architecture for Scaling Out

CDN!

Clients

Internet Storage

Net

Interface

Proxy

Load

Balancer

Web Stack

Web

Serv

ers#

Ap

ache, N

gin

x,

Lig

http

d!

Ap

p

Serv

ers!

PH

P, Ja

va, R

ails

, C,

Perl, P

yth

on!

Data

base!

MySQ

L,

Postg

reSQ

L !

Cache Servers memcached

11 : Copyright 2009 Gear6 Inc.

Memcached: Pillar of Web 2.0 Architecture

“Everything runs #from memory#in Web 2.0”!

Evan Weaver, Twitter, March 2009!

12 : Copyright 2009 Gear6 Inc.

The Fix: Memcached

“A high performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by

alleviating database load”!

•!Big hash table!

•!Created by Danga Interactive for LiveJournal!

•!Significantly reduced database load!

•!Perfect for web sites with high database load!

•! In use by Facebook, Twitter, MyYearbook, others!

13 : Copyright 2009 Gear6 Inc.

Evolution of a Dynamic Site #1 A day in the life of a growing web service

•! Event: Site has growth in number of users/sessions/page views/apps causing excessive read load on DB!

•!Action: Replicate Database (and/or add more app servers)!

MySQL

App Server App Server App Server

write!

MySQL

App Server App Server App Server

write!

MySQL

write! …

App Server App Server App Server

14 : Copyright 2009 Gear6 Inc.

Evolution of a Dynamic Site #2 A day in the life of a growing web service

•! Event: Individual caches on the app/db servers are overwhelmed from chaotic/non-deterministic content access!

•!Action: Add memcached server on servers with underutilized memory resources… results in even fewer reads to database!

MySQL

App Server App Server App Server

write!

MySQL

write! …

App Server App Server App Server

MySQL

App Server App Server App Server

write!

MySQL

write! …

App Server App Server App Server memcached memcached memcached

memcached memcached memcached

15 : Copyright 2009 Gear6 Inc.

MySQL

Evolution of a Dynamic Site #3 A day in the life of a growing web service

•! Event: Memcached needs more memory resources than what is available on other (shared) servers!

•!Action: Move memcached servers to dedicated servers!

MySQL

App Server App Server App Server

write!

MySQL

write!

App Server App Server App Server

App Server App Server App Server

write!

MySQL

write! …

App Server App Server App Server memcached memcached memcached

memcached memcached

memcached memcached memcached

memcached

16 : Copyright 2009 Gear6 Inc.

What Memcached is NOT:

Fault-tolerant or highly available!

A large object cache!

Application-specific!

A database!

A persistent data store!

17 : Copyright 2009 Gear6 Inc.

Memcached: Best Practices

•!Use with MySQL :-)!

•!Use on 64-bit servers!

•!Cache “expensive operations”!

•!Cache bi-directionally (R/W)!

•!Design to withstand failures gracefully!

•!Use consistent hashing!

•!Careful with numbers of connections!

»!Peak!

»!Transitions!

•!Evictions!»!Segment Memcached

data into separate pools!

•!Optimize sizing: Instances and pools!

•!Instrumentation!

18 : Copyright 2009 Gear6 Inc.

Memcache Use Cases

Site Type Repeatable Use

Social networking Profile caching

Content aggregation HTML/page caching

Ad targeting Cookie/profile tracking

Gaming and entertainment Session caching

Location-based services DB query scaling

Relationship Session caching

E-commerce Session and HTML caching

19 : Copyright 2009 Gear6 Inc.

Use Case Example: Session Management

•!4m+ daily visitors!

•!15k hits/sec!

•!6k updates/sec!

•!Tens of thousands concurrent connections!

•!Session tracked and ads are placed in accordance to session!

20 : Copyright 2009 Gear6 Inc.

Hadoop!

Recommendations on

User webpages

Load Balancer Load Balancer

Load Balancer

Webserver / php

User Targeting Service

Thin/fast memcache

Client layer (reads)

Update processing

(writes)

User Targeting Service

Thin/fast memcache

Client layer (reads)

Update processing

(writes)

User Targeting Service

Thin/fast memcache

Client layer (reads)

Update processing

(writes)

Map/Reduce Jobs

Data processing

User profile updates

Ad-Hoc Analysis

Memcache repopulation

(bulk updates, recovery)

User targeting data

From logs and other

systems

“Lazy” Updates

Bulk/batch

updates

Use Case Example:

User Targeting Engine

Memcached pool!

Reports!

21 : Copyright 2009 Gear6 Inc.

Useful Memcached Tools

advanced reporter!

wireshark!

brutis!

statsproxy!

cacti!Graph and analyze Memcached statistics!

View bu$ered Memcached stats in your browser!

Size and test changes to memcache clusters!

Dissect and analyze Memcached network tra"c!

Track hot keys and clients in Memcached!

22 : Copyright 2009 Gear6 Inc.

Statsproxy + Cacti Templates

To use the cacti

templates for

memcached with statsproxy, you

either need to

modify the

templates to use

port 8080 or change the

statsproxy config to

use port 11211

23 : Copyright 2009 Gear6 Inc.

•! First and leading provider #of Memcached solutions!

•! Memcached solution including!

•! High density!

•! High Availability!

•! Advanced memory #management!

•! Enhanced reporting#capabilities !

•! Support for multi-tenancy!

•! Disruption free #software upgrades!

•! 100% client compatible!

24 : Copyright 2009 Gear6 Inc.

Questions?

Thank you for attending our webinar!

“Memcached and the Rise of the New Dynamic Web” !

www.gear6.com!and please visit our web site at:!

25 : Copyright 2009 Gear6 Inc.

References

•! Danga.com!

•! Highscalability.com!

•! Dev.gear6.com!

•! Groups.google.com/group/memcached!

•! Code.google.com/p/memcached!

•! Twitter.com/gearsix!

•! Cacti.net!

•! Wireshark.org!

•! http://dev.mysql.com/doc/mysql-ha-scalability/en/ha-memcached-

using-deployment.html!

•! http://dev.mysql.com/doc/mysql-ha-scalability/en/ha-memcached-using-hashtypes.html!

•! http://jayant7k.blogspot.com/2009/04/memcached-replication.html!

•! http://www.lexemetech.com/2007/11/consistent-hashing.html!

•! http://www8.org/w8-papers/2a-webserver/caching/paper2.htmlhttp://www.last.fm/user/RJ/journal/2007/04/10/rz_libketama_-_a_consistent_hashing_algo_for_memcache_clients!

•! http://bazaar.launchpad.net/~libmemcached-developers/libmemcached/

trunk/revision/539!