techdays 2010 portugal - scaling your data tier with app fabric 16x9
Post on 10-May-2015
2.064 Views
Preview:
TRANSCRIPT
Como garantir a escalabilidade da sua camada de dados com o Windows Server AppFabric
WIN304
Nuno Godinho
Partner & CTO @ ITech4All
nuno.godinho@itech4all.com
@NunoGodinho
Nuno Filipe GodinhoPartner & CTO @ ITech4all
Mail: Nuno.Godinho@itech4all.comNuno.Godinho@sapo.pt
Blogs: http://pontonetpt.com/blogs/nunogodinhohttp://xamlpt.com/blogs/nunogodinhohttp://weblogs.asp.net/nunogodinhohttp://msmvps.org/blogs/nunogodinho
Twitter: @NunoGodinho
About Me
• The Problem!• Caching with the Windows
Server AppFabric• Overview and Programming
Model• Caching Futures• Summary• Q&A
Agenda
The Problem
Online Pharmacy
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
And then…
• Flu Hits!
You become a popular Pharmacy!
…Web Tier(ASP.Net)
Users
Database Data Tier
Application
Application
Application
Web Site’s too
slow!!
Servers are crashing
Database is hot!!
Where did my
shopping cart go?
Possible Solution
Data Near Processing
ASP.NET
Web ServiceDatabas
e
Smart Client Browser
Cache
CacheCache
CacheCache
• Cache is scoped to machine / process• Machines die• Processes recycle
• Cache memory is limited
Good but…
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?
Caching with the Windows Server AppFabric
What Is It?
• 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
Where does it fit?
… Web Tier(ASP.Net)
Users
Database
Cloud Data Tier
Application
Application
ApplicationCaching
Access LayerCaching
Access Layer
Cach
ing
Serv
ice
Cach
ing
Serv
ice
Cach
ing
Serv
ice
Cache Tier
Caching Access Layer
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
Why AppFabric Caching
• 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
• 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.
• 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?
• 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.
What Stage Is It In?
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”)
DemoInstallation
Overview and Programming AppFabric Caching
Deployment and Access API
Deployment
Cach
ing
Serv
ice
Cach
ing S
erv
ice
Cach
ing
Serv
ice
Configuration Store
Install AppFabric
… Application Application Application
<hosts> <host name="BL1CDB8083714“ cachePort="22233" cacheHostName="DistributedCacheService"/> ….. </hosts> <localCache isEnabled=“true" ../><security … />
Caching Access Layer
Caching Access Layer
Caching Access Layer
.NET 3.5 SP1 OR .NET 4
Configure AppFabric
.NET 4
Update Web.config
Users
Copy Client DLLs
DemoAppFabric Caching CodePlex Tool
http://mdcadmintool.codeplex.com/
• 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
• Centralized administration through powershell
• Perfmon to monitor the cache (new in Beta)
• Logging • Default ETW, support for file logs
Administration & Monitoring
// 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");
• 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
• 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);
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
How does it Scale?
Data Distribution - Partitioned Cache
… Web Tier
Cache TierC
ach
e Serv
ice
Cach
e Serv
ice
Users
Cach
e
Serv
ice
A C EDB G IHF
Scale on Data Size - More machines => More memory to
cache
Scale on Cache Throughput - More machines => keys
distributed across more machines => better throughput
ASP.Net App
Caching Client
ASP.Net App
Caching Client
ASP.Net App
Caching Client
AC ED BGI HF
Scale Test Output
Load
Throughput
Latency
1 Cache ServerAs load increases, throughput fails
to scale latency increases
Caching Tier
Add Second Cache Server
ThroughputLoad Max
Throughput increasesLatency
decreases
Caching Tier
Load
Latency
Add Third Cache Server
Load
Throughput
Latency
Caching Tier
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
Features
• 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!
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
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
• 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”);
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
• 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
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
• 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);
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
DemoProgramming Model
AppFabric Caching Futures
AppFabric Caching and Azure Platform
• 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
App on-premise; Data on SQLAzure
… ASP.Net Web Tier Application Application Application
AppFabric Caching Access
Layer
AppFabric Caching Access Layer
AppFabric Caching Access
Layer
Cach
ing
Work
er
Role
Cach
ing
Serv
ice
Cach
ing
Serv
ice
Cach
ing
Serv
ice Application &
AppFabric Caching
deployed On-premise
Data on SQL Azure
App on Windows Azure; Data on SQL Azure
…Web Role
Application Application ApplicationAppFabric
Caching Access Layer
AppFabric Caching Access Layer
AppFabric Caching Access
Layer
Cach
ing
Work
er
Role
Cach
ing
Serv
ice
Cach
ing
Serv
ice
Application & AppFabric
Caching on Windows Azure
Data on SQL Azure
AppFabric Caching Worker
Role
Cach
ing
Serv
ice
App on Windows Azure; Data on-premise
…Web Role
Application Application ApplicationAppFabric
Caching Access Layer
AppFabric Caching Access Layer
AppFabric Caching Access
Layer
Cach
ing
Work
er
Role
Cach
ing
Serv
ice
Cach
ing
Serv
ice
Application & AppFabric
Caching on Windows Azure
AppFabric Caching Worker
Role
Cach
ing
Serv
ice
Data on-premises
AppFabric Service
Bus
ASP.NET and Persistence
• 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
• 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
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
Summary
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
http://msdn.microsoft.com/AppFabric
AppFabric on MSDN
Q & A
A sua opinião é importante!Complete o questionário de avaliação e devolva-o à saida.
top related