View
3.745
Download
1
Category
Tags:
Preview:
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.
Citation preview
Ido FlatowSenior Architect
Microsoft MVPSELA Group
Caching in AzureMore than Just Azure Caching
@idoFLATOWhttp://bit.ly/flatow-blog
This presentation:http://sdrv.ms/
17s8osK
www.devconnections.com
CACHING IN WINDOWS AZURE
2
THE WORLD BEFOREDISTRIBUTED CACHE
www.devconnections.com
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
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
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
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
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
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
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
www.devconnections.com
CACHING IN WINDOWS AZURE
12
WINDOWS AZURE CACHE SERVICECache-as-a-Service
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
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
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
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
www.devconnections.com
CACHING IN WINDOWS AZURE
17
WINDOWS AZURE CACHE SERVICEBenchmark
www.devconnections.com
CACHING IN WINDOWS AZURE
18
WINDOWS AZURE IN-ROLE CACHEDistributed cache agent for cloud services
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
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
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
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
www.devconnections.com
CACHING IN WINDOWS AZURE
23
WINDOWS AZURE IN-ROLE CACHEBenchmark
www.devconnections.com
CACHING IN WINDOWS AZURE
24
MEMCACHEDOpen source, in-memory key-value cache
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
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
www.devconnections.com
CACHING IN WINDOWS AZURE
MEMCACHED
27
OtherRoles
Memcached Worker Roles
Cloud Service
Featu
res
Pro
s/Cons
Topolo
gy
Ste
ps
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
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
www.devconnections.com
CACHING IN WINDOWS AZURE
30
MEMCACHEDBenchmark
www.devconnections.com
CACHING IN WINDOWS AZURE
31
REDISOpen source, advanced key-value store
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
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
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
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
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
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
www.devconnections.com
CACHING IN WINDOWS AZURE
38
REDISBenchmark
www.devconnections.com
CACHING IN WINDOWS AZURE
39
COUCHBASEOpen source document database
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
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
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
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
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
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
www.devconnections.com
CACHING IN WINDOWS AZURE
46
COUCHBASEBenchmark
www.devconnections.com
CACHING IN WINDOWS AZURE
47
BENCHMARK COMPARISON
BTW, the lower the better!
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)
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
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
idof@sela.co.il @idoflatow http://bit.ly/flatow-blog
This presentation: sdrv.ms/17s8osK
Recommended