Upload
udaiappa-ramachandran
View
767
Download
4
Embed Size (px)
Citation preview
Azure Redis Cache
Udaiappa Ramachandran ( Udai )//linkedin.com/in/udair
Who am I?• Udaiappa Ramachandran ( Udai )• CTO, Akumina, Inc.,• Consultant• Azure Insider• New Hampshire Cloud User Group (http://www.meetup.com/nashuaug )• Focus on Cloud Computing
• Microsoft Azure and Amazon Web Services
• http://cloudycode.wordpress.com• @nhcloud
Agenda• Redis Cache• Redis Data Types• Redis Eviction policies• Cache Patterns• Azure Redis Cache• Best practices• Demo• References• Q & A
Redis Cache• In-memory, high throughput key-value store• Rich data types- Ability to store more than just strings• Configurable Eviction policies• Highly customizable replication support
• Supports hierarchy of ‘Slaves’ per ‘Master’
• Persistence support• Point in time, Log every write, or both
• Clustering• Built in LUA scripting support• Atomic operations• Transactions• Publisher – Subscriber pattern• Pipelining
Redis Cache…• Rich Ecosystem
• Proven at scale: Twitter, GitHub, Weibo, Pinterest, Snapchat, Craigstlist, StackOverflow, Flickr, etc.,
• Wide range of open source community• Rich set of Redis client libraries in multiple languages available on NuGet
• For Example StockExchange.Redis, ServiceStack.Redis• Many more open source libraries and script
• Tools• Redis-benchmark.exe• Redis-cli.exe• Rdm.exe from http://redisdesktop.com/download• Redis Commander from http://joeferner.github.io/redis-commander/
Redis Data Types• Strings• Lists• Sets• Sorted sets• Hashes• Non-trivial, atomic operations on data
• Appends, increments, sorts, merges and many more
String CommandsRedis StackExchange.Redis
SETGETAPPENDINCRDECRGETRANGEMGETMSETSTRLEN
StringAppendStringBitCountStringBitOperationStringBitPositionStringDecrementStringIncrementStringGetStringGetBitStringGetRangeStringGetSetStringGetWithExpiryStringLengthStringSetStringSetBitStringSetRange
List CommandsRedis StackExchange.Redis
LPUSHRPUSHLREMLSETLINDEXLRANGELLENLPOPRPOPLTRIM
ListGetByIndexListInsertAfterListInsertBeforeListLeftPopListLeftPushListLengthListRangeListRemoveListRightPopListRightPopLeftPushListRightPushListSetByIndexListTrim
Set CommandsRedis StackExchange.Redis
SADDSCARDSDIFFSINTERSUNIONSISMEMBERSMEMBERSSMOVESREM
SetAddSetCombineSetCombineAndStoreSetContainsSetLengthSetMembersSetMoveSetPopSetRandomMemberSetRandomMembersSetRemoveSetScan
Sorted Set CommandsRedis StackExchange.Redis
ZADDZCARDZCOUNTZINCRBYZRANGEZRANKZREMZSCORE
SortAndStoreSortedSetAddSortedSetCombineAndStoreSortedSetDecrementSortedSetIncrementSortedSetLengthSortedSetLengthByValueSortedSetRangeByRankSortedSetRangeByRankWithScoreSortedSetRangeByValueSortedSetRankSortedSetRemoveSortedSetRemoveRangeByScoreSortedSetRemoveRangeByValueSortedSetScanSortedSetScore
Hash CommandsRedis StackExchange.Redis
HSETHMSETHGETHMGETHGETALLHDELHEXISTSHINCRBYHKEYSHVALS
HashDecrementHashIncrementHashDeleteHashExistsHashGetHashGetAllHashKeysHashLengthHashScanHashSetHashValues
Redis Eviction Policies• noeviction• allkeys-lru• volatile-lru• allkeys-random• volatile-random• volatile-ttl
Azure Redis Cache• Redis Cache hosted and managed by Microsoft• Dedicated virtual instance per cache• Multiple sizes up to 53GB• Tiers
• Basic: Single node, multiple sizes up to 53GB• Standard: Two node Master/Replica, 99.9% SLA, multiple sizes up to 53GB• Premium: Two-node Primary/Replica with up to 10 shards. Multiple sizes from 6 GB to 53 GB
(contact Microsoft for more).
• Available in all Azure Regions• SSL/non-SSL
Azure Redis Cache…• RBAC support• Provisioning Redis Cache
• Azure Management Portal• API• PowerShell
• Monitoring/Diagnostics• Alerts• ASP.NET Sessions and Output cache providers• Memcached protocol shim
Monitoring Azure Redis Cache• Monitor in the portal• Set eviction policies• Set alerts• Monitor using redis tools ex., redis-cli.exe
• High fragmentation
• Benchmarking using redis-benchmark.exe
Scaling Azure Redis Cache• Scale Up (Vertical Scaling)
• Increase cache size (memory), Bandwidth, CPU
• Scale Out (Horizontal Scaling)• Increased Cache Size, Bandwidth, CPU• Improved Availability, Replication, Clustering
• Things to know• You can't scale to or from a Premium cache.• You can't scale from a Standard cache to a Basic cache.• You can scale from a Basic cache to a Standard cache but you can't change the size at the same
time. If you need a different size, you can do a subsequent scaling operation to the desired size.• You can't scale from a larger size down to the C0 (250 MB) size.
Cache Patterns• Read-Through (RT) – caches data after reading them• Write-Through (WT) - writes data on cache update• Cache Aside is used when the caching provider offers no RT or WT capabilities
• Read from the cache first• Go to the data storage if cache “misses”• Invalidate cache upon data changes
• Retry Logic• Local cache
• Separate cache on each instance• Inconsistent results between instances• Very, very fast• Static or nearly staic data• Examples: Azure In-Role cache, .NET 4 MemoryCache
• Distributed Caching• Transactional or dynamic data• Common cache shared between instances• More scalable • Slower• Example: Managed Cache, Redis Cache
Best Practices• Select right Cache SKU
• Size, Availability, Netowrk Bandwidth, etc.,
• Always use latest version of StackExchange.Redis• Cache and Client should be in the same region• Set Expiration time: minimizes the stale data impact• Use Single instance of ConnectionMultiplexer• AbortOnConnectFail=false• ConnectRetry• Set ConnectionTimeout• Large values/Long running commands
• Use multiple connection multiplexers for different connection settings.
• Bench mark using redis-benchmark.exe• Pub/Sub is not recommended for reliable notification
Demo• Download Source from
• https://github.com/nhcloud/azureredis
Reference• //msdn.microsoft.com/en-us/library/dn589799.aspx• //msdn.microsoft.com/en-us/library/azure/dn766201.aspx• //azure.microsoft.com/en-us/documentation/articles/cache-configure• //msdn.microsoft.com/en-us/library/ff649918.aspx• //azure.microsoft.com/en
-us/blog/investigating-timeout-exceptions-in-stackexchange-redis-for-azure-redis-cache/• //
azure.microsoft.com/en-us/documentation/articles/web-sites-connect-to-redis-using-memcache-protocol/
• //redis.io/documentation• //github.com/MSOpenTech/redis/releases
Q & A
Thank you for attending New Hampshire - Nashua Cloud .NET User Group