SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
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?

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Similar a 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
 

Similar a 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)
 

Último

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

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