More Cache for Less Cash (DevLink 2014)

Preview:

DESCRIPTION

Review of the various cache options available in the Microsoft Azure platform.

Citation preview

More Cache for Less Cash

Michael S. Collier@MichaelCollier

DevLink 2014 – August 27, 2014

Today’s Agenda

• Why Cache?• Cache Options in Azure• Demos• Monitoring and Scaling• Pricing and Features

3

4

Why Cache?

Load on server increases with users

Add a load balancer and more web instances

Continue to scale out the web and business logic tiers

DB load starts to increase, becomes the bottleneck

Azure Load Balancer

Web Tier

Business Tier

Data Tier

5

Why Cache?

Improve application performance

Reduce load on DB

Azure Load Balancer

Web Tier

Business Tier

Data Tier

Cache Cache Tier

What is Azure Cache Service?

6

A distributed, in-memory, flexible cache for all data types that can be used to speed up Azure applications and reduce database load.Basically, cache helps your

app become faster.

Windows Azure Cache

A Cache Story

Shared Cache

• Cloud Services

• Shared – quotas

• Lacked feature parity

• Multiple size options

• Expensive• Performance challenged• Throttling

• Deprecated August 2014

In-Role Cache

• Cloud Services

• Co-located (free)

• Dedicated ($$)

• Feature parity

• Good performance

• Not multi-tenant

Cache Service

• Cloud Services, Web Sites, or VMs

• Feature parity

• Managed infrastructure

• Price/capacity tiers

• Good performance (1ms read)

7

A Cache Story

Shared Cache

• Cloud Services

• Shared – quotas

• Lacked feature parity

• Multiple size options

• Expensive• Performance challenged• Throttling

• Deprecated August 2014

In-Role Cache

• Cloud Services

• Co-located (free)

• Dedicated ($$)

• Feature parity

• Good performance

• Not multi-tenant

Cache Service

• Cloud Services, Web Sites, or VMs

• Feature parity

• Managed infrastructure

• Price/capacity tiers

• Good performance (1ms read)

8

A Cache Story

Shared Cache

• Cloud Services

• Shared – quotas

• Lacked feature parity

• Multiple size options

• Expensive• Performance challenged• Throttling

• Deprecated August 2014

In-Role Cache

• Cloud Services

• Co-located (free)

• Dedicated ($$)

• Feature parity

• Good performance

• Not multi-tenant

Cache Service

• Cloud Services, Web Sites, or VMs

• Feature parity

• Managed infrastructure

• Price/capacity tiers

• Good performance (1ms read)

9

A Cache Story

Shared Cache

• Cloud Services

• Shared – quotas

• Lacked feature parity

• Multiple size options

• Expensive• Performance

challenged• Throttling

• Deprecated August 2014

In-Role Cache

• Cloud Services

• Co-located (free)

• Dedicated ($$)

• Feature parity

• Good performance

• Not multi-tenant

Cache Service

• Cloud Services, Web Sites, or VMs

• Feature parity

• Managed infrastructure

• Price/capacity tiers

• Good performance (1ms read)

Redis Cache

• TBD

• TBD

• TBD

• TBD

10

http://aka.ms/MigrateFromSharedCaching

In-Role Cache (Co-located)

11

Web Roles

300MB 300MB 300MB 300MB

1.2GB Distributed Cache

Source: Windows Azure Training Kit

In-Role Cache (Dedicated)

12

24GB Distributed Cache

Web Roles

12GB CacheWorker Role

12GB CacheWorker Role

2Source: Windows Azure Training Kit

In-Role Cache (Dedicated)

13

24GB Distributed Cache

Web Roles

12GB CacheWorker Role

12GB CacheWorker Role

4

12GB CacheWorker Role

12GB CacheWorker Role

48GB Distributed Cache

Source: Windows Azure Training Kit

14

In-Role Cache

• Based on the AppFabric Cache engine• Released w/ Oct. 2012 release of Azure SDK 1.8• Cache part of your Cloud Service application• No quotas or throttling• Isolation, flexibility, and control• High performance

• Features: named cache, regions, tagging, HA, local, notifications

• Pro: You manage as part of your application• Con: You manage it; only available to Cloud Service roles

in same deployment

Create and Configure In-Role Cache

Configure a Role in the Cloud Service to host the cache

15

Configure the Cache Clients

• Use NuGet to configure the cache clients• Microsoft.WindowsAzure.Caching• Settings placed in web.config or app.config• Modify to point to the cache server role

16

<dataCacheClients> <dataCacheClient name="default"> <!--To use the in-role flavor of Windows Azure Cache, set identifier to be the cache cluster role name --> <!--To use the Windows Azure Cache Service, set identifier to be the endpoint of the cache cluster --> <autoDiscover isEnabled="true" identifier="MyScores.Web" /> <!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />--> </dataCacheClient></dataCacheClients>

Role Name

17

DEMO TIME!!!

18

Recap

1. Select “Enable Caching” in Azure role configuration

2. Install NuGet package (Microsoft.WindowsAzure.Caching)

3. Set role name in web.config4. Get/Set data

Monitoring the Cache

Diagnostic Level

Data Collected

0 Critical/catastrophic server logs only

1 Data to help in assessing usage patterns, cache health, and potential errors. Default.

2 Fine grain data for all requests and important system information

3 Diagnostic data with more verboseness and system information

4 Highest verbosity logs for all requests and system information

19

Provides a single setting for cache servers and clientsConfigures levels for logs, traces, performance counters & crash dumps

Full details at http://aka.ms/CacheDiagnostics

20

Monitoring the Cache

• Set cache diagnostic level in configuration or portal

• Level (1-4) controls verbosity, perf counters, & crash dumps.

• Start at 1 and increase as needed<Role name="WorkerRole1"> <Instances count="1" /> <ConfigurationSettings> <!– Cache Server --> <Setting name="Microsoft.WindowsAzure.Plugins.Caching.DiagnosticLevel“ value="1" />

<!– Cache Client--> <Setting name="Microsoft.WindowsAzure.Plugins.Caching.ClientDiagnosticLevel" value="1" /> </ConfigurationSettings></Role> Full details at http://mcollier.net/AzureCacheDiag

Monitoring the Cache

21

public class WebRole : RoleEntryPoint{    public override bool OnStart()    {             

// Enable cache diagnostics       DiagnosticMonitorConfiguration dmConfig =              DiagnosticMonitor.GetDefaultInitialConfiguration();

      // Configure collection of cache diagnostic data.       CacheDiagnostics.ConfigureDiagnostics(dmConfig);

      DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString",  dmConfig);

      return base.OnStart();     }}

Considerations

• Unable to create DataCache in RoleEntryPoint

• Max object size is 8MB post serialized

• Default serializer is NetDataContractSerializer

• Cost only for role instances

• Only accessible from within same Cloud Service• Deployment will impact the cache (instances recycle)

22

23

What’s the Azure Managed Cache Service?

Shared Azure Website Stamp

App2

App1 VM VM

VM

IaaS VMs

Cloud Services

Azure Managed Cache Service

1. SLA backed2. Microsoft Managed3. Scalable &

Resilient

24

Create and Configure the Cache Service

• Based on AppFabric Cache engine

• Create via PowerShell only • Manage in Azure management portal

• Choose an offering• Basic (128MB to 1GB in 128MB units, 1 named cache)• Standard (1GB to 10GB in 1GB units, notifications, and 10 named

caches)• Premium (5GB to 150GB in 5GB units, notifications, HA, and 10

named caches)

• Locate in same region as client for best perf and cost

Create and Configure the Cache Service

25

PS C:\> New-AzureManagedCache -Name devlinkcache ` -Location "East US" `

-Sku Basic ` -Memory 128MB

26

DEMO TIME!!!

27

Recap

1. Create Managed Cache via PowerShell2. Install NuGet package

(Microsoft.WindowsAzure.Caching)3. Set cache service endpoint & key in

web.config4. Get/Set data

28

Monitoring the Cache

29

Scaling the Cache

Dynamically scale without loosing any existing data

30

High Availability

Client Primary

Secondary

Read / Write

Write

Premium only

Doubles required memory

Increased latency & decreased throughput

31

Pricing Details

Basic Standard Premium

Price Per Unit(Preview)

$25/month(prorated hourly)

$100/month(prorated hourly)

$400/month(prorated hourly)

Cache Size 128 MB 1 GB 5 GB

Scale Up to 8 units Up to 10 units Up to 30 units

Named Caches 1 10 10

High Availability Notifications

See http://mcollier.net/AzureCachePricing

Benefits of the Azure Managed Cache Service• Use from any app types (VM, Web Site, Mobile Service, Cloud

Service)• Each instance deployed within dedicated VMs (fast, predictable

performance)• No quotas or throttling• Store up to 150GB per cache instance• Avg. retrieval time of 1ms. Insert in about 1.2ms• Highly available / distributed across multiple servers• Managed service – focus on apps not infrastructure• Same .NET cache API used with in-role cache for Cloud

Services• Support for ASP.NET Session State and Page Output Caching• Unique cache service instance for each app, or share across

apps32

33

Azure Redis Cache (Preview)

• Secure, dedicated Redis cache• Hosting and monitoring by Microsoft

• 250MB – 26GB (Preview)

• Tiers• Basic – single node; dev/test and non-critical

workloads• Standard – provides master/slave replication

Azure Redis Cache (Preview)

34

35

Monitoring and Alerts

• Set metrics and timeframe to monitor

• Pin to dashboard

• Alert when threshold reached

36

DEMO TIME!!!

37

Recap

1. Create Redis Cache via portal2. Add Redis C# client (e.g.

StackExchange.Redis)3. Obtain Redis endpoint and password from

portal4. Determine formatter for .NET objects5. Get/Set data

38

Common Architecture

Web Roles

Storage Table

Windows Azure Cache

3. W

rite

1. R

ead

2. Read

39

Common Architecture

Windows Azure Load Balancer

Web Roles Worker Roles

SQL Database (Azure)

Azure Cache

Read

Read

Writ

e

Preload the cache

Carefully choose expiration and eviction settings

40

Common Architecture

Azure Load Balancer Web Roles Storage Queue Worker Roles

Storage Table SQL Database (Azure)

Azure Cache

Write Read

Wri

te

Read

Write

Wri

te

Cloud Service Fundamentals - Caching

• Factory implementation• Custom BinarySerializer

class• protobuf-net• Fast and small

41

http://mcollier.net/AzureCSF

What Cache?

42

• Azure Shared Cache – out of service on September 1, 2014

New Development

Need GA and SLA

43

Where to Cache?

Mix cache solutions for price / manageability / features

Azure Load Balancer Web Roles

Azure Cache

Read

• Data shared by other services/apps

• General application data

In-role cache

• Session / Page Output Cache

• FREE!

Summary

• In-Role Cache• Cloud Services only• Co-located (free) or Dedicated ($$$)• Isolated cache-related workload

• Cache Service• Microsoft managed service, dedicated tenant, SLA backed• Cloud Services, Web Sites, and VMs• Full parity with in-role cache (SDK)

• Redis Cache• Microsoft managed Redis Cache• Master/Slave replication in Standard tier• Normal Redis features/functionality

44

More Resources

• Azure Cache Options Overview• http://msdn.microsoft.com/en-us/library/azure/gg278356.aspx

• Which Azure Cache Offering is right for me?• http://msdn.microsoft.com/en-us/library/azure/dn766201.aspx

• Cloud Service Fundamentals – Caching Basics• http://azure.microsoft.com/blog/2013/10/03/cloud-service-fundamentals-caching-basics/

• Capacity Planning Spreadsheet (In-Role Cache)• http://msdn.microsoft.com/en-us/library/hh914129

• Lap around Azure Redis Cache• http://azure.microsoft.com/blog/2014/06/04/lap-around-azure-redis-cache-preview/

45

Q &

A

Ask your questions

Recommended