TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

68
Como garantir a escalabilidade da sua camada de dados com o Windows Server AppFabric WIN304 N uno Godinho Partner & CTO @ ITech4All [email protected] @NunoGodinho

Transcript of TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Page 1: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Como garantir a escalabilidade da sua camada de dados com o Windows Server AppFabric

WIN304

Nuno Godinho

Partner & CTO @ ITech4All

[email protected]

@NunoGodinho

Page 2: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Nuno Filipe GodinhoPartner & CTO @ ITech4all

Mail: [email protected]@sapo.pt

Blogs: http://pontonetpt.com/blogs/nunogodinhohttp://xamlpt.com/blogs/nunogodinhohttp://weblogs.asp.net/nunogodinhohttp://msmvps.org/blogs/nunogodinho

Twitter: @NunoGodinho

About Me

Page 3: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• The Problem!• Caching with the Windows

Server AppFabric• Overview and Programming

Model• Caching Futures• Summary• Q&A

Agenda

Page 4: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

The Problem

Page 5: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Online Pharmacy

Page 6: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Typical Web Architecture

• Need to get routed to same machine (i.e. sticky sessions)

Users

• Each machine round trips for data

• Data that is cached is stored in the memory of one server

Web Tier

• CPU and disk can get saturated due to traffic

• Service access is slow

Data

Tier

Page 7: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

And then…

• Flu Hits!

Page 9: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Possible Solution

Page 10: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Data Near Processing

ASP.NET

Web ServiceDatabas

e

Smart Client Browser

Cache

CacheCache

CacheCache

Page 11: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• Cache is scoped to machine / process• Machines die• Processes recycle

• Cache memory is limited

Good but…

Page 12: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

1Some features may require certain editions of Windows Server

• You could have as much cache as you wanted?

• You could share a giant cache across servers, services and even clients?

• What if this was something you could simply add to the platform for 1free?

What if?

Page 13: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Caching with the Windows Server AppFabric

Page 14: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

What Is It?

Page 15: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• An explicit, distributed, in-memory application cache for all kinds of data • (CLR objects, rows, XML, Binary data etc.)• Fuse "memory" across machines into a unified

cache

What is AppFabric Caching?

Unified Cache View

Caching clients can be across machines or processes

Clients Access the Cache as if it

was a large single cache

Cache Layer distributes data

across the various cache

nodes

Page 17: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

AppFabric Cache

• No need for sticky sessionsUsers

• Cached data available to all serversWeb

Tier

• Multiple machines means scale and high-availability

• Lots of cache memory

Caching Tier

• Reduces load on database

• Duplicate Service Calls eliminated

Data Tier

Page 18: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Why AppFabric Caching

Page 19: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• 1. Share Data Across Applications• No more sticky routing

• 2. Performance

• 3. Scale out by adding more boxes

• 4. High Availability Protect from Web & Cache Server Failure

Why use AppFabric Caching?

Operation Throughput Latency Bulk Fetch

Read 28, 000/ sec (2k)

1-2ms 200k/sec (512 bytes)

Write 20,000 / sec (2k)

3 ms -

Operation Servers Throughput

Read 2k 1 28,000 ops/ sec

Read 2k 2 52, 500 ops/ sec

Read 2k 3 78, 000 ops/ sec

Page 20: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• 5. Proven Technology - Associated Press Custom News live on CTP3

Why use AppFabric Caching?

• AppFabric caching capabilities caches metadata and news for widgets

• Serves 16 million hits per day

• Increased the amount of cached data 6 times.

Page 21: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• 5. Proven Technology Contd..• Dell.com uses AppFabric caching!• Channel Partner Portal uses AppFabric

caching• Provides targeted content and search results • Tracks customer browse history and downloads.

• Next Generation Sales Platform Solutions to use AppFabric caching (currently under construction)

• Just two of the many TAP customers in line for production

Why AppFabric Caching?

Page 22: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• 6. Do all this at low cost!

Why AppFabric Caching? – Best yet

AppFabric

CACHINGSERVICE BUS ACCESS

CONTROL

MONITORINGWORKFLOW HOSTING

SERVICE HOSTING

SCALE OUTHIGH AVAILABILITY

MULTI-TENANT

MANAGEMENT

• Use inexpensive commodity hardware

• Ships as part of Windows Server AppFabric 2010 Wave 1

* Different Features of the cache might require higher level SKUs of Windows Server.

Page 23: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

What Stage Is It In?

Page 24: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

When Can I Get Windows Server AppFabric ?

CTP1June ‘08

CTP2PDC ‘08

CTP3Mar

‘09

Beta• PDC• Nov ‘09

RTM2010 Wave 1

* CY10

Azure CTPPost RTM

(Formerly Called “Velocity”)

Page 25: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

DemoInstallation

Page 26: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Overview and Programming AppFabric Caching

Page 27: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Deployment and Access API

Page 29: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

DemoAppFabric Caching CodePlex Tool

http://mdcadmintool.codeplex.com/

Page 30: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• Domain Based Security Option• Domain Account / Local Account based

Authentication• Only authorized servers can join the cluster• Only authorized clients can connect to the

cluster

• Transport Level Security• Turn on/off Signing or Encryption

• Can turn off Cache Security• Use Firewalls, IPSec, VLANs to protect cache

Security (new since Beta)

grant-cacheallowedclientaccount  RedDomain\Machine1$ grant-cacheallowedclientaccount  RedDomain\John

Page 31: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• Centralized administration through powershell

• Perfmon to monitor the cache (new in Beta)

• Logging • Default ETW, support for file logs

Administration & Monitoring

Page 32: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

// Create instance of cachefactory (reads appconfig)DataCacheFactory fac = new DataCacheFactory();

// Get a named cache from the factoryDataCache catalog = fac.GetCache("catalogcache");

AppFabric Caching API

// Simple Get/Putcatalog.Put("toy-101", new Toy("Puzzle", .,.));

// From the same or a different clientToy toyObj = (Toy)catalog.Get("toy-101");

// Region based Get/Putcatalog.CreateRegion("toyRegion");

// Both toy and toyparts are put in the same region catalog.Put("toy-101", new Toy( .,.), “toyRegion”);Catalog.Put("toypart-100", new ToyParts(…), “toyRegion”);

Toy toyObj = (Toy)catalog.Get("toy-101“,"toyRegion");

Page 33: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• Host• Physical processes hosting

AppFabric Caching instance.• Named Caches

• Can span across machines• Defined in the configuration file

AppFabric Caching Logical Hierarchy

• Cache Item• Key, Payload (Object ), Tags, TTL,

Timestamps, Version

• Regions• Physically co-located Container of

Cache Items• May be implicit or explicitly

created

Regions Region A

Key Payload Tags Key Payload Tags 121 xxxx “Toy” “Child”

123 yyyy “Toy” “Chair”..

Machine -> Cache Host -> Named Caches -> Regions -> Cache Items -> Objects

AppFabric Caching Service

Named Cache : Product Catalog

Named Cache : Electronics Inventory

AppFabric Caching Service

AppFabric Caching Service

AppFabric Caching Service

Page 34: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• Add Tags to Items• Tag Search on Default Regions (New

in Beta)

Access APIs – Tagging Items

Tag hotItem = new Tag("hotItem");

catalog.Put("toy-101", new Toy("Puzzle"), new Tag[]{hotItem}, “toyRegion”);

catalog.Put("toy-102", new Toy("Bridge"), “toyRegion”);

// From the same or a different clientList<KeyValuePair<string, object>> toys = catalog.GetAnyMatchingTag("toyRegion", hotItem);

Page 35: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Usage Pattern – Cache Aside (Explicit Caching)

// Read from CacheToy toyObj = (Toy) catalog.Get("toy-101"); Application

Cach

ing

Serv

ice

Database

// If Not present in the cacheif (toyObj == null){ // Read from backend.. toyObj = ReadFromDatabase(); // Populate Cache catalog.Put("toy-101", toyObj);

return toyObj;}

Caching Access Layer

Page 36: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

How does it Scale?

Page 38: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Scale Test Output

Load

Throughput

Latency

1 Cache ServerAs load increases, throughput fails

to scale latency increases

Caching Tier

Page 39: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Add Second Cache Server

ThroughputLoad Max

Throughput increasesLatency

decreases

Caching Tier

Load

Latency

Page 40: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Add Third Cache Server

Load

Throughput

Latency

Caching Tier

Page 41: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

GridDynamics Blog Engine Tests

00:00 05:00 10:00 15:00 20:000

1000

2000

3000

4000

5000Throughput Test

Increase Load vs Requests / sec

Time

More info at http://blogs.msdn.com/velocity/ or http://www.griddynamics.com/velocity

0 1000 2000 3000 40000

0.1

0.2

0.3

0.4

0.5

16 KB objects, Response Time,

sec

Requests / sec1 2 3 4 5 6 8

0

1000

2000

3000

4000

5000Scale Test

# of Nodes vs Throughput

Nodes

Page 42: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Features

Page 43: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• Classify your data • Reference or Activity or Resource Data

• Examine Requirements• Performance - Throughput & Latency• Consistency – Tolerable staleness• Eviction - Is the data evictable?• Security - Is there any secure data?• Availability – Survive node or cluster

failures?

Use the right features!

Page 44: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Types of Data

Reference Activity Resource

Primary Read Only Read-Write Not shared

Read-Write, Shared

Catalog Data Shopping Cart Auction Data/Seat Assignment

Web Tier

Distributed Cache

Shopping Cart

Pharmacy Catalog

Pharmacy Inventory

Grocery Shop

Page 45: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

ApplicationApplication

AppFabric Caching Client

• Catalog data doesn’t change often• Unnecessary network cost to access from different

machines• Solution – Local Cache

Reference Data – Performance

Put(K2, v3)

Routing Table

Cache2Cache1

Primary for K2,V2

K2, V2

Primary for K1,V1

K1, V1

Cache3

Primary for K3,V3

K3, V3

AppFabric Caching Client

Local CacheRouting Table

K2, V2

Get(K2)Get(K2)

K2, V3

Page 46: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• Enumerate all items in Region• Bulk Fetch from region (New in

Beta)• 200-300k ops per second

Reference Data – Bulk Get

Catalog.BulkGet( new List<string>(){“toy-101”, “toy-102”} ,

“toyRegion”);

Page 47: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

ApplicationApplication

(K2, V2)

Cache2Cache1 Cache3

Primary for

Activity Data - Availability

Get(K2)

Primary for Primary for

K3, V3

AppFabric Caching ClientRouting Table

K2

, V2

PUT

Secondary for

K2, V2

K1, V1

Secondary for

K3, V3

Secondary for

K1, V1

AppFabric Caching ClientRouting Table

K2, V2

Replication Agent

Page 48: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• GetCacheItem returns a version object• Every update to an object internally increments it's version• Supply the version obtained along with the Put/Remove• Put/Remove will succeed only if the passed in version matches the

version in the cache

Resource Data - Optimistic Locking

Version Based Update

Time Client1 Client2 (Different Thread or process)

T0 CacheItem item = catalog.GetCacheItem(“PlayerRegion”, ”Zune”);

CacheItem item = catalog.GetCacheItem(“PlayerRegion”, ”Zune”);

T1 ((ZuneObject)item.Object).inventory --;

((ZuneObject)item.Object).inventory--;

T2 catalog.Put(“PlayerRegion”, “Zune”, item.Object, item.Version);

T3 catalog.Put(“PlayerRegion”, “Zune”, item.Object, item.Version);// Version mismatch// Client must retry again

Two clients access the same item

Both update the item

Second Client gets in first; put succeeds because item version matches;

atomically increments the version

First client tries put;Fails because the versions

don’t match

Page 49: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

K1

• New in Beta – Take locks on non-existent keys• Allows you to co-ordinate creating new object

amongst multiple clients

Resource Data - Pessimistic Locking

Client1: GetAndLock ("k1")

Client2: GetAndLock ("k1")

Client3: Get ("k1")

Regular Get succeeds

GetAndLock gets lock handle

Other GetAndLock on same item fails

Page 50: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• Cache Event notifications• Register on any client to notify

changes• Batched Notifications – (New in

Beta)

Resource/Activity Data – Tracking Changes

DataCache.RegisterCacheLevelCallback( int filter, DataCacheChangeCallback delegate);

DataCache.RegisterRegionLevelCallback( String region, int filter, DataCacheChangeCallback delegate);

DataCache.RegisterKeyLevelCallback( String region, String key, int filter, DataCacheChangeCallback delegate);

Page 51: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Application

Cache2Cache1

Primary for

K2, V2

Primary for

K1, V1

Cache3

Primary for

K3, V3

Scalable Notifications

AppFabric Caching ClientRouting Table

Register Notification for

Key “K3"

Map Keys to Partition

(say P2)

Poll Required

Nodes

Nodes Return List of

ChangesLSN Order

Partition: P2

Last LSN: 19

Call DelegateStore Last LSN

Change Log

Partition P1

Add K2Del K32

Change Log (Partition P2)

Del K32Del K43

Change Log

33 Add K134 Del

K22

Page 52: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

DemoProgramming Model

Page 53: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

AppFabric Caching Futures

Page 54: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

AppFabric Caching and Azure Platform

Page 55: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• You are a popular Online Pharmacy!!• Lots of Users!

• Irregular & Elastic Demands

• Solution - Move to the Services World!• Application on-premise with data on SQL Azure• Application on Windows Azure with data on

SQL Azure• Application on Windows Azure with on-premise

database connected by AppFabric Service Bus

Application Growth

Page 59: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

ASP.NET and Persistence

Page 60: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• ASP.Net extends cache surface .Net 4.0

• Integrate with the Application Cache• System.Runtime.Caching namespace• AppFabric Caching will be a provider for

this namespace

• Granular Session Updates• IPartialSessionState lists keys changed

• Extensible Output Cache Provider• Output Caching not limited to single node

Integration with ASP.Net

Page 61: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

• Callback for read-through, write-behind • Specified at Named Cache Level• Read-Through• Called when item not present in cache• Callback returns the object/serialized bytes

• Write-Behind• Writes to cache are queued • Callback called asynchronously in batches• Re-tries upon failure

• Bulk Access APIs

Future – Cache Through

Page 62: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

GridDynamics testing on CTP1

50 times improvement in some cases

HPC Integration

Scratch

AppFabric Caching

Intermediate

Store

RollupOperation

Final

Resu

lts

Keys

SplitMethod

Mark

et

Data

Central Market Data Store(~1 TB Tick

Data)

Final Results Store

Job Input

ScratchCalculationOperation

AppFabric Caching

Market Data

Page 63: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Summary

Page 64: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Web Scenarios

• Distributed/Global object cache• Low latency

access• High scale• Availability

• Cache for reference and activity data

• Scale IIS/ASP.Net applications

Enterprise / HPC

Scenarios

• Persistence• LINQ

enabled cache• Integrate with

HPC server• Heterogeneous

client support• Co-locate

compute and data

Software + Services

Scenarios

• Application Cache for Windows Azure

• More data services• BI, Streaming,

Reporting• OData (REST API)

AppFabric Caching Vision – Cache for all your data

Page 65: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

http://msdn.microsoft.com/AppFabric

AppFabric on MSDN

Page 66: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9

Q & A

Page 68: TechDays 2010 Portugal - Scaling your data tier with app fabric 16x9