High-Availability: cache and queue
2014-07-24Truc Le - [email protected]
Executive Summary
• The objective of this presentation is fundamental web development method using the cache.
• Optimization code to reduce resource cost and make website faster.
• Amazon Web Services for Cache and Queue
2014-07-24 High-Availability: cache and queue
Outline• Cache
• Simple example & Benchmark
• Queue & Write behind
• Simple worker demo
• Amazon Web Services for Cache and Queue
• Scalability
2014-07-24 High-Availability: cache and queue
Caching
• Cache can help reduce database loads.
• Instead of going to the database, data can be loaded from in-memory cache
• Times faster than database.
2014-07-24 High-Availability: cache and queue
Simple implementation
2014-07-24 High-Availability: cache and queue
No cache
2014-07-24 High-Availability: cache and queue
Get cache
2014-07-24 High-Availability: cache and queue
Use & Set cache
Expired time 60 secondsSerialize and & Unserialize for object storage
Benchmark method
Tool : siegeAPI URL : 20
Deployment on AWSEC2 (ubuntu) : t2.microRDS (mysql) : db.t1.microElasticCache (redis) : cache.t1.micro
2014-07-24 High-Availability: cache and queue
Result
Concurrent User: 50 - Delay: 10 - Repeat: 2
Cache vs (No cache)Elapsed time : 20.13 secs ( 27.97)Response time : 0.93 secs ( 4.23 )Transaction rate : 4.97 trans/sec ( 3.58 )
2014-07-24 High-Availability: cache and queue
Result
Concurrent User: 100 - Delay: 10 - Repeat: 2
Cache vs (No cache)Elapsed time : 30.97 secs ( 27.10) ???Response time : 5 secs ( 3.84 ) ???Transaction rate : 6.46 trans/sec ( 7.38 ) ???
2014-07-24 High-Availability: cache and queue
Log details
2014-07-24 High-Availability: cache and queue
96 empty responses
Conclusion
- Too many connections (>32)- To increase max connections need larger RDSCache helps:● Save money● More concurrent user● Faster delivery
2014-07-24 High-Availability: cache and queue
What could be cached?
• Database query• Variable & Object• View page & Template• API
2014-07-24 High-Availability: cache and queue
Redis is more than cache
• It's a "NoSQL" key-value data stores• It's a data structures server
Applications: Counting stuff, Pub/Sub, Queues, Real time analysis, Leaderboards and related problems ...
2014-07-24 High-Availability: cache and queue
Queue & Write-Behind● Offload database writes● Spread writes out to flatten peaks● Consolidate multiple writes into fewer database writes● Being disconnected from the DB will let the frontend keep
running if the DB is down!
2014-07-24 High-Availability: cache and queue
2014-07-24 High-Availability: cache and queue
Architecture
2014-07-24 High-Availability: cache and queue
Compare with traditional
Running demo queue
2014-07-24 High-Availability: cache and queue
Amazon ElasticCache
• Saves administrative cost
• Provides replication features for the Redis engine
• Automatically detects and replaces failed nodes
• Availability Zone redundancy
2014-07-24 High-Availability: cache and queue
2014-07-24 High-Availability: cache and queue
Amazon Simple Queue Service
• Runs within Amazon’s high-availability data centers
• All messages are stored redundantly across multiple servers and data centers
• Unlimited number of services to read and write
• Unlimited number of messages at any time
• Inexpensive
2014-07-24 High-Availability: cache and queue
Scalability
2014-07-24 High-Availability: cache and queue