High-Availability: cache and queue 
2014-07-24 
Truc Le - afterlastangel@gmail.com
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 
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 seconds 
Serialize and & Unserialize for object storage 
2014-07-24 High-Availability: cache and queue
Benchmark method 
Tool : siege 
API URL : 20 
Deployment on AWS 
EC2 (ubuntu) : t2.micro 
RDS (mysql) : db.t1.micro 
ElasticCache (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 RDS 
Cache 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
Architecture 
2014-07-24 High-Availability: cache and queue
Compare with traditional 
2014-07-24 High-Availability: cache and queue
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

High availability system cache and queue - Write behind

  • 1.
    High-Availability: cache andqueue 2014-07-24 Truc Le - afterlastangel@gmail.com
  • 2.
    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
  • 3.
    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
  • 4.
    Caching • Cachecan 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
  • 5.
    Simple implementation Nocache 2014-07-24 High-Availability: cache and queue
  • 6.
    Get cache 2014-07-24High-Availability: cache and queue
  • 7.
    Use & Setcache Expired time 60 seconds Serialize and & Unserialize for object storage 2014-07-24 High-Availability: cache and queue
  • 8.
    Benchmark method Tool: siege API URL : 20 Deployment on AWS EC2 (ubuntu) : t2.micro RDS (mysql) : db.t1.micro ElasticCache (redis) : cache.t1.micro 2014-07-24 High-Availability: cache and queue
  • 9.
    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
  • 10.
    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
  • 11.
    Log details 2014-07-24High-Availability: cache and queue 96 empty responses
  • 12.
    Conclusion - Toomany connections (>32) - To increase max connections need larger RDS Cache helps: ● Save money ● More concurrent user ● Faster delivery 2014-07-24 High-Availability: cache and queue
  • 13.
    What could becached? • Database query • Variable & Object • View page & Template • API 2014-07-24 High-Availability: cache and queue
  • 14.
    Redis is morethan 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
  • 15.
    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
  • 16.
  • 17.
    Compare with traditional 2014-07-24 High-Availability: cache and queue
  • 18.
    Running demo queue 2014-07-24 High-Availability: cache and queue
  • 19.
    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
  • 20.
  • 21.
    Amazon Simple QueueService • 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
  • 22.