SlideShare une entreprise Scribd logo
1  sur  27
Making (Almost) Any Database
Faster and Cheaper with Caching
Faster is Better!
DarinBriskman
AWSTechnical Evangelist
briskman@amazon.comor@briskmad
1
©2017, Amazon Web Services, I
nc. or its affiliates. All rights reser
ved
2
In-Memory Key-Value Store
High-performance
Redis and Memcached
Fully managed; Zero admin
Highly Available and Reliable
Hardened by Amazon
Demanding Real-Time Workloads
Thousands of Customers Implementing Large Scale Caching, Leaderboards,
Session Management, Messaging, Queuing and more
Gaming AdTech Media Mobile Other
Modern Applications Require Fast Performance
• We live in a connected world
• Phones, Tablets, Cars, Air Conditioners, Toasters, Drones …
• Experiences are increasingly contextual
• Analytics everywhere, for everything
• Apps need to provide real-time responses
• Database performance is frequently the bottleneck
• Loads are variable and unpredictable
Redis – the fast in-memory database
Powerful
~200 commands + Lua scripting
In-memory database
Utility data structures
strings, lists, hashes, sets, sorted sets,
bitmaps & HyperLogLogs
Simple
Atomic operations
supports transactions
has ACID properties
Ridiculously fast!
<500microsecond latency for
most commands
Highly Available
replication
Persistent
snapshots
Open Source
5
Current Version: 3.4.2 (Oct 2016)
One Simple Example ….
+
on-demand c3.8xlarge
3,000,000 objects
+
100 bytes each
memtier benchmark
50 read : 50 write
1,228,432 TPS
Source: http://highscalability.com/blog/2014/8/27/the-12m-opssec
-redis-cloud-cluster-single-server-unbenchmar.html
* Throughput determined by Requests per Second. Commands: Average% across SET, GET, INCR, LPUSH, RPUSH, LPOP, RPOP, SADD, SPOP, LPUSH, LRANGE_100, LRANGE_300, LRANGE_500, MSET was used.
Load: 1 Million Requests with Pipelined commands, Payload 3 bytes; Redis Instance compared: cache.m4.xlarge, cache.m3.xlarge; Same instance used to issue requests ( c4.xlarge with Redis Client/benchmark tool installed).
7
Passion for delivering constant innovation
ElastiCache for Redis delivers 34% greater throughput across various Redis commands using M4 instances vs. M3 instances.*
Amazon Web Services and Intel
8
Fully managed service = Automated Operations
Database hosted on Amazon EC2 Amazon Managed DBS
Amazon
ElastiCache
Redis Multi-AZ
Easy Monitoring via CloudWatch
Fully Managed
Enhanced Redis Engine
Easy to Deploy & Use
ElastiCache vs. Self-Managed Redis
No Cross-AZ Data Transfer Costs
Engineered For Cloud Scale
Clusters!
• Enables Horizontal Scaling
• In ElastiCache for Redis 3.2:
• a Cluster is one or more Shards
• a Shard is a primary node plus up to 5 replica nodes
• Up to 15 Shards per Cluster
• 15 r3.8xlarge = 3.5TiB!
• Up to 20 million reads per second
• Up to 4.5 million writes per second
• Cluster-level backup and restore
S5
S1
S2
S4 S3
Client
ElastiCache for Redis Cluster
Autosharding • 16384 hash slots per Cluster
• Slot for a key is CRC16 modulo {key}
• Slots are distributed across the Cluster into Shards
• Developers must use a Redis cluster client
• Clients are redirected to the correct shard
• Smart clients store a map
• Any open-source Redis cluster client will work
S5
S1
S2
S4 S3
Client
Shard S1 = slots 0 – 3276
Shard S2 = slots 3277 – 6553
Shard S3 = slots 6554 – 9829
Shard S4 = slots 9830 – 13106
Shard S5 = slots 13107 - 16383
ElastiCache for Redis Cluster
Faster Recovery • A Cluster consists of 1 – 15 Shards
• Each Shard has a primary node and up to 5 replica nodes
• In the event of a primary node outage, a replica node in
that Shard will be promoted
Primary
S1a
S1b S1c
S2a
S2b S2c
S3a
S3b S3c
Replica
Shard Shard Shard
X
S2c
S2a
ElastiCache for Redis Cluster
Data Types for Rapid Development
Redis Data Type Contains Read/write ability
String
Binary-safe strings (up to 512 MB), Integers or
floating point values, Bitmaps.
Operate on the whole string, parts, increment/decrement
the integers and floats, get/set bits by position.
Hash
Unordered hash table of keys to string
values
Add, fetch, or remove individual ítems by key, fetch the w
hole hash.
List Doubly linked list of strings
Push or pop items from both ends, trim based on offsets,
read individual or multiple items, find or remove items by
value.
Set Unordered collection of unique strings
Add, fetch, or remove individual items, check membership
, intersect, union, difference, fetch random items.
Sorted Set
Ordered mapping of string members to
floating-point scores, ordered by score
Add, fetch, or remove individual items, fetch items based
on score ranges or member value.
Geospatial
index
Sorted set implementation using geospatial
information as the score
Add, fetch or remove individual items, search by coordina
tes and radius, calculate distance.
HyperLogLog
Probabilistic data structure to count unique
things using 12Kb of memory
Add individual or multiple items, get the cardinality.
Value1Key1
Value2Key2
Lon.:
-103.55328
Lat.:
20.63373
Value
10000110
...10
I m a string!
...0000110
ACBD
CBCA
C: 250A: 250D: 0.3B: 0.1
Source:: https://cs.brown.edu/courses/cs227/archives/2011/slides/mar07-redis.pdf
Some Data Type Examples
Source: http://www.slideshare.net/FedericoDanielColomb/redis-introduction-54750742
14
Redis – Read/Write Connections
# Ruby example
redis_write = Redis.new(
'mygame-dev.z2vq55.ng.0001.usw2.cache.amazonaws.com')
redis_read = Redis::Distributed.new([
'mygame-dev-002.z2vq55.ng.0001.usw2.cache.amazonaws.com',
'mygame-dev-003.z2vq55.ng.0001.usw2.cache.amazonaws.com'
])
redis_write.zset("leaderboard", "nateware", 1976)
top_10 = redis_read.zrevrange("leaderboard", 0, -1)
Caching Pattern
Elastic Load
Balancing
EC2 App
Instances
RDS MySQL
DB Instance
ElastiCache
Database Writes
App
Reads
Clients
Cache
Updates
Database Reads
Caching Pattern
Elastic Load
Balancing
EC2 App
Instances
RDS MySQL
Database Writes
Clients
Database Reads
ElastiCache
App
Reads
Cache
Updates
IGA Works Uses ElastiCache to Power Real-Time App Monetization
By using RDS we saved on operations
cost for our relational databases. Using
ElastiCache we could boost the read
performance of RDS and offload the
massive request rate
Jeongsang Baek
VP Engineering, IGA Works
”
“
• IGA Works is Korea’s leading mobile business platform
• Adpopcorn is an ad monetization platform for mobile applications
that supports 130 million devices
• Storing Ad Inventory in ElastiCache in front of RDS guaranteed real-
time ad bidding and serving, while RDS provides the durable
database layer
Expedia’s Real-time Analytics Application Uses Amazon ElastiCache
Expedia is a leader in the $1 trillion travel industry, with an extensive portfolio that
includes some of the world’s most trusted travel brands.
With ElastiCache Redis as caching
layer, the write throughput on
DynamoDB has been set to 3500,
down from 35000, reducing the cost
by 6x.
Kuldeep Chowhan
Engineering Manager, Expedia
”
“ • Expedia’s real-time analytics application
collects data for its “test & learn” experiments
on Expedia sites.
• The analytics application processes ~200
million messages daily.
• Re:invent talk:
https://www.youtube.com/watch?v=ie4dWGT
76LM
Caching
Clients
Amazon
ElastiCache
Amazon
DynamoDB
Cache
Reads/Writes
DB
Reads/Writes
Elastic Load
Balancing
Amazon
EC2
Amazon
RDS
 Better Performance - Microseconds Speed
 Cost Effective
 Higher Throughput
DB
Reads/Writes
Query Caching
• For each query, check to see if the query is in the cache
• If so, return the result from the cache
• If not, query the database and cache the result
• Caching isn’t forever
• Use a TTL value to invalidate
• Invalidate-on-load using a trigger (or a Lambda function)
21
Example with PHP
if (isset($queryParam['search'])) {
$redis = new Client();
$hash = md5($_SERVER['QUERY_STRING']);
if (!$redis->get($hash . '-results')) {
[[insert database search here, generating '-results' and '-info']]
$redis->set($hash . '-results', serialize($search->call()));
$redis->expire($hash . '-results', 86400);
$redis->set($hash . '-info', serialize($search->call(true)));
$redis->expire($hash . '-info', 86400);
}
$results = unserialize($redis->get($hash . '-results'));
$info = unserialize($redis->get($hash . '-info'));
22
Data Caching
• Loading actual database rows (or items) into the cache
• Speedy access for high-load data
• Reduce the load on the database
• For smaller databases, cache the whole database!
23
Example with Python
import redis
r = redis.Redis(
host='hostname',
port=port,
password='password')
row = table.get(row_id)
r.set('row:' + row_id, json.dumps(row.to_dict())
24
Best Practices for Redis Cluster
• Use latest engine version – 3.2.4
• Use Redis Cluster (even for a single shard) to mitigate node failure impact
• Set reserved-memory to at least 10% of total available memory
• Swap usage should be zero or very low.
• Put read-replicas in a different AZ from the primary
• For important workloads use 2 read replicas per primary
• Write to the primary, read from the read-replicas
• Avoid “KEYS” command and other long running commands
26
In-Memory Key-Value Store
High-performance
Redis and Memcached
Fully managed; Zero admin
Highly Available and Reliable
Hardened by Amazon
https://s3-us-west-2.
amazonaws.com/
fastdata/ElastiCacheLab.zip
Lab Time!!

Contenu connexe

Tendances

Getting Started with Managed Database Services on AWS
Getting Started with Managed Database Services on AWSGetting Started with Managed Database Services on AWS
Getting Started with Managed Database Services on AWS
Amazon Web Services
 

Tendances (20)

Getting Started with Amazon ElastiCache
Getting Started with Amazon ElastiCacheGetting Started with Amazon ElastiCache
Getting Started with Amazon ElastiCache
 
Deep Dive: Amazon RDS
Deep Dive: Amazon RDSDeep Dive: Amazon RDS
Deep Dive: Amazon RDS
 
What’s New in Amazon Aurora
What’s New in Amazon AuroraWhat’s New in Amazon Aurora
What’s New in Amazon Aurora
 
AWS re:Invent 2016: Introduction to Managed Database Services on AWS (DAT307)
AWS re:Invent 2016: Introduction to Managed Database Services on AWS (DAT307)AWS re:Invent 2016: Introduction to Managed Database Services on AWS (DAT307)
AWS re:Invent 2016: Introduction to Managed Database Services on AWS (DAT307)
 
Managing Data with Voume Velocity, and Variety with Amazon ElastiCache for Redis
Managing Data with Voume Velocity, and Variety with Amazon ElastiCache for RedisManaging Data with Voume Velocity, and Variety with Amazon ElastiCache for Redis
Managing Data with Voume Velocity, and Variety with Amazon ElastiCache for Redis
 
Introduction to Amazon Relational Database Service
Introduction to Amazon Relational Database ServiceIntroduction to Amazon Relational Database Service
Introduction to Amazon Relational Database Service
 
Focus on your app with Amazon RDS
Focus on your app with Amazon RDSFocus on your app with Amazon RDS
Focus on your app with Amazon RDS
 
Getting Started with Managed Database Services on AWS
Getting Started with Managed Database Services on AWSGetting Started with Managed Database Services on AWS
Getting Started with Managed Database Services on AWS
 
BDA 302 Deep Dive on Migrating Big Data Workloads to Amazon EMR
BDA 302 Deep Dive on Migrating Big Data Workloads to Amazon EMRBDA 302 Deep Dive on Migrating Big Data Workloads to Amazon EMR
BDA 302 Deep Dive on Migrating Big Data Workloads to Amazon EMR
 
Deep Dive on Amazon RDS
Deep Dive on Amazon RDSDeep Dive on Amazon RDS
Deep Dive on Amazon RDS
 
What's New in Amazon RDS for Open Source and Commercial Databases
What's New in Amazon RDS for Open Source and Commercial DatabasesWhat's New in Amazon RDS for Open Source and Commercial Databases
What's New in Amazon RDS for Open Source and Commercial Databases
 
Optimize MySQL Workloads with Amazon Elastic Block Store - February 2017 AWS ...
Optimize MySQL Workloads with Amazon Elastic Block Store - February 2017 AWS ...Optimize MySQL Workloads with Amazon Elastic Block Store - February 2017 AWS ...
Optimize MySQL Workloads with Amazon Elastic Block Store - February 2017 AWS ...
 
Amazon Redshift Deep Dive
Amazon Redshift Deep Dive Amazon Redshift Deep Dive
Amazon Redshift Deep Dive
 
Introduction to Amazon Relational Database Service
Introduction to Amazon Relational Database ServiceIntroduction to Amazon Relational Database Service
Introduction to Amazon Relational Database Service
 
Amazon RDS & Amazon Aurora: Relational Databases on AWS - SRV206 - Atlanta AW...
Amazon RDS & Amazon Aurora: Relational Databases on AWS - SRV206 - Atlanta AW...Amazon RDS & Amazon Aurora: Relational Databases on AWS - SRV206 - Atlanta AW...
Amazon RDS & Amazon Aurora: Relational Databases on AWS - SRV206 - Atlanta AW...
 
Unleash the Power of Redis with Amazon ElastiCache
Unleash the Power of Redis with Amazon ElastiCache Unleash the Power of Redis with Amazon ElastiCache
Unleash the Power of Redis with Amazon ElastiCache
 
Amazon RDS for Microsoft SQL: Performance, Security, Best Practices (DAT303) ...
Amazon RDS for Microsoft SQL: Performance, Security, Best Practices (DAT303) ...Amazon RDS for Microsoft SQL: Performance, Security, Best Practices (DAT303) ...
Amazon RDS for Microsoft SQL: Performance, Security, Best Practices (DAT303) ...
 
Introduction to Amazon Relational Database Service
Introduction to Amazon Relational Database ServiceIntroduction to Amazon Relational Database Service
Introduction to Amazon Relational Database Service
 
Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)
 
Migrating to Amazon RDS with Database Migration Service
Migrating to Amazon RDS with Database Migration ServiceMigrating to Amazon RDS with Database Migration Service
Migrating to Amazon RDS with Database Migration Service
 

En vedette

En vedette (20)

Everything You Need for a Viral Game, Except the Game
Everything You Need for a Viral Game, Except the GameEverything You Need for a Viral Game, Except the Game
Everything You Need for a Viral Game, Except the Game
 
Deep Dive on Amazon DynamoDB
Deep Dive on Amazon DynamoDBDeep Dive on Amazon DynamoDB
Deep Dive on Amazon DynamoDB
 
Introduction to Amazon DynamoDB
Introduction to Amazon DynamoDBIntroduction to Amazon DynamoDB
Introduction to Amazon DynamoDB
 
Migrating to Amazon RDS with Database Migration Service
Migrating to Amazon RDS with Database Migration ServiceMigrating to Amazon RDS with Database Migration Service
Migrating to Amazon RDS with Database Migration Service
 
Telenor Connexion
Telenor Connexion Telenor Connexion
Telenor Connexion
 
What’s New in Amazon Aurora for MySQL and PostgreSQL
What’s New in Amazon Aurora for MySQL and PostgreSQLWhat’s New in Amazon Aurora for MySQL and PostgreSQL
What’s New in Amazon Aurora for MySQL and PostgreSQL
 
Introduction to Amazon Relational Database Service
Introduction to Amazon Relational Database ServiceIntroduction to Amazon Relational Database Service
Introduction to Amazon Relational Database Service
 
Cost Optimisation on AWS
Cost Optimisation on AWSCost Optimisation on AWS
Cost Optimisation on AWS
 
Hive: A Cloud Story
Hive: A Cloud StoryHive: A Cloud Story
Hive: A Cloud Story
 
Partnering with AWS
Partnering with AWSPartnering with AWS
Partnering with AWS
 
Opening Keynote
Opening Keynote Opening Keynote
Opening Keynote
 
Best Practices for Migrating your Data Warehouse to Amazon Redshift
Best Practices for Migrating your Data Warehouse to Amazon RedshiftBest Practices for Migrating your Data Warehouse to Amazon Redshift
Best Practices for Migrating your Data Warehouse to Amazon Redshift
 
AWS re:Invent 2016: AWS Database State of the Union (DAT320)
AWS re:Invent 2016: AWS Database State of the Union (DAT320)AWS re:Invent 2016: AWS Database State of the Union (DAT320)
AWS re:Invent 2016: AWS Database State of the Union (DAT320)
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 
Building A Modern Data Analytics Architecture on AWS
Building A Modern Data Analytics Architecture on AWSBuilding A Modern Data Analytics Architecture on AWS
Building A Modern Data Analytics Architecture on AWS
 
Introducing Amazon Lex – A Service for Building Voice or Text Chatbots - Marc...
Introducing Amazon Lex – A Service for Building Voice or Text Chatbots - Marc...Introducing Amazon Lex – A Service for Building Voice or Text Chatbots - Marc...
Introducing Amazon Lex – A Service for Building Voice or Text Chatbots - Marc...
 
Streaming Data Analytics with Amazon Redshift and Kinesis Firehose
Streaming Data Analytics with Amazon Redshift and Kinesis FirehoseStreaming Data Analytics with Amazon Redshift and Kinesis Firehose
Streaming Data Analytics with Amazon Redshift and Kinesis Firehose
 
AWS Black Belt Online Seminar 2017 Auto Scaling
AWS Black Belt Online Seminar 2017 Auto ScalingAWS Black Belt Online Seminar 2017 Auto Scaling
AWS Black Belt Online Seminar 2017 Auto Scaling
 
AWS Services Overview
AWS Services OverviewAWS Services Overview
AWS Services Overview
 
AWS re:Invent 2016: Design Patterns for High Availability: Lessons from Amazo...
AWS re:Invent 2016: Design Patterns for High Availability: Lessons from Amazo...AWS re:Invent 2016: Design Patterns for High Availability: Lessons from Amazo...
AWS re:Invent 2016: Design Patterns for High Availability: Lessons from Amazo...
 

Similaire à Making (Almost) Any Database Faster and Cheaper with Caching

Spilo, отказоустойчивый PostgreSQL кластер / Oleksii Kliukin (Zalando SE)
Spilo, отказоустойчивый PostgreSQL кластер / Oleksii Kliukin (Zalando SE)Spilo, отказоустойчивый PostgreSQL кластер / Oleksii Kliukin (Zalando SE)
Spilo, отказоустойчивый PostgreSQL кластер / Oleksii Kliukin (Zalando SE)
Ontico
 

Similaire à Making (Almost) Any Database Faster and Cheaper with Caching (20)

Making (Almost) Any Database Faster and Cheaper with Caching
Making (Almost) Any Database Faster and Cheaper with CachingMaking (Almost) Any Database Faster and Cheaper with Caching
Making (Almost) Any Database Faster and Cheaper with Caching
 
Fast Data at Scale with Amazon ElastiCache for Redis
Fast Data at Scale with Amazon ElastiCache for RedisFast Data at Scale with Amazon ElastiCache for Redis
Fast Data at Scale with Amazon ElastiCache for Redis
 
Getting started with Amazon ElastiCache
Getting started with Amazon ElastiCacheGetting started with Amazon ElastiCache
Getting started with Amazon ElastiCache
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDBAgility and Scalability with MongoDB
Agility and Scalability with MongoDB
 
Day 4 - Big Data on AWS - RedShift, EMR & the Internet of Things
Day 4 - Big Data on AWS - RedShift, EMR & the Internet of ThingsDay 4 - Big Data on AWS - RedShift, EMR & the Internet of Things
Day 4 - Big Data on AWS - RedShift, EMR & the Internet of Things
 
Getting Started with Amazon Redshift
Getting Started with Amazon RedshiftGetting Started with Amazon Redshift
Getting Started with Amazon Redshift
 
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
AWS re:Invent 2016: ElastiCache Deep Dive: Best Practices and Usage Patterns ...
 
Amazon Elasticache Deep Dive - March 2017 AWS Online Tech Talks
Amazon Elasticache Deep Dive - March 2017 AWS Online Tech TalksAmazon Elasticache Deep Dive - March 2017 AWS Online Tech Talks
Amazon Elasticache Deep Dive - March 2017 AWS Online Tech Talks
 
ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...
ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...
ElastiCache Deep Dive: Best Practices and Usage Patterns - March 2017 AWS Onl...
 
Getting Started with Amazon Redshift
Getting Started with Amazon RedshiftGetting Started with Amazon Redshift
Getting Started with Amazon Redshift
 
C* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag Jambhekar
C* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag JambhekarC* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag Jambhekar
C* Summit 2013: Cassandra at eBay Scale by Feng Qu and Anurag Jambhekar
 
Spilo, отказоустойчивый PostgreSQL кластер / Oleksii Kliukin (Zalando SE)
Spilo, отказоустойчивый PostgreSQL кластер / Oleksii Kliukin (Zalando SE)Spilo, отказоустойчивый PostgreSQL кластер / Oleksii Kliukin (Zalando SE)
Spilo, отказоустойчивый PostgreSQL кластер / Oleksii Kliukin (Zalando SE)
 
Data & Analytics - Session 2 - Introducing Amazon Redshift
Data & Analytics - Session 2 - Introducing Amazon RedshiftData & Analytics - Session 2 - Introducing Amazon Redshift
Data & Analytics - Session 2 - Introducing Amazon Redshift
 
Getting Started with Amazon Redshift
Getting Started with Amazon RedshiftGetting Started with Amazon Redshift
Getting Started with Amazon Redshift
 
(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services
(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services
(DAT204) NoSQL? No Worries: Build Scalable Apps on AWS NoSQL Services
 
Unleash the Power of Redis with Amazon ElastiCache
Unleash the Power of Redis with Amazon ElastiCacheUnleash the Power of Redis with Amazon ElastiCache
Unleash the Power of Redis with Amazon ElastiCache
 
BDA402 Deep Dive: Log Analytics with Amazon Elasticsearch Service
BDA402 Deep Dive: Log Analytics with Amazon Elasticsearch ServiceBDA402 Deep Dive: Log Analytics with Amazon Elasticsearch Service
BDA402 Deep Dive: Log Analytics with Amazon Elasticsearch Service
 
AWS를 활용한 첫 빅데이터 프로젝트 시작하기(김일호)- AWS 웨비나 시리즈 2015
AWS를 활용한 첫 빅데이터 프로젝트 시작하기(김일호)- AWS 웨비나 시리즈 2015AWS를 활용한 첫 빅데이터 프로젝트 시작하기(김일호)- AWS 웨비나 시리즈 2015
AWS를 활용한 첫 빅데이터 프로젝트 시작하기(김일호)- AWS 웨비나 시리즈 2015
 
AWS Webcast - Managing Big Data in the AWS Cloud_20140924
AWS Webcast - Managing Big Data in the AWS Cloud_20140924AWS Webcast - Managing Big Data in the AWS Cloud_20140924
AWS Webcast - Managing Big Data in the AWS Cloud_20140924
 
Fast Data at Scale - AWS Summit Tel Aviv 2017
Fast Data at Scale - AWS Summit Tel Aviv 2017Fast Data at Scale - AWS Summit Tel Aviv 2017
Fast Data at Scale - AWS Summit Tel Aviv 2017
 

Plus de Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

Plus de Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Dernier

Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
raffaeleoman
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
amilabibi1
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
Sheetaleventcompany
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
Kayode Fayemi
 

Dernier (20)

The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
Causes of poverty in France presentation.pptx
Causes of poverty in France presentation.pptxCauses of poverty in France presentation.pptx
Causes of poverty in France presentation.pptx
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animals
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 

Making (Almost) Any Database Faster and Cheaper with Caching

  • 1. Making (Almost) Any Database Faster and Cheaper with Caching Faster is Better! DarinBriskman AWSTechnical Evangelist briskman@amazon.comor@briskmad 1 ©2017, Amazon Web Services, I nc. or its affiliates. All rights reser ved
  • 2. 2 In-Memory Key-Value Store High-performance Redis and Memcached Fully managed; Zero admin Highly Available and Reliable Hardened by Amazon
  • 3. Demanding Real-Time Workloads Thousands of Customers Implementing Large Scale Caching, Leaderboards, Session Management, Messaging, Queuing and more Gaming AdTech Media Mobile Other
  • 4. Modern Applications Require Fast Performance • We live in a connected world • Phones, Tablets, Cars, Air Conditioners, Toasters, Drones … • Experiences are increasingly contextual • Analytics everywhere, for everything • Apps need to provide real-time responses • Database performance is frequently the bottleneck • Loads are variable and unpredictable
  • 5. Redis – the fast in-memory database Powerful ~200 commands + Lua scripting In-memory database Utility data structures strings, lists, hashes, sets, sorted sets, bitmaps & HyperLogLogs Simple Atomic operations supports transactions has ACID properties Ridiculously fast! <500microsecond latency for most commands Highly Available replication Persistent snapshots Open Source 5 Current Version: 3.4.2 (Oct 2016)
  • 6. One Simple Example …. + on-demand c3.8xlarge 3,000,000 objects + 100 bytes each memtier benchmark 50 read : 50 write 1,228,432 TPS Source: http://highscalability.com/blog/2014/8/27/the-12m-opssec -redis-cloud-cluster-single-server-unbenchmar.html
  • 7. * Throughput determined by Requests per Second. Commands: Average% across SET, GET, INCR, LPUSH, RPUSH, LPOP, RPOP, SADD, SPOP, LPUSH, LRANGE_100, LRANGE_300, LRANGE_500, MSET was used. Load: 1 Million Requests with Pipelined commands, Payload 3 bytes; Redis Instance compared: cache.m4.xlarge, cache.m3.xlarge; Same instance used to issue requests ( c4.xlarge with Redis Client/benchmark tool installed). 7 Passion for delivering constant innovation ElastiCache for Redis delivers 34% greater throughput across various Redis commands using M4 instances vs. M3 instances.* Amazon Web Services and Intel
  • 8. 8 Fully managed service = Automated Operations Database hosted on Amazon EC2 Amazon Managed DBS
  • 9. Amazon ElastiCache Redis Multi-AZ Easy Monitoring via CloudWatch Fully Managed Enhanced Redis Engine Easy to Deploy & Use ElastiCache vs. Self-Managed Redis No Cross-AZ Data Transfer Costs Engineered For Cloud Scale
  • 10. Clusters! • Enables Horizontal Scaling • In ElastiCache for Redis 3.2: • a Cluster is one or more Shards • a Shard is a primary node plus up to 5 replica nodes • Up to 15 Shards per Cluster • 15 r3.8xlarge = 3.5TiB! • Up to 20 million reads per second • Up to 4.5 million writes per second • Cluster-level backup and restore S5 S1 S2 S4 S3 Client ElastiCache for Redis Cluster
  • 11. Autosharding • 16384 hash slots per Cluster • Slot for a key is CRC16 modulo {key} • Slots are distributed across the Cluster into Shards • Developers must use a Redis cluster client • Clients are redirected to the correct shard • Smart clients store a map • Any open-source Redis cluster client will work S5 S1 S2 S4 S3 Client Shard S1 = slots 0 – 3276 Shard S2 = slots 3277 – 6553 Shard S3 = slots 6554 – 9829 Shard S4 = slots 9830 – 13106 Shard S5 = slots 13107 - 16383 ElastiCache for Redis Cluster
  • 12. Faster Recovery • A Cluster consists of 1 – 15 Shards • Each Shard has a primary node and up to 5 replica nodes • In the event of a primary node outage, a replica node in that Shard will be promoted Primary S1a S1b S1c S2a S2b S2c S3a S3b S3c Replica Shard Shard Shard X S2c S2a ElastiCache for Redis Cluster
  • 13. Data Types for Rapid Development Redis Data Type Contains Read/write ability String Binary-safe strings (up to 512 MB), Integers or floating point values, Bitmaps. Operate on the whole string, parts, increment/decrement the integers and floats, get/set bits by position. Hash Unordered hash table of keys to string values Add, fetch, or remove individual ítems by key, fetch the w hole hash. List Doubly linked list of strings Push or pop items from both ends, trim based on offsets, read individual or multiple items, find or remove items by value. Set Unordered collection of unique strings Add, fetch, or remove individual items, check membership , intersect, union, difference, fetch random items. Sorted Set Ordered mapping of string members to floating-point scores, ordered by score Add, fetch, or remove individual items, fetch items based on score ranges or member value. Geospatial index Sorted set implementation using geospatial information as the score Add, fetch or remove individual items, search by coordina tes and radius, calculate distance. HyperLogLog Probabilistic data structure to count unique things using 12Kb of memory Add individual or multiple items, get the cardinality. Value1Key1 Value2Key2 Lon.: -103.55328 Lat.: 20.63373 Value 10000110 ...10 I m a string! ...0000110 ACBD CBCA C: 250A: 250D: 0.3B: 0.1 Source:: https://cs.brown.edu/courses/cs227/archives/2011/slides/mar07-redis.pdf
  • 14. Some Data Type Examples Source: http://www.slideshare.net/FedericoDanielColomb/redis-introduction-54750742 14
  • 15. Redis – Read/Write Connections # Ruby example redis_write = Redis.new( 'mygame-dev.z2vq55.ng.0001.usw2.cache.amazonaws.com') redis_read = Redis::Distributed.new([ 'mygame-dev-002.z2vq55.ng.0001.usw2.cache.amazonaws.com', 'mygame-dev-003.z2vq55.ng.0001.usw2.cache.amazonaws.com' ]) redis_write.zset("leaderboard", "nateware", 1976) top_10 = redis_read.zrevrange("leaderboard", 0, -1)
  • 16. Caching Pattern Elastic Load Balancing EC2 App Instances RDS MySQL DB Instance ElastiCache Database Writes App Reads Clients Cache Updates Database Reads
  • 17. Caching Pattern Elastic Load Balancing EC2 App Instances RDS MySQL Database Writes Clients Database Reads ElastiCache App Reads Cache Updates
  • 18. IGA Works Uses ElastiCache to Power Real-Time App Monetization By using RDS we saved on operations cost for our relational databases. Using ElastiCache we could boost the read performance of RDS and offload the massive request rate Jeongsang Baek VP Engineering, IGA Works ” “ • IGA Works is Korea’s leading mobile business platform • Adpopcorn is an ad monetization platform for mobile applications that supports 130 million devices • Storing Ad Inventory in ElastiCache in front of RDS guaranteed real- time ad bidding and serving, while RDS provides the durable database layer
  • 19. Expedia’s Real-time Analytics Application Uses Amazon ElastiCache Expedia is a leader in the $1 trillion travel industry, with an extensive portfolio that includes some of the world’s most trusted travel brands. With ElastiCache Redis as caching layer, the write throughput on DynamoDB has been set to 3500, down from 35000, reducing the cost by 6x. Kuldeep Chowhan Engineering Manager, Expedia ” “ • Expedia’s real-time analytics application collects data for its “test & learn” experiments on Expedia sites. • The analytics application processes ~200 million messages daily. • Re:invent talk: https://www.youtube.com/watch?v=ie4dWGT 76LM
  • 21. Query Caching • For each query, check to see if the query is in the cache • If so, return the result from the cache • If not, query the database and cache the result • Caching isn’t forever • Use a TTL value to invalidate • Invalidate-on-load using a trigger (or a Lambda function) 21
  • 22. Example with PHP if (isset($queryParam['search'])) { $redis = new Client(); $hash = md5($_SERVER['QUERY_STRING']); if (!$redis->get($hash . '-results')) { [[insert database search here, generating '-results' and '-info']] $redis->set($hash . '-results', serialize($search->call())); $redis->expire($hash . '-results', 86400); $redis->set($hash . '-info', serialize($search->call(true))); $redis->expire($hash . '-info', 86400); } $results = unserialize($redis->get($hash . '-results')); $info = unserialize($redis->get($hash . '-info')); 22
  • 23. Data Caching • Loading actual database rows (or items) into the cache • Speedy access for high-load data • Reduce the load on the database • For smaller databases, cache the whole database! 23
  • 24. Example with Python import redis r = redis.Redis( host='hostname', port=port, password='password') row = table.get(row_id) r.set('row:' + row_id, json.dumps(row.to_dict()) 24
  • 25. Best Practices for Redis Cluster • Use latest engine version – 3.2.4 • Use Redis Cluster (even for a single shard) to mitigate node failure impact • Set reserved-memory to at least 10% of total available memory • Swap usage should be zero or very low. • Put read-replicas in a different AZ from the primary • For important workloads use 2 read replicas per primary • Write to the primary, read from the read-replicas • Avoid “KEYS” command and other long running commands
  • 26. 26 In-Memory Key-Value Store High-performance Redis and Memcached Fully managed; Zero admin Highly Available and Reliable Hardened by Amazon