Caching in Windows Azure

49
Ido Flatow Senior Architect Microsoft MVP SELA Group Caching in Azure More than Just Azure Caching @idoFLATOW http://bit.ly/flatow- blog This presentation: http://sdrv.ms/ 17s8osK

description

Examining caching solutions that you can use in Windows Azure, such as the Windows Azure Cache service, In-role cache, Memcached, Redis, and Couchbase. The presentation shows the different features of each caching solution, pros and cons, deployment strategies, and deployment steps.

Transcript of Caching in Windows Azure

Page 1: Caching in Windows Azure

Ido FlatowSenior Architect

Microsoft MVPSELA Group

Caching in AzureMore than Just Azure Caching

@idoFLATOWhttp://bit.ly/flatow-blog

This presentation:http://sdrv.ms/

17s8osK

Page 2: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

2

THE WORLD BEFOREDISTRIBUTED CACHE

Page 3: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

Page 4: Caching in Windows Azure

Ido FlatowSenior Architect

Microsoft MVPSELA Group

Caching in AzureMore than just Azure Caching

@idoFLATOWhttp://bit.ly/flatow-blog

This presentation:http://sdrv.ms/

15QPjke

Page 5: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

5

WHAT WE ARE GOING TO SEE

Different caching solutions Different deployment strategies For each solution

General features, pros/cons

Windows Azure deployment steps

C# API and benchmarks

Page 6: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

6

CACHING 101

Why do we cache? Scale-out our applications

Decrease load on database

Store data close to the application

Speed up data access

Page 7: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

8

CACHING 101

What is expected of a cache? Key/value CRUD

Store any entity type (no special attributes)

LRU / absolute / sliding evictions

Concurrent access

Cache per application (multitenant)

Secured transport

Page 8: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

9

CACHING 101

What would also be great? Bulk operations

Enumeration and queries

Clustering and replication for high-availability

Change notifications

Transactions

Data persistence

Management API

Page 9: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

10

CACHING SOLUTIONS

Memcached

Coherence

Couchbase

Redis

SharedCache

AppFabric

NCache

StateServer

In-memory key-value store for on-premises and Windows Azure

In-memory key-value store

Key-value store, Data structure server

NoSQL document database

Page 10: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

11

WINDOWS AZURE COMPONENTS

Windows Azure PaaS components Storage, database, caching

Cloud Services Web role, worker role

Virtual Machines OS images, virtual hard disks

Virtual Networks Subnets, VPN

Page 11: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

12

WINDOWS AZURE CACHE SERVICECache-as-a-Service

Page 12: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

13

WINDOWS AZURE CACHE SERVICE Store any Data-Contract serializable objects Item eviction (LRU, absolute, and sliding) Item locking Local cache for re-fetching Group items to regions

Bulk get/delete

Simple tag-based queries

Offering-dependent features: Standard - Separate cache per application

Premium - Notifications for region and item changes

Includes providers for ASP.NET session state and output cache

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 13: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

14

WINDOWS AZURE CACHE SERVICE

Pros Cache-as-a-Service, no installation required

Available from everywhere

Supports high-availability (premium offering)

Secured (transport + authentication)

Cons Billed by cache size

Not available in all US data centers

Still in preview (for now)

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 14: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

WINDOWS AZURE CACHE SERVICE

15

Cache Service

Virtual Machine

WebSite

CloudService

On-premises

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 15: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

16

WINDOWS AZURE CACHE SERVICE

Create the cache service in the portal Cache size

Region

Add the Windows Azure Caching NuGet package to your application

Configure host name and security key

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 16: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

17

WINDOWS AZURE CACHE SERVICEBenchmark

Page 17: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

18

WINDOWS AZURE IN-ROLE CACHEDistributed cache agent for cloud services

Page 18: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

19

WINDOWS AZURE IN-ROLE CACHE

Same features as cache service Separate caches per-application

Expiration and eviction

Local cache

Notifications

Regions and tagging

Cache provider for ASP.NET

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 19: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

20

WINDOWS AZURE IN-ROLE CACHE

Pros Runs on dedicated roles or existing roles (co-located)

Deployment is very straightforward

Same API as the on-premises AppFabric caching

Supports replication for high-availability

Provides diagnostics information

Cons No security measurements (necessary?)

Accessible only within the cloud service

No management tools

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 20: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

WINDOWS AZURE IN-ROLE CACHE

21

OtherRoles

Co-locatedRoles

DedicatedWorker Role

Cloud ServiceC

luste

ring

& R

ep

lica

tion

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 21: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

22

WINDOWS AZURE IN-ROLE CACHE

Dedicated cache role Add a Cache Worker Role project to the cloud

project

Configure number of instances and size

Co-located cache Open the Caching tab in the role’s properties, and

select the Enable Caching option

Specify cache size (percentage of memory)

In the application Add the Windows Azure Caching NuGet package

Configure the role name running the cache

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 22: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

23

WINDOWS AZURE IN-ROLE CACHEBenchmark

Page 23: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

24

MEMCACHEDOpen source, in-memory key-value cache

Page 24: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

25

MEMCACHED

Simple CRUD API Data is stored in binary form Item eviction (LRU and absolute) Features extended by client libraries

Clustering

Sliding eviction

Replaceable serializers

Data compression

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 25: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

26

MEMCACHED

Pros Well-known solution, used by many sites

Has many client libraries (C++, Java, PHP, .NET, Ruby …)

Supports clustering (managed by the client library)

Cons Item size limited to 1 MB

Retrieve only by ID, no query support

Windows port a bit old (1.4.4 from 2009)

Replication not supported in most client libraries

No security – public endpoints are problematic(Security supported with SASL on Linux VMs)

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 26: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

MEMCACHED

27

OtherRoles

Memcached Worker Roles

Cloud Service

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 27: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

28

MEMCACHED

Cache service Create a new worker role

Add an internal endpoint in the role’s properties for port 11211

Configure number of instances and size

Worker role Add the WazMemcachedServer NuGet package

Add a bit of code (2 lines) to run the cache service

In the application Add the EnyimMemcached NuGet package

Add some code to create the client configuration

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 28: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

29

MEMCACHED

var configuration = new MemcachedClientConfiguration();

foreach (var instance in RoleEnvironment.Roles["MemcachedServer"].Instances)

{

IPEndPoint endpoint = instance.InstanceEndpoints["MemcachedEP"].IPEndpoint;

configuration.Servers.Add(endpoint);

}

var client = new MemcachedClient(configuration);

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 29: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

30

MEMCACHEDBenchmark

Page 30: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

31

REDISOpen source, advanced key-value store

Page 31: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

32

REDIS

Stores entities, lists, and sets Item eviction (LRU, absolute, and sliding) Item locking Atomic transactions for groups of

commands Built-in Pub/Sub messaging Cache can be persisted periodically or

consistently

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 32: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

33

REDIS

Pros Supports various data types

Windows version is up-to-date

Data is replicated to slave servers for high-availability

Secured with authentication

Cons Single threaded, requests are served sequentially

Transport is not encrypted

Does not support clustering

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 33: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

Cloud Service

REDIS

34

Redis Slave

Re

plic

atio

n

Redis Master

Virtual Machine

Cloud Service

Vir

tu

al

Ne

tw

or

k

OtherRoles

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 34: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

35

REDIS

Run the deployment tool from ossonazure.interoperabilitybridge.com

Wait 20 minutes while it executes Give up and press Ctrl+C Open Visual Studio and do it manually

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 35: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

36

REDIS

Create a cloud project with two worker roles: RedisMaster and RedisSlave

Configure roles Add an internal endpoint for port 6379

Set instance sizes

Set number of slave instances

In both worker roles Add the redis-server.exe and redis.conf files

Add code to run the redis-server.exe using Process.Start()

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 36: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

37

REDIS

In the slave worker role Write code to edit the redis.config and set

the master’s IP address

In the application Add the ServiceStack.Redis NuGet

package

Use either the RoleEnvironment or a static IP address to configure the master’s address

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 37: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

38

REDISBenchmark

Page 38: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

39

COUCHBASEOpen source document database

Page 39: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

40

COUCHBASE

Entities stored as either binary or JSON Item eviction (absolute and sliding) No LRU, it’s a database Bulk get Cache (bucket) per application Indexing and querying with views Views can use reduce functions

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 40: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

41

COUCHBASE

Pros Replication and clustering

Buckets can be Couchbase or Memcached based

Couchbase buckets are persisted (enables warmup)

Secured (transport + authentication)

Web administration

Provides usage statistics

Cons Requires a virtual machine and a virtual network

Query requires serializing content to JSON

Not totally free

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 41: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

42

COUCHBASE

Replication & Clustering

Virtual Machine

Cloud Service

Vir

tu

al

Ne

tw

or

k CouchbaseVMs

On-premises

VPN

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 42: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

43

COUCHBASE

Create a virtual network Create VMs in the virtual network In each VM

Install Couchase

Configure incoming firewall rules(11211, 11210, 4369, 8091, 21100-21199)

Configure Couchbase cluster

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 43: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

44

COUCHBASE

In the application Add the CouchbaseNetClient NuGet

package

Configure the VMs addresses and port

If application is running in a cloud service

Add a <NetworkConfiguration> element in the ServiceConfiguration.Cloud.cscfg

Configure the role to use the same virtual network as the Couchbase VMs

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 44: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

45

COUCHBASE

<NetworkConfiguration>

<VirtualNetworkSite name="CachingNetwork" />

<AddressAssignments>

<InstanceAddress roleName="AzureCacheClientDemo">

<Subnets>

<Subnet name="Compute" />

</Subnets>

</InstanceAddress>

</NetworkConfiguration>

Featu

res

Pro

s/Cons

Topolo

gy

Ste

ps

Page 45: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

46

COUCHBASEBenchmark

Page 46: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

47

BENCHMARK COMPARISON

BTW, the lower the better!

Page 47: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

48

OTHER CACHING OPTIONS

Install on-premises caching solutions on Virtual Machines

Use either Windows or Linux VMs

Easily accessible by clients running in the same virtual network

External access may require additional configuration

Use other cache-as-a-service solutions Prefer services that use Windows Azure – better

throughput

Redis and Memcached are currently available as a service in Windows Azure (http://garantiadata.com)

Page 48: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

49

THE GOTCHAS

Security Private vs. Public vs. Virtual network

Clustering Public endpoint load balancing

Debugging Deployed cache vs. Windows Azure Emulator

VM restarts Cache resets due to guest/host upgrades

Price Choose the proper instance size

Page 49: Caching in Windows Azure

www.devconnections.com

CACHING IN WINDOWS AZURE

50

RESOURCES

Windows Azure Cache

bit.ly/appfabric-on-azurebit.ly/azure-caching-memcached

Memcached

memcached.orgbit.ly/memcached-on-azure

Redis

redis.iobit.ly/redis-on-azurebit.ly/redis-on-azure-linux

Couchbase

www.couchbase.combit.ly/couchbase-on-azure

[email protected] @idoflatow http://bit.ly/flatow-blog

This presentation: sdrv.ms/17s8osK