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

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
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
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Dernier (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
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
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

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