SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
SHARDING REDIS at FLITE
Eugene Feingold & Chakri Kodali
WHAT IS FLITE?
•  Display advertising platform
•  Create and publish rich,
interactive ads
•  Serve ad impressions
•  Collect and analyze metrics,
batch AND realtime
WHAT IS FLITE?
•  Display advertising platform
•  Create and publish rich,
interactive ads
•  Serve ad impressions
•  Collect and analyze metrics,
batch AND realtime
with
REALTIME YOU SAY?
•  Realtime monitoring of ad performance
•  Debugging of ads, with instant feedback on triggered events
METRICS ARCHITECTURE
JVM
JVM
JVM
ad
ad
ad
ad
ad
ad
ad
node.js
node.js
pipelined write of ~30 items
WRITING TO REDIS
Persistence: Up to 4 hours for most data
Amount: ~30 writes per event, pipelined
Granularity: By second, minute, hour
Write Types:
•  HSET - JSON blobs (Event body data)
•  LPUSH - Lists of events (Events by session)
•  HINCRBY - Simple counters (Events by ad)
•  ZINCRBY - Sorted set counters (To retrieve “Top 100”)
•  PUBSUB - Stream event data (Debugger)
READING FROM REDIS
Redis transactions are used extensively like multi, exec
Read types:
•  HGETALL - get all data for event
•  HGET - get event counts by ad
•  LRANGE - list of all events by session
•  ZREVRANGE - top 100 ads with highest number of events
•  SUBSCRIBE
AND ALL OF THIS AT SCALE
•  Daily traffic peaks: 100k - 200k events per minute
•  Peaks are really plateaus that last for hours
•  Read load is negligible by comparison, but reads must be fast
•  In fact, everything must be fast: <1 sec latency for debugger to work
WHAT’S WRONG WITH THIS PICTURE?
JVM
JVM
JVM
ad
ad
ad
ad
ad
ad
ad
node.js
node.js
WHAT’S WRONG WITH THIS PICTURE?
Bottleneck!
JVM
JVM
JVM
ad
ad
ad
ad
ad
ad
ad
node.js
node.js
SCALABILITY FAIL!
What did it look like?
2-3x of our usual load
SCALABILITY FAIL!
Note how only 1 core is being used 14,000 open connections!
What did it look like?
A QUICK SOLUTION?
•  MOAR Megahurtz!!: m2.2xl is already about as fast as Amazon gets.
•  Redis-As-A-Service: Expensive, not fast enough for even our usual load.
•  twemproxy: Twitter’s sharding solution.
Doesn’t support all commands: PING, MULTI, INFO, MGET, etc…
WHAT ABOUT JEDIS’S NATIVE SHARDING?
•  No pipelining
•  No pubsub
•  Complicated consistent hashing mechanism makes reading in other
environments more difficult
LET’S ROLL OUR OWN!
Goals: Speed, speed, speed
Not Goals: Fault tolerance, redundancy, resiliency
HOW HARD CAN IT BE?
Sharding method: Java hashCode of key for every item written
JVMad
event items
node.js
Write to many Read from one
WHAT HAPPENED?
Before Sharding After Sharding
Items per Event 30 30
Items written per Event per Redis 30 10
Redis Connections per Event 1 3
Connections per second per Redis box n n
Reality: When n gets to around 500, Redis maxes out CPU and starts rejecting connections.
Theory: Since Redis claims to be able to handle 70k connections per second, the amount of
data being sent per connection is the problem.
SO HOW HARD CAN IT BE?
HARD.
TAKE TWO
Sharding method: Java hashCode of EVENT key for every item written.
A single key now lives on multiple Redis boxes
JVMad
event items
node.js
Write to one Read from many
BETTER!
Before Sharding After Take 1 After Take 2
Items per Event 30 30 30
Items written per Event per Redis 30 10 30
Redis Connections per Event 1 3 1
Connections per second per Redis box n n n/3
More load can be easily accommodated by adding boxes
CODING CHALLENGES
Java
•  Managing multiple connection pools
•  Managing multiple pipelines
•  Automatic health checks
node.js
•  Finding hashing function that works in different environments
•  Managing multiple pipelines
•  Fanout requests and merging response once pipeline is
executed
SINGLE-REDIS JEDIS WORKFLOW
On application startup:
1.  Initialize jedisPool with connection info
Every time:
1.  Jedis jedisClient = jedisPool.getClient();
2.  Pipeline pipeline = jedisClient.pipelined();
3.  State your business
4.  pipeline.sync();
5.  jedisPool.returnResource(jedisClient);
SHARDED JEDIS WORKFLOW
On application startup:
1.  Initialize n jedisPools with connection info
Every time:
1.  Jedis jedisClient = jedisPool.getClient();
2.  Pipeline pipeline = jedisClient.pipelined();
3.  State your business
4.  pipeline.sync();
5.  jedisPool.returnResource(jedisClient);
SHARDED JEDIS WORKFLOW
On application startup:
1.  Initialize n jedisPools with connection info
Every time:
1.  Jedis jedisClient = jedisPool.getClient(); Which pool?
2.  Pipeline pipeline = jedisClient.pipelined(); Which client?
3.  State your business To whom?
4.  pipeline.sync(); Which pipeline?
5.  jedisPool.returnResource(jedisClient); Return what where?
SHARDED JEDIS WORKFLOW
RedisNodeManager
Spring-created singleton
JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager
SHARDED JEDIS WORKFLOW
RedisNodeManager
Spring-created singleton
JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager
RedisPipelineManager JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager
getPipelineManager()
SHARDED JEDIS WORKFLOW
RedisNodeManager
Spring-created singleton
JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager
RedisPipelineManager JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager
Pipeline
getPipelineManager()
getPipeline(shardKey)
LET’S LOOK AT SOME CODE!
OPERATIONAL DETAILS
•  Redis is single threaded
o  You can run multiple Redises on one server
o  Bind each Redis instance to a specific core
QUESTIONS?

Contenu connexe

Tendances

node.js, javascript and the future
node.js, javascript and the futurenode.js, javascript and the future
node.js, javascript and the futureJeff Miccolis
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRob O'Doherty
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs Irfan Maulana
 
Create a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBCreate a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBHengki Sihombing
 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrencypgriess
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven ProgrammingKamal Hussain
 
Understand How Node.js and Core Features Works
Understand How Node.js and Core Features WorksUnderstand How Node.js and Core Features Works
Understand How Node.js and Core Features WorksHengki Sihombing
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJSHüseyin BABAL
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming Tom Croucher
 
Frontera распределенный робот для обхода веба в больших объемах / Александр С...
Frontera распределенный робот для обхода веба в больших объемах / Александр С...Frontera распределенный робот для обхода веба в больших объемах / Александр С...
Frontera распределенный робот для обхода веба в больших объемах / Александр С...Ontico
 
Тарас Кирилюк — Docker basics. How-to for Drupal developers
Тарас Кирилюк — Docker basics. How-to for Drupal developersТарас Кирилюк — Docker basics. How-to for Drupal developers
Тарас Кирилюк — Docker basics. How-to for Drupal developersLEDC 2016
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJSJITENDRA KUMAR PATEL
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)Chris Cowan
 
Node.js tutoria for beginner
Node.js tutoria for beginnerNode.js tutoria for beginner
Node.js tutoria for beginnerManinder Singh
 

Tendances (20)

node.js, javascript and the future
node.js, javascript and the futurenode.js, javascript and the future
node.js, javascript and the future
 
Vert.x
Vert.xVert.x
Vert.x
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Create Rest API in Nodejs
Create Rest API in Nodejs Create Rest API in Nodejs
Create Rest API in Nodejs
 
Create a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBCreate a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDB
 
NodeJS Concurrency
NodeJS ConcurrencyNodeJS Concurrency
NodeJS Concurrency
 
Server Side Event Driven Programming
Server Side Event Driven ProgrammingServer Side Event Driven Programming
Server Side Event Driven Programming
 
Node
NodeNode
Node
 
Understand How Node.js and Core Features Works
Understand How Node.js and Core Features WorksUnderstand How Node.js and Core Features Works
Understand How Node.js and Core Features Works
 
Node.js for beginner
Node.js for beginnerNode.js for beginner
Node.js for beginner
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
 
Frontera распределенный робот для обхода веба в больших объемах / Александр С...
Frontera распределенный робот для обхода веба в больших объемах / Александр С...Frontera распределенный робот для обхода веба в больших объемах / Александр С...
Frontera распределенный робот для обхода веба в больших объемах / Александр С...
 
Nodejs
NodejsNodejs
Nodejs
 
Тарас Кирилюк — Docker basics. How-to for Drupal developers
Тарас Кирилюк — Docker basics. How-to for Drupal developersТарас Кирилюк — Docker basics. How-to for Drupal developers
Тарас Кирилюк — Docker basics. How-to for Drupal developers
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJS
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
Node.js tutoria for beginner
Node.js tutoria for beginnerNode.js tutoria for beginner
Node.js tutoria for beginner
 

Similaire à Sharding Redis at Flite

FreeSWITCH as a Microservice
FreeSWITCH as a MicroserviceFreeSWITCH as a Microservice
FreeSWITCH as a MicroserviceEvan McGee
 
DevOps &lt;3 node.js
DevOps &lt;3 node.jsDevOps &lt;3 node.js
DevOps &lt;3 node.jsJeff Miccolis
 
Handling Redis failover with ZooKeeper
Handling Redis failover with ZooKeeperHandling Redis failover with ZooKeeper
Handling Redis failover with ZooKeeperryanlecompte
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystemYukti Kaura
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Node.js for .NET Developers
Node.js for .NET DevelopersNode.js for .NET Developers
Node.js for .NET DevelopersDavid Neal
 
Hyperdex - A closer look
Hyperdex - A closer lookHyperdex - A closer look
Hyperdex - A closer lookDECK36
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqRuben Tan
 
Vert.x keynote for EclipseCon 2013
Vert.x keynote for EclipseCon 2013Vert.x keynote for EclipseCon 2013
Vert.x keynote for EclipseCon 2013timfox111
 
Apache OpenWhisk Serverless Computing
Apache OpenWhisk Serverless ComputingApache OpenWhisk Serverless Computing
Apache OpenWhisk Serverless ComputingUpkar Lidder
 
Planning to Fail #phpuk13
Planning to Fail #phpuk13Planning to Fail #phpuk13
Planning to Fail #phpuk13Dave Gardner
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNATomas Cervenka
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)Tech in Asia ID
 

Similaire à Sharding Redis at Flite (20)

Mini-Training: Node.js
Mini-Training: Node.jsMini-Training: Node.js
Mini-Training: Node.js
 
FreeSWITCH as a Microservice
FreeSWITCH as a MicroserviceFreeSWITCH as a Microservice
FreeSWITCH as a Microservice
 
DevOps &lt;3 node.js
DevOps &lt;3 node.jsDevOps &lt;3 node.js
DevOps &lt;3 node.js
 
Handling Redis failover with ZooKeeper
Handling Redis failover with ZooKeeperHandling Redis failover with ZooKeeper
Handling Redis failover with ZooKeeper
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node js
Node jsNode js
Node js
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
Node.js Chapter1
Node.js Chapter1Node.js Chapter1
Node.js Chapter1
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node.js for .NET Developers
Node.js for .NET DevelopersNode.js for .NET Developers
Node.js for .NET Developers
 
Hyperdex - A closer look
Hyperdex - A closer lookHyperdex - A closer look
Hyperdex - A closer look
 
Node js internal
Node js internalNode js internal
Node js internal
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
Vert.x keynote for EclipseCon 2013
Vert.x keynote for EclipseCon 2013Vert.x keynote for EclipseCon 2013
Vert.x keynote for EclipseCon 2013
 
Apache OpenWhisk Serverless Computing
Apache OpenWhisk Serverless ComputingApache OpenWhisk Serverless Computing
Apache OpenWhisk Serverless Computing
 
Planning to Fail #phpuk13
Planning to Fail #phpuk13Planning to Fail #phpuk13
Planning to Fail #phpuk13
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
 
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
 

Dernier

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 

Dernier (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 

Sharding Redis at Flite

  • 1. SHARDING REDIS at FLITE Eugene Feingold & Chakri Kodali
  • 2. WHAT IS FLITE? •  Display advertising platform •  Create and publish rich, interactive ads •  Serve ad impressions •  Collect and analyze metrics, batch AND realtime
  • 3. WHAT IS FLITE? •  Display advertising platform •  Create and publish rich, interactive ads •  Serve ad impressions •  Collect and analyze metrics, batch AND realtime with
  • 4. REALTIME YOU SAY? •  Realtime monitoring of ad performance •  Debugging of ads, with instant feedback on triggered events
  • 6. WRITING TO REDIS Persistence: Up to 4 hours for most data Amount: ~30 writes per event, pipelined Granularity: By second, minute, hour Write Types: •  HSET - JSON blobs (Event body data) •  LPUSH - Lists of events (Events by session) •  HINCRBY - Simple counters (Events by ad) •  ZINCRBY - Sorted set counters (To retrieve “Top 100”) •  PUBSUB - Stream event data (Debugger)
  • 7. READING FROM REDIS Redis transactions are used extensively like multi, exec Read types: •  HGETALL - get all data for event •  HGET - get event counts by ad •  LRANGE - list of all events by session •  ZREVRANGE - top 100 ads with highest number of events •  SUBSCRIBE
  • 8. AND ALL OF THIS AT SCALE •  Daily traffic peaks: 100k - 200k events per minute •  Peaks are really plateaus that last for hours •  Read load is negligible by comparison, but reads must be fast •  In fact, everything must be fast: <1 sec latency for debugger to work
  • 9. WHAT’S WRONG WITH THIS PICTURE? JVM JVM JVM ad ad ad ad ad ad ad node.js node.js
  • 10. WHAT’S WRONG WITH THIS PICTURE? Bottleneck! JVM JVM JVM ad ad ad ad ad ad ad node.js node.js
  • 11. SCALABILITY FAIL! What did it look like? 2-3x of our usual load
  • 12. SCALABILITY FAIL! Note how only 1 core is being used 14,000 open connections! What did it look like?
  • 13. A QUICK SOLUTION? •  MOAR Megahurtz!!: m2.2xl is already about as fast as Amazon gets. •  Redis-As-A-Service: Expensive, not fast enough for even our usual load. •  twemproxy: Twitter’s sharding solution. Doesn’t support all commands: PING, MULTI, INFO, MGET, etc…
  • 14. WHAT ABOUT JEDIS’S NATIVE SHARDING? •  No pipelining •  No pubsub •  Complicated consistent hashing mechanism makes reading in other environments more difficult
  • 15. LET’S ROLL OUR OWN! Goals: Speed, speed, speed Not Goals: Fault tolerance, redundancy, resiliency
  • 16. HOW HARD CAN IT BE? Sharding method: Java hashCode of key for every item written JVMad event items node.js Write to many Read from one
  • 17. WHAT HAPPENED? Before Sharding After Sharding Items per Event 30 30 Items written per Event per Redis 30 10 Redis Connections per Event 1 3 Connections per second per Redis box n n Reality: When n gets to around 500, Redis maxes out CPU and starts rejecting connections. Theory: Since Redis claims to be able to handle 70k connections per second, the amount of data being sent per connection is the problem.
  • 18. SO HOW HARD CAN IT BE? HARD.
  • 19. TAKE TWO Sharding method: Java hashCode of EVENT key for every item written. A single key now lives on multiple Redis boxes JVMad event items node.js Write to one Read from many
  • 20. BETTER! Before Sharding After Take 1 After Take 2 Items per Event 30 30 30 Items written per Event per Redis 30 10 30 Redis Connections per Event 1 3 1 Connections per second per Redis box n n n/3 More load can be easily accommodated by adding boxes
  • 21. CODING CHALLENGES Java •  Managing multiple connection pools •  Managing multiple pipelines •  Automatic health checks node.js •  Finding hashing function that works in different environments •  Managing multiple pipelines •  Fanout requests and merging response once pipeline is executed
  • 22. SINGLE-REDIS JEDIS WORKFLOW On application startup: 1.  Initialize jedisPool with connection info Every time: 1.  Jedis jedisClient = jedisPool.getClient(); 2.  Pipeline pipeline = jedisClient.pipelined(); 3.  State your business 4.  pipeline.sync(); 5.  jedisPool.returnResource(jedisClient);
  • 23. SHARDED JEDIS WORKFLOW On application startup: 1.  Initialize n jedisPools with connection info Every time: 1.  Jedis jedisClient = jedisPool.getClient(); 2.  Pipeline pipeline = jedisClient.pipelined(); 3.  State your business 4.  pipeline.sync(); 5.  jedisPool.returnResource(jedisClient);
  • 24. SHARDED JEDIS WORKFLOW On application startup: 1.  Initialize n jedisPools with connection info Every time: 1.  Jedis jedisClient = jedisPool.getClient(); Which pool? 2.  Pipeline pipeline = jedisClient.pipelined(); Which client? 3.  State your business To whom? 4.  pipeline.sync(); Which pipeline? 5.  jedisPool.returnResource(jedisClient); Return what where?
  • 25. SHARDED JEDIS WORKFLOW RedisNodeManager Spring-created singleton JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager
  • 26. SHARDED JEDIS WORKFLOW RedisNodeManager Spring-created singleton JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager RedisPipelineManager JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager getPipelineManager()
  • 27. SHARDED JEDIS WORKFLOW RedisNodeManager Spring-created singleton JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager RedisPipelineManager JedisPoolManagerJedisPoolManagerJedisPoolManagerRedisPoolManager Pipeline getPipelineManager() getPipeline(shardKey)
  • 28. LET’S LOOK AT SOME CODE!
  • 29. OPERATIONAL DETAILS •  Redis is single threaded o  You can run multiple Redises on one server o  Bind each Redis instance to a specific core