Amazon ElastiCache
ElastiCache can improve overall performance of the application
In-Memory Data Cache - The primary purpose of an in-memory key-value store is to provide ultra-fast and inexpensive access to copies of data.
What Should be Cached ?
- Speed and Expense need to be considered - its slower to get data from databases than from cache
- Data and Access Pattern - No point to cache rapidly changing or seldom accessed data
- Staleness - Cached data is stale data - application tolerance for stale data need to be considered
Consider caching your data if:
it is slow or expensive to acquire
it is accessed with sufficient frequency
it is relatively static or staleness is not an issue
Redis -
Redis sorted lists - allow for Gaming leader boards -
Can use ZADD and ZREVRANGEBYSCORE
eg:
ZADD leaderboard 132 Robert
ZADD leaderboard 231 Sandra
ZREVRANGEBYSCORE leaderboard +inf -inf
Redis Publisher/Subscriber - Messaging - http://redis.io/topics/pubsub
- using single channel subscription
SUBSCRIBE news.sports
UNSUBSCRIBE news.sports
- allows subscription to multiple specified channels
- cancel all subscriptions UNSUBSCRIBE
- Subscriptions using Pattern Matching
PSUBSCRIBE news.sports.*
PUNSUBSCRIBE news.sports.*
- publishing to the channel/sPUBLISH news.sports "Hello."
Recommendation Data (Redis Counters & Hashes)
Using redis counters you can increment on a like and decrement on a dislike
and also using hashes you can maintain a list of everyone who has liked or disliked
Memcached vs Redis
Memecache is a widely adopted in-memory key store, no disk persistence
The primary goal of caching is typically to offload reads from your database or other primary data source.
Redis - open source key value store supports advanced data structures and has disk persistence built in, redis elasticache clusters are managed as stateful entities that include failover, similar to amazon rds manages database failover.
• Is object caching your primary goal, for example to offload your database? If so, use Memcached.
• Are you interested in as simple a caching model as possible? If so, use Memcached.
• Are you planning on running large cache nodes, and require multithreaded performance with utilization of multiple cores? If so, use Memcached.
• Do you want the ability to scale your cache horizontally as you grow? If so, use Memcached.
• Does your app need to atomically increment or decrement counters? If so, use either Redis or Memcached.
• Are you looking for more advanced data types, such as lists, hashes, and sets? If so, use Redis.
• Does sorting and ranking datasets in memory help you, such as with leaderboards? If so, use Redis.
• Are publish and subscribe (pub/sub) capabilities of use to your application? If so, use Redis.
• Is persistence of your key store important? If so, use Redis.
• Do you want to run in multiple AWS Availability Zones (Multi-AZ) with failover? If so, use Redis.
https://d0.awsstatic.com/whitepapers/performance-at-scale-with-amazon-elasticache.pdf
Take Advantage of Redis Adding to your stack
http://oldblog.antirez.com/post/take-advantage-of-redis-adding-it-to-your-stack.html
Guide to ElastiCache
https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/UseCases.html
Comments
Post a Comment