why memcached?

36
Why Memcached? Presented by: Bill Takacs – Director, Product Management September 2009

Upload: gear6

Post on 16-Apr-2017

17.487 views

Category:

Technology


0 download

TRANSCRIPT

Why Memcached?

Presented by:

Bill Takacs – Director, Product Management

September 2009

Agenda

Ri f th d i b• Rise of the dynamic web

• Memcached

• The web architecture

• The evolution of a dynamic site and Memcached

• Gear6 solution

2 : Copyright 2009 Gear6 Inc.

The Web: What’s Changed?

• Population

• Traffic

• Content and applications

3 : Copyright 2009 Gear6 Inc.

Web Growth: Population

Forrester: 2 2 billion people online globally by 2013Forrester: 2.2 billion people online globally by 2013

4 : Copyright 2009 Gear6 Inc.

Web Growth: Traffic

Cisco: “Annual global IP trafficCisco: Annual global IP trafficwill exceed two-thirds of a zettabyte

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

Source: Cisco Visual Networking Index,9 June 2009

5 : Copyright 2009 Gear6 Inc.

Web Growth: Application & Content

EntertainmentEntertainment

Social networking

Media

CommunicationDynamicDynamicDynamicDynamicStaticStaticStaticStatic

Communication

Community-generated content

6 : Copyright 2009 Gear6 Inc.

But growth can beGrowth can be painful

But growth can be

painful(VERY)

painful

Web Architecture

➜ Most sites (over 65%) based on LAMP or JAVA ( )➜ Industry standard servers replaced proprietary SMP➜ Shift to dynamic content puts strain on origin sites

NetInterface

Web Stack

ClientsInternet

StorageInterface

WSe

ApacLASe

PHP, JPer

DaM

Pos

StoraStora

file, file,

StoraStora

file, file,

CDNProxy

Load

Web

erversche, N

ginx, Lighttpd

App

erversava, R

ails, Crl, Python

tabaseM

ySQL,

stgreSQL

age Interfacage Interfacblock, FC

, SCS

block, FC, SC

Sage Interfacage Interfacblock, FC

, SCS

block, FC, SC

S LoadBalancer

C,

ce:ce:SISIce:ce:SISI

8 : Copyright 2009 Gear6 Inc.

What to do?

9 : Copyright 2009 Gear6 Inc.

New Caching Architecturefor Scaling Out for Scaling Out

W b S k

ClientsStorage

NetInterface

Web Stack

CDN

InternetStorage

Proxy

Web

ServeA

pache, NLighttp

App

ServePH

P, Java, RPerl, Pyt

Databa

MySQ

PostgreS

Storage IStorage I

file, block, file, block,

Storage IStorage I

file, block, file, block, CDN

LoadBalancer

b ersN

ginx, pd

p ersR

ails, C,

thon

aseL, SQ

L

nterface:nterface:FC

, SCSI

FC, SC

SInterface:nterface:FC

, SCSI

FC, SC

SI

Cache ServersMemcached

10 : Copyright 2009 Gear6 Inc.

Memcached: Pillar of Web 2.0 Architecture

“Everything runs“Everything runs“Everything runsfrom memory

“Everything runsfrom memoryfrom memoryin Web 2.0”

from memoryin Web 2.0”

Evan Weaver, Twitter, March 2009Evan Weaver, Twitter, March 2009

11 : Copyright 2009 Gear6 Inc.

The Fix: Memcached

“A high performance, distributed memory object caching g p , y j gsystem, generic in nature, but intended for use in

speeding up dynamic web applications by alleviating database load”database load”

Ref: http://www.danga.com/memcached/

• Big hash table

• Created by Danga Interactive for LiveJournal

• Significantly reduced database load

• Perfect for web sites with high database loadPerfect for web sites with high database load

• In use by Facebook, Twitter, myYearbook, others

12 : Copyright 2009 Gear6 Inc.

More on Memcached

• Takes advantage of available DRAMTakes advantage of available DRAM

• Open sourceOpe sou ce

• Distributed under BSD license

• Server - Current version is 1.2.8» http://www.danga.com/memcached/download.bml

M li t• Many clients» http://code.google.com/p/memcached/wiki/Clients

13 : Copyright 2009 Gear6 Inc.

Why Memcached with MySQL?

• Scale-out of dynamic web sitesy

• Page loads

• Efficient resource utilization

• Support for dozensto hundreds of nodes

• Open source

14 : Copyright 2009 Gear6 Inc.

How Does Memcached Work?

• Client - Server

H h F ti• Hash Function

• Memcached• Memcached» Two stage

15 : Copyright 2009 Gear6 Inc.

Memcached Server

• Slab allocator

• Libevent based

• Simple Protocol (no XML)

• Server has internal hash table

• Servers are dumb – they don’t know about each other

16 : Copyright 2009 Gear6 Inc.

Memcached Server

• LimitsLimits» Key size = (250 bytes)» 1MB Limit » 32bit/64bit (maximum size of process)

• LRU» Least recently accessed

items are cycled out» One LRU exists per “slab class”» One LRU exists per slab class» LRU “evictions” need not

be common• Threads? Yes

17 : Copyright 2009 Gear6 Inc.

Memcached Clients

• Client hashes key to server listClient hashes key to server list

• Serializes the objectSe a es t e object

• Many client librariesy

• Authentication

18 : Copyright 2009 Gear6 Inc.

What about…..

• Redundancy• Redundancy

• Failover• Failover

19 : Copyright 2009 Gear6 Inc.

Consistent Hashing

• Why?

• How does it work?

20 : Copyright 2009 Gear6 Inc.

Commands

• Storage commands:» Set / Add / Replace /

Append / Prepend / CASAppend / Prepend / CAS

• Retrieval commands:» Get / Gets

• Delete / increment / decrement

• Stats

21 : Copyright 2009 Gear6 Inc.

Memcached UDFs for MySQL

• Suite of functions thatwork with Memcachedand MySQLand MySQL

• Leverage power ofLeverage power ofSQL Engine

• Combine tasksmySQL

• Open source

application

22 : Copyright 2009 Gear6 Inc.

pp

Putting it all together

Client-1 Client-2 Client-3Client 1 Client 2 Client 3

C

Server X Server Y Server Z

Key = value

23 : Copyright 2009 Gear6 Inc.

yFoo = seattle

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

Event: Site has growth inEvent: Site has growth in number of users, sessions,

page views and apps, causing excessive read load on DB

Action: Replicate database(and/or add more app servers)

excessive read load on DB

App ServerApp Server App ServerApp Server App ServerApp Server App ServerApp Server App ServerApp Server App ServerApp Server

App ServerApp Server App ServerApp Server App ServerApp Server

readread

write

writewrite

MySQLMySQL

readread

MySQLMySQLreadread

MySQLMySQLreadread

24 : Copyright 2009 Gear6 Inc.

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

Event: Individual caches on the Action: Add memcached server

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 databasedeterministic content access even fewer reads to database

App ServerApp Server App ServerApp Server App ServerApp Server

App ServerApp Server App ServerApp Server App ServerApp Server

App ServerApp Server App ServerApp Server App ServerApp Server

App ServerApp Server App ServerApp Server App ServerApp Servermemcached memcached memcached

memcached memcached memcached

itit itit

MySQLMySQLreadreadwrite

MySQLMySQLreadreadwrite …

MySQLMySQLreadread

write

MySQLMySQLreadread

write …

25 : Copyright 2009 Gear6 Inc.

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

Event: Memcached needsEvent: Memcached needsmore memory resources than

what are available on other (shared) servers

Action: Move Memcached servers to dedicated servers

(shared) servers

App ServerApp Server App ServerApp Server App ServerApp Server

App ServerApp Server App ServerApp Server App ServerApp Server

App ServerApp Server App ServerApp Server App ServerApp Server

App ServerApp Server App ServerApp Server App ServerApp Servermemcached memcached memcached

memcached memcached memcached

…memcached memcached memcached

MySQLMySQL MySQLMySQL

write

MySQLMySQL

writewrite

MySQLMySQL

write …readreadreadreadreadreadreadread

26 : Copyright 2009 Gear6 Inc.

What Memcached is NOT:

A persistent data storeA persistent data store

A database

Application-specific

A large object cache

Fault-tolerant or highly available

27 : Copyright 2009 Gear6 Inc.

Memcached: Best Practices

• Use with MySQL :-)y Q )

• Use on 64-bit servers

• Cache “expensiveoperations”

• Cache bi-directionally(read/write)( )

• Design to withstandfailures gracefullyfailures gracefully

• Use consistent hashing

28 : Copyright 2009 Gear6 Inc.

Memcached: Best Practices (cont’d)

• Careful with numbers of connectionsCareful with numbers of connections» Peak» Transitions

• Evictions» Segment Memcached data into separate pools

O ti i i i i t d l• Optimize sizing: instances and pools

Instrumentation• Instrumentation

29 : Copyright 2009 Gear6 Inc.

Memcache Use Cases

Site Type Repeatable Use

Social networking Profile caching

Content aggregation HTML/page caching

Ad targeting Cookie/profile trackingAd targeting Cookie/profile tracking

Gaming and entertainment Session caching

Location-based services DB query scaling

R l ti hi S i hiRelationship Session caching

E-commerce Session and HTML caching

30 : Copyright 2009 Gear6 Inc.

Use Case Example:Session ManagementSession Management

• 4m+ daily visitors

• 15k hits/secWeb ServersWeb Servers

• 6k updates/sec

Tens of thousands ofSS • Tens of thousands of concurrent connections

S i t k d d d

Application Application Servers withServers withMemcached ClientsMemcached Clients

• Session tracked and ads are placed in accordance to session

Memcached ServersMemcached Servers

MySQLMySQL ServersServers

31 : Copyright 2009 Gear6 Inc.

Useful Memcached Tools

advanced reporterp

wireshark

Track hot keys and clients in Memcached

wireshark

brutisDissect and analyze Memcached network traffic

brutisSize and test changes to memcache clusters

statsproxyView buffered Memcached stats in your browser

cactiGraph and analyze Memcached statistics

32 : Copyright 2009 Gear6 Inc.

Statsproxy + Cacti Templates

To use the cacti templates for memcached withmemcached with statsproxy, you either need to modify the templates to usetemplates to use port 8080 or change the statsproxy config to use port 11211use port 11211

33 : Copyright 2009 Gear6 Inc.

About Gear6

• First and leading providerof Memcached solutions

• Memcached solution including

• High densityHigh density

• High availability

• Advanced memory• Advanced memorymanagement

• Enhanced reportingbiliticapabilities

• Support for multi-tenancy

• Disruption freesoftware upgrades

• 100% client compatible

34 : Copyright 2009 Gear6 Inc.

00% c e t co pat b e

Questions?

Thank you for attending our webinarThank you for attending our webinar“Why Memcached”

Bill TakacsBill TakacsGear6Gear6Gear6Gear6

[email protected]@gear6.com+1 650 587 7118+1 650 587 7118

and please visit our web site at:

www.gear6.comwww.gear6.comand please visit our web site at:

35 : 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

36 : Copyright 2009 Gear6 Inc.

• http://bazaar.launchpad.net/~libmemcached-developers/libmemcached/trunk/revision/539