SlideShare uma empresa Scribd logo
1 de 54
How to serve
2500 requests per second
SAPO text Ads
Miguel Mascarenhas Filipe @ codebits, November 2010
Who am I ?
Team lead of
Anúncios Sapo (text ads) team
Team of 5 (+ me) software engineers,
designing & developing the
text ads platform
How to serve VS How we serve
Are we a role-model?
Are there recipes ?
Should there be a how to?
Summary
●
Project Overview
●
Full System Overview
●
Serving Text Ads
●
Latency & Speed
●
Scaling on the Front
●
Backend & backend Services
●
Availability, Reliability & Fault Tolerance
●
Scalability Issues
●
Monitoring & Logging
●
Programming Languages & Technologies
Anúncios SAPO
●
Text Advertisement System
●
Search Engines:
●
BING ( http://www.bing.pt )
●
SAPO's Search ( http://sl.pt )
●
SAPO & Partners' Content Network
●
~200 web sites
●
Impresa, Publico, Cofina, IOL, controlinveste
●
Peaks at 90M ad requests per day, 2500/sec
Serving
Text Ads
Concepts
●
Pay Per Click Business Model
●
CPC - Cost Per Click
●
QPS – Queries Per Second
●
CTR - Click Through Rate
(clicks / impressions)
Serving text-ads ..
Major features:
●
choose & serve ads
●
register requests, impressions, clicks,
conversions
●
maintain user budget up to date
●
Quickly reflect changes in ad pool
Serving text-ads ...
elect_get_ads() {
if( words )
ads = get_ads_keywords()
else {
if (crawled_site)
ads = get_ads_crawler()
else
ads = get_ads_site_keywords()
}
site_ads = get_ads_site_targeting()
merge_ads(ads,site_ads)
}
Serving text-ads ...
Election of ads:
●
requires index
ads['word'] -> [ad1, ad2, ad3..]
●
ads ordered by:
'score' -> f(CTR, CPC, quality)
●
Auction based on
Generalized second-price Auction
Serving text-ads..
Other essential features:
contextualization of webpages/sites
blacklisting of ads per site
reporting information
scoring quality of ads
anti-fraud systems/fraud detectors
LATENCY & SPEED
.. and their importance
Latency
Low latency is required:
Search pages (BING,SAPO,..) have to:
search ads (that's us!)
search results
and merge results together.
«ads added last» - site developers put ad-
request code at the end of the page (last thing
to load, usually)
Latency
Without good latency
ads are slow to appear and
users have moved on...
Latency
Slow ads Low CTR BAD!
Latency has a BIG impact
on REVENUE.
Latency Service Level Agreement
99.9% of reqs under:
150 milliseconds
Average response time is:
20 milliseconds
Never take more than 1 second.
serve blank ads in that case
How to keep low Latency ?
Pre-computing everything is essential
Fast contextualization lookup
Handle lack of information gracefully
(turning essential into optional)
How to keep low Latency ?
Decouple (and postpone) everything
that isn't essential to serve ads
.. such as DB writes & other side effects of
serving ads.
Fast word lookups - LiveDB
Fast word/site lookup(inverted index of ads)
●
cache it in local RAM (memcached)
●
'persistent' backing store is RAM
Fast word lookups - LiveDB
Offline creation of index:
ads['word'] -> [ ad1, ad2, ad3, ad4, ... ]
Lots of details, need to compute additional
information for each tuple: (word, ad, CPC):
CTR, Evaluation Score
Fast word lookups - LiveDB
We choose on MySQL for:
●
fast 'inverted index' creation
(by using Stored procedures & replication)
●
fast index lookup based on the 'fame'
of MySQL speed in simple workloads
●
Replication for free using MySQL's
master-slave replication
Fast word lookups - LiveDB
Workload is almost read-only.
(in fact, we can make it read-only with some tricks)
Storage engines FAST for read-only workloads:
MySQL MEMORY
MySQL MyISAM
Very, very similar
MEMORY has more restrictions & limitations
MySQL MEMORY
Extremely fast lookup.
data is guaranteed to be in RAM (or in swap..)
Benchmarked MySQL Memory engine:
.. avg response time was around 10-20msecs,
..within our needs!
Constraints:
• There is a maximum table size in bytes
• VARCHAR is in fact.. CHAR()
MySQL MyISAM
.. After months in production use,
MEMORY engine proved problematic..
Evaluated MyISAM, did benchmarks:
same speed, lower standard deviation.
Speed
Speed is .. ?
Queries per second ?
Sequential or Concurrently (Throughput) ?
Speed
Speed is ..
Queries per second.
Sequential or Concurrently (Throughput) ?
Throughput is obviously what matters in this
case..
Speed!
avg time is 20msecs = 50 QPS
but... it's totally parallel workload.
And most of the time is IOwait on index
lookup.
1 server cpu can do ~6x this: ~300 QPS
.. current servers: ~1200 QPS ..
Scaling on the Front..
Se scale horizontally because:
●
We can add more Frontends
to handle more QPS
●
We can add more LiveDB slaves
to handle more SQL Queries
Backend
Message queueing system:
SAPO BROKER
Backend Services

'compact' & apply operations to the DBMS

runs anti-fraud system

runs contextualizer & crawler

runs semantic analyser

runs reports & suggestions system
Building the LiveDB
MySQL is the ACID DBMS
MySQL is the non-ACID LiveDB.
Python & Stored Procedures create LiveDB
in a MySQL DBMS slave,
MySQL replication pushes
to the read-only slaves
Availability & Reliability
(no downtime please..)
Reliability & Fault Tolerance
Almost every service/component is redundant.
Currently there are only 2 single points of
failure:

Master DB server

Master LiveDB server
And even if BOTH FAIL,
we keep serving ads...
Reliability & Fault Tolerance
Failure in Master LiveDB server:

We have a hot spare,

Can change master in aprox 5 to 10 minutes
Failure in Master DB:
●
Data starts to pile up on Backend services
●
Backoffices are unable to operate (no new ads)
●
if failure lasts a long time:
we might serve ads without budget
●
Electing a new Master is performed manually
Has happened before, no ad serving downtime.
Scalability Issues
We can scale horizontally in all but two
components currently:

Master DBMS MySQL server
(but we are far from saturating it..)
we currently don't plan to 'solve' this

Master LiveDB server
...
Scalability Issues
Building LiveDB doesn't scale:
●
We build a full new LiveDB everytime
●
It isn't distributed nor is it easily made parallel
●
Time is proportional to nº of active Bids
LiveDB should be updated only with recent changes in ad pool.
Impossible to do with current main DB data model and
with current LiveDB design
We are currently investing heavily on a solution to this,
LiveCouchDB
Monitoring & Logging
(is everything okay?)
Monitoring & Logging
Bad things happen:
Log it, deal with it...
We need to know about it:
monitor logs
trigger alarm if errors on log..
Monitoring & Alarmistics
frontend code failures
intercept error
serve blank ad
log error
trigger alarm
Monitoring & Alarmistics
network failures
reconnect with exponential backoff
log error
trigger alarm ?
Monitoring & Alarmistics
machine failures
replication & redundancy
save state to disk
Monitoring & Alarmistics
software bugs..
bad (or lack of) data
radio silence
log error
trigger alarm
Programming Languages
.. and software used
Programming Languages
Python (backend)
Perl (frontend code)
C (1 app only)
Java (broker & reporting)
PHP (backoffices)
SQL
Javascript
Software used
Linux
memcached
MySQL
squid
nginx
Currently Evaluating
Languages:
Hadoop PIG
Technologies:
Hadoop
CouchDB
Questions?

Mais conteúdo relacionado

Mais procurados

I feel the need... the need for SPEED
I feel the need... the need for SPEEDI feel the need... the need for SPEED
I feel the need... the need for SPEEDdarrenthedev
 
Basic course for junior web developer
Basic course for junior web developerBasic course for junior web developer
Basic course for junior web developerTran Khoa
 
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadkranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadKrivoy Rog IT Community
 
Async ... Await – concurrency in java script
Async ... Await – concurrency in java scriptAsync ... Await – concurrency in java script
Async ... Await – concurrency in java scriptAthman Gude
 
Php training in chandigarh - CBitss Technologies
Php training in chandigarh  - CBitss Technologies Php training in chandigarh  - CBitss Technologies
Php training in chandigarh - CBitss Technologies Cbitss Technologies
 
Page Performance
Page PerformancePage Performance
Page Performancestk_jj
 

Mais procurados (10)

WordCamp RVA
WordCamp RVAWordCamp RVA
WordCamp RVA
 
I feel the need... the need for SPEED
I feel the need... the need for SPEEDI feel the need... the need for SPEED
I feel the need... the need for SPEED
 
BDD using behat
BDD using behatBDD using behat
BDD using behat
 
Basic course for junior web developer
Basic course for junior web developerBasic course for junior web developer
Basic course for junior web developer
 
kranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High loadkranonit S06E01 Игорь Цинько: High load
kranonit S06E01 Игорь Цинько: High load
 
web optimizations
web optimizationsweb optimizations
web optimizations
 
Async ... Await – concurrency in java script
Async ... Await – concurrency in java scriptAsync ... Await – concurrency in java script
Async ... Await – concurrency in java script
 
Php training in chandigarh - CBitss Technologies
Php training in chandigarh  - CBitss Technologies Php training in chandigarh  - CBitss Technologies
Php training in chandigarh - CBitss Technologies
 
Page Performance
Page PerformancePage Performance
Page Performance
 
Optimization
OptimizationOptimization
Optimization
 

Destaque

EFRAC INDUSTRIAL REPORT
EFRAC INDUSTRIAL REPORTEFRAC INDUSTRIAL REPORT
EFRAC INDUSTRIAL REPORTPriyanka Bal
 
Formation à Zotero - Niveau 2
Formation à Zotero - Niveau 2Formation à Zotero - Niveau 2
Formation à Zotero - Niveau 2Nicolas Alarcon
 
Signaler et valoriser vos publications scientifiques r
Signaler et valoriser vos publications scientifiques rSignaler et valoriser vos publications scientifiques r
Signaler et valoriser vos publications scientifiques rNicolas Alarcon
 
La democrazia che sognò le fate (stato di eccezione, teoria dell'alieno e del...
La democrazia che sognò le fate (stato di eccezione, teoria dell'alieno e del...La democrazia che sognò le fate (stato di eccezione, teoria dell'alieno e del...
La democrazia che sognò le fate (stato di eccezione, teoria dell'alieno e del...UNIVERSITY OF COIMBRA
 
Neo repubblicanesimo, neo-repubblicanismo, neo repubblicanesimo, neorepubblic...
Neo repubblicanesimo, neo-repubblicanismo, neo repubblicanesimo, neorepubblic...Neo repubblicanesimo, neo-repubblicanismo, neo repubblicanesimo, neorepubblic...
Neo repubblicanesimo, neo-repubblicanismo, neo repubblicanesimo, neorepubblic...UNIVERSITY OF COIMBRA
 
Neo marxismo, neomarxismo, neo marxismo
Neo marxismo, neomarxismo, neo marxismoNeo marxismo, neomarxismo, neo marxismo
Neo marxismo, neomarxismo, neo marxismoUNIVERSITY OF COIMBRA
 
Post marxismo, postmarxismo, post marxismo
Post marxismo, postmarxismo, post marxismoPost marxismo, postmarxismo, post marxismo
Post marxismo, postmarxismo, post marxismoUNIVERSITY OF COIMBRA
 
Marxismo, marxismus, marxisme, marxism
Marxismo, marxismus, marxisme, marxismMarxismo, marxismus, marxisme, marxism
Marxismo, marxismus, marxisme, marxismUNIVERSITY OF COIMBRA
 
Repubblicanesimo, republicanism, republikanismus, républicanisme, republicani...
Repubblicanesimo, republicanism, republikanismus, républicanisme, republicani...Repubblicanesimo, republicanism, republikanismus, républicanisme, republicani...
Repubblicanesimo, republicanism, republikanismus, républicanisme, republicani...UNIVERSITY OF COIMBRA
 
Grille d'entretien des focus group Livre
Grille d'entretien des focus group LivreGrille d'entretien des focus group Livre
Grille d'entretien des focus group LivreNicolas Alarcon
 
AMD Stock Pitch 2013
AMD Stock Pitch 2013AMD Stock Pitch 2013
AMD Stock Pitch 2013Dan Zhang
 
7th Gen AMD A-Series Announcement
7th Gen AMD A-Series Announcement7th Gen AMD A-Series Announcement
7th Gen AMD A-Series AnnouncementKok Kee
 
Kale Chane ke Fayde: Swasthvardhak Guno Se Bharpur
Kale Chane ke Fayde: Swasthvardhak Guno Se BharpurKale Chane ke Fayde: Swasthvardhak Guno Se Bharpur
Kale Chane ke Fayde: Swasthvardhak Guno Se Bharpurcshradhha
 
Novo(a) apresentação do microsoft power point
Novo(a) apresentação do microsoft power pointNovo(a) apresentação do microsoft power point
Novo(a) apresentação do microsoft power pointeduarda renzi
 
Aula de língua portuguesa como le
Aula de língua portuguesa como leAula de língua portuguesa como le
Aula de língua portuguesa como leElô Ribeiro
 
Open Data Institute - Presentation for workshop
Open Data Institute - Presentation for workshopOpen Data Institute - Presentation for workshop
Open Data Institute - Presentation for workshopOpen City Foundation
 
Amd Ryzen. Últimos detalles - Blog|informaticapremium
Amd Ryzen. Últimos detalles - Blog|informaticapremiumAmd Ryzen. Últimos detalles - Blog|informaticapremium
Amd Ryzen. Últimos detalles - Blog|informaticapremiuminformaticapremium
 
Analise do conto A Cartomante
Analise do conto A CartomanteAnalise do conto A Cartomante
Analise do conto A CartomanteAmanda Silva
 
Search Engine Marketing
Search Engine MarketingSearch Engine Marketing
Search Engine Marketingiandewar
 

Destaque (20)

EFRAC INDUSTRIAL REPORT
EFRAC INDUSTRIAL REPORTEFRAC INDUSTRIAL REPORT
EFRAC INDUSTRIAL REPORT
 
Formation à Zotero - Niveau 2
Formation à Zotero - Niveau 2Formation à Zotero - Niveau 2
Formation à Zotero - Niveau 2
 
Signaler et valoriser vos publications scientifiques r
Signaler et valoriser vos publications scientifiques rSignaler et valoriser vos publications scientifiques r
Signaler et valoriser vos publications scientifiques r
 
La democrazia che sognò le fate (stato di eccezione, teoria dell'alieno e del...
La democrazia che sognò le fate (stato di eccezione, teoria dell'alieno e del...La democrazia che sognò le fate (stato di eccezione, teoria dell'alieno e del...
La democrazia che sognò le fate (stato di eccezione, teoria dell'alieno e del...
 
Neo repubblicanesimo, neo-repubblicanismo, neo repubblicanesimo, neorepubblic...
Neo repubblicanesimo, neo-repubblicanismo, neo repubblicanesimo, neorepubblic...Neo repubblicanesimo, neo-repubblicanismo, neo repubblicanesimo, neorepubblic...
Neo repubblicanesimo, neo-repubblicanismo, neo repubblicanesimo, neorepubblic...
 
Neo marxismo, neomarxismo, neo marxismo
Neo marxismo, neomarxismo, neo marxismoNeo marxismo, neomarxismo, neo marxismo
Neo marxismo, neomarxismo, neo marxismo
 
Post marxismo, postmarxismo, post marxismo
Post marxismo, postmarxismo, post marxismoPost marxismo, postmarxismo, post marxismo
Post marxismo, postmarxismo, post marxismo
 
Marxismo, marxismus, marxisme, marxism
Marxismo, marxismus, marxisme, marxismMarxismo, marxismus, marxisme, marxism
Marxismo, marxismus, marxisme, marxism
 
Repubblicanesimo, republicanism, republikanismus, républicanisme, republicani...
Repubblicanesimo, republicanism, republikanismus, républicanisme, republicani...Repubblicanesimo, republicanism, republikanismus, républicanisme, republicani...
Repubblicanesimo, republicanism, republikanismus, républicanisme, republicani...
 
Grille d'entretien des focus group Livre
Grille d'entretien des focus group LivreGrille d'entretien des focus group Livre
Grille d'entretien des focus group Livre
 
AMD Stock Pitch 2013
AMD Stock Pitch 2013AMD Stock Pitch 2013
AMD Stock Pitch 2013
 
7th Gen AMD A-Series Announcement
7th Gen AMD A-Series Announcement7th Gen AMD A-Series Announcement
7th Gen AMD A-Series Announcement
 
Kale Chane ke Fayde: Swasthvardhak Guno Se Bharpur
Kale Chane ke Fayde: Swasthvardhak Guno Se BharpurKale Chane ke Fayde: Swasthvardhak Guno Se Bharpur
Kale Chane ke Fayde: Swasthvardhak Guno Se Bharpur
 
Novo(a) apresentação do microsoft power point
Novo(a) apresentação do microsoft power pointNovo(a) apresentação do microsoft power point
Novo(a) apresentação do microsoft power point
 
Aula de língua portuguesa como le
Aula de língua portuguesa como leAula de língua portuguesa como le
Aula de língua portuguesa como le
 
a cartomante
a cartomantea cartomante
a cartomante
 
Open Data Institute - Presentation for workshop
Open Data Institute - Presentation for workshopOpen Data Institute - Presentation for workshop
Open Data Institute - Presentation for workshop
 
Amd Ryzen. Últimos detalles - Blog|informaticapremium
Amd Ryzen. Últimos detalles - Blog|informaticapremiumAmd Ryzen. Últimos detalles - Blog|informaticapremium
Amd Ryzen. Últimos detalles - Blog|informaticapremium
 
Analise do conto A Cartomante
Analise do conto A CartomanteAnalise do conto A Cartomante
Analise do conto A Cartomante
 
Search Engine Marketing
Search Engine MarketingSearch Engine Marketing
Search Engine Marketing
 

Semelhante a How to serve 2500 Ad requests per second

Edge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEA
Edge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEAEdge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEA
Edge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEAAkamai Technologies
 
Richardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichard Rodger
 
Richardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichard Rodger
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Storyvanphp
 
Migration of a high-traffic E-commerce website from Legacy Monolith to Micros...
Migration of a high-traffic E-commerce website from Legacy Monolith to Micros...Migration of a high-traffic E-commerce website from Legacy Monolith to Micros...
Migration of a high-traffic E-commerce website from Legacy Monolith to Micros...Pavel Pratyush
 
Evolution of DBA in the Cloud Era
 Evolution of DBA in the Cloud Era Evolution of DBA in the Cloud Era
Evolution of DBA in the Cloud EraMydbops
 
Salvatore Incandela "Loyalty cashback - Scaling with MongoDB"
Salvatore Incandela "Loyalty cashback - Scaling with MongoDB"Salvatore Incandela "Loyalty cashback - Scaling with MongoDB"
Salvatore Incandela "Loyalty cashback - Scaling with MongoDB"Paybay
 
Dubbo and Weidian's practice on micro-service architecture
Dubbo and Weidian's practice on micro-service architectureDubbo and Weidian's practice on micro-service architecture
Dubbo and Weidian's practice on micro-service architectureHuxing Zhang
 
From 6 hours to 1 minute... in 2 days! How we managed to stream our (long) Ha...
From 6 hours to 1 minute... in 2 days! How we managed to stream our (long) Ha...From 6 hours to 1 minute... in 2 days! How we managed to stream our (long) Ha...
From 6 hours to 1 minute... in 2 days! How we managed to stream our (long) Ha...Dataconomy Media
 
Big Data Berlin - Criteo
Big Data Berlin - CriteoBig Data Berlin - Criteo
Big Data Berlin - CriteoSofian Djamaa
 
Storing State Forever: Why It Can Be Good For Your Analytics
Storing State Forever: Why It Can Be Good For Your AnalyticsStoring State Forever: Why It Can Be Good For Your Analytics
Storing State Forever: Why It Can Be Good For Your AnalyticsYaroslav Tkachenko
 
Magento performancenbs
Magento performancenbsMagento performancenbs
Magento performancenbsvarien
 
From prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.ioFrom prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.ioMáté Lang
 
iFood on Delivering 100 Million Events a Month to Restaurants with Scylla
iFood on Delivering 100 Million Events a Month to Restaurants with ScyllaiFood on Delivering 100 Million Events a Month to Restaurants with Scylla
iFood on Delivering 100 Million Events a Month to Restaurants with ScyllaScyllaDB
 
Building a real-time, scalable and intelligent programmatic ad buying platform
Building a real-time, scalable and intelligent programmatic ad buying platformBuilding a real-time, scalable and intelligent programmatic ad buying platform
Building a real-time, scalable and intelligent programmatic ad buying platformJampp
 
Processing 19 billion messages in real time and NOT dying in the process
Processing 19 billion messages in real time and NOT dying in the processProcessing 19 billion messages in real time and NOT dying in the process
Processing 19 billion messages in real time and NOT dying in the processJampp
 
Monitoring lessons from waze sre team
Monitoring lessons from waze sre teamMonitoring lessons from waze sre team
Monitoring lessons from waze sre teamYonit Gruber-Hazani
 
Building and Scaling a WebSockets Pubsub System
Building and Scaling a WebSockets Pubsub SystemBuilding and Scaling a WebSockets Pubsub System
Building and Scaling a WebSockets Pubsub SystemKapil Reddy
 
Magento for-performance- v01
Magento for-performance- v01Magento for-performance- v01
Magento for-performance- v01Rajneesh Maurya
 
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...Continuent
 

Semelhante a How to serve 2500 Ad requests per second (20)

Edge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEA
Edge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEAEdge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEA
Edge 2014: Maintaining the Balance: Getting the Most of Your CDN with IKEA
 
Richardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichardrodger nodeday-2014-final
Richardrodger nodeday-2014-final
 
Richardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichardrodger nodeday-2014-final
Richardrodger nodeday-2014-final
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
 
Migration of a high-traffic E-commerce website from Legacy Monolith to Micros...
Migration of a high-traffic E-commerce website from Legacy Monolith to Micros...Migration of a high-traffic E-commerce website from Legacy Monolith to Micros...
Migration of a high-traffic E-commerce website from Legacy Monolith to Micros...
 
Evolution of DBA in the Cloud Era
 Evolution of DBA in the Cloud Era Evolution of DBA in the Cloud Era
Evolution of DBA in the Cloud Era
 
Salvatore Incandela "Loyalty cashback - Scaling with MongoDB"
Salvatore Incandela "Loyalty cashback - Scaling with MongoDB"Salvatore Incandela "Loyalty cashback - Scaling with MongoDB"
Salvatore Incandela "Loyalty cashback - Scaling with MongoDB"
 
Dubbo and Weidian's practice on micro-service architecture
Dubbo and Weidian's practice on micro-service architectureDubbo and Weidian's practice on micro-service architecture
Dubbo and Weidian's practice on micro-service architecture
 
From 6 hours to 1 minute... in 2 days! How we managed to stream our (long) Ha...
From 6 hours to 1 minute... in 2 days! How we managed to stream our (long) Ha...From 6 hours to 1 minute... in 2 days! How we managed to stream our (long) Ha...
From 6 hours to 1 minute... in 2 days! How we managed to stream our (long) Ha...
 
Big Data Berlin - Criteo
Big Data Berlin - CriteoBig Data Berlin - Criteo
Big Data Berlin - Criteo
 
Storing State Forever: Why It Can Be Good For Your Analytics
Storing State Forever: Why It Can Be Good For Your AnalyticsStoring State Forever: Why It Can Be Good For Your Analytics
Storing State Forever: Why It Can Be Good For Your Analytics
 
Magento performancenbs
Magento performancenbsMagento performancenbs
Magento performancenbs
 
From prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.ioFrom prototype to production - The journey of re-designing SmartUp.io
From prototype to production - The journey of re-designing SmartUp.io
 
iFood on Delivering 100 Million Events a Month to Restaurants with Scylla
iFood on Delivering 100 Million Events a Month to Restaurants with ScyllaiFood on Delivering 100 Million Events a Month to Restaurants with Scylla
iFood on Delivering 100 Million Events a Month to Restaurants with Scylla
 
Building a real-time, scalable and intelligent programmatic ad buying platform
Building a real-time, scalable and intelligent programmatic ad buying platformBuilding a real-time, scalable and intelligent programmatic ad buying platform
Building a real-time, scalable and intelligent programmatic ad buying platform
 
Processing 19 billion messages in real time and NOT dying in the process
Processing 19 billion messages in real time and NOT dying in the processProcessing 19 billion messages in real time and NOT dying in the process
Processing 19 billion messages in real time and NOT dying in the process
 
Monitoring lessons from waze sre team
Monitoring lessons from waze sre teamMonitoring lessons from waze sre team
Monitoring lessons from waze sre team
 
Building and Scaling a WebSockets Pubsub System
Building and Scaling a WebSockets Pubsub SystemBuilding and Scaling a WebSockets Pubsub System
Building and Scaling a WebSockets Pubsub System
 
Magento for-performance- v01
Magento for-performance- v01Magento for-performance- v01
Magento for-performance- v01
 
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
Marketing Automation at Scale: How Marketo Solved Key Data Management Challen...
 

Último

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

How to serve 2500 Ad requests per second

  • 1. How to serve 2500 requests per second SAPO text Ads Miguel Mascarenhas Filipe @ codebits, November 2010
  • 2. Who am I ? Team lead of Anúncios Sapo (text ads) team Team of 5 (+ me) software engineers, designing & developing the text ads platform
  • 3. How to serve VS How we serve Are we a role-model? Are there recipes ? Should there be a how to?
  • 4. Summary ● Project Overview ● Full System Overview ● Serving Text Ads ● Latency & Speed ● Scaling on the Front ● Backend & backend Services ● Availability, Reliability & Fault Tolerance ● Scalability Issues ● Monitoring & Logging ● Programming Languages & Technologies
  • 5.
  • 6.
  • 7.
  • 8. Anúncios SAPO ● Text Advertisement System ● Search Engines: ● BING ( http://www.bing.pt ) ● SAPO's Search ( http://sl.pt ) ● SAPO & Partners' Content Network ● ~200 web sites ● Impresa, Publico, Cofina, IOL, controlinveste ● Peaks at 90M ad requests per day, 2500/sec
  • 9.
  • 11. Concepts ● Pay Per Click Business Model ● CPC - Cost Per Click ● QPS – Queries Per Second ● CTR - Click Through Rate (clicks / impressions)
  • 12. Serving text-ads .. Major features: ● choose & serve ads ● register requests, impressions, clicks, conversions ● maintain user budget up to date ● Quickly reflect changes in ad pool
  • 13. Serving text-ads ... elect_get_ads() { if( words ) ads = get_ads_keywords() else { if (crawled_site) ads = get_ads_crawler() else ads = get_ads_site_keywords() } site_ads = get_ads_site_targeting() merge_ads(ads,site_ads) }
  • 14. Serving text-ads ... Election of ads: ● requires index ads['word'] -> [ad1, ad2, ad3..] ● ads ordered by: 'score' -> f(CTR, CPC, quality) ● Auction based on Generalized second-price Auction
  • 15. Serving text-ads.. Other essential features: contextualization of webpages/sites blacklisting of ads per site reporting information scoring quality of ads anti-fraud systems/fraud detectors
  • 16. LATENCY & SPEED .. and their importance
  • 17. Latency Low latency is required: Search pages (BING,SAPO,..) have to: search ads (that's us!) search results and merge results together. «ads added last» - site developers put ad- request code at the end of the page (last thing to load, usually)
  • 18. Latency Without good latency ads are slow to appear and users have moved on...
  • 19. Latency Slow ads Low CTR BAD! Latency has a BIG impact on REVENUE.
  • 20. Latency Service Level Agreement 99.9% of reqs under: 150 milliseconds Average response time is: 20 milliseconds Never take more than 1 second. serve blank ads in that case
  • 21. How to keep low Latency ? Pre-computing everything is essential Fast contextualization lookup Handle lack of information gracefully (turning essential into optional)
  • 22. How to keep low Latency ? Decouple (and postpone) everything that isn't essential to serve ads .. such as DB writes & other side effects of serving ads.
  • 23. Fast word lookups - LiveDB Fast word/site lookup(inverted index of ads) ● cache it in local RAM (memcached) ● 'persistent' backing store is RAM
  • 24. Fast word lookups - LiveDB Offline creation of index: ads['word'] -> [ ad1, ad2, ad3, ad4, ... ] Lots of details, need to compute additional information for each tuple: (word, ad, CPC): CTR, Evaluation Score
  • 25. Fast word lookups - LiveDB We choose on MySQL for: ● fast 'inverted index' creation (by using Stored procedures & replication) ● fast index lookup based on the 'fame' of MySQL speed in simple workloads ● Replication for free using MySQL's master-slave replication
  • 26. Fast word lookups - LiveDB Workload is almost read-only. (in fact, we can make it read-only with some tricks) Storage engines FAST for read-only workloads: MySQL MEMORY MySQL MyISAM Very, very similar MEMORY has more restrictions & limitations
  • 27. MySQL MEMORY Extremely fast lookup. data is guaranteed to be in RAM (or in swap..) Benchmarked MySQL Memory engine: .. avg response time was around 10-20msecs, ..within our needs! Constraints: • There is a maximum table size in bytes • VARCHAR is in fact.. CHAR()
  • 28. MySQL MyISAM .. After months in production use, MEMORY engine proved problematic.. Evaluated MyISAM, did benchmarks: same speed, lower standard deviation.
  • 29.
  • 30. Speed Speed is .. ? Queries per second ? Sequential or Concurrently (Throughput) ?
  • 31. Speed Speed is .. Queries per second. Sequential or Concurrently (Throughput) ? Throughput is obviously what matters in this case..
  • 32. Speed! avg time is 20msecs = 50 QPS but... it's totally parallel workload. And most of the time is IOwait on index lookup. 1 server cpu can do ~6x this: ~300 QPS .. current servers: ~1200 QPS ..
  • 33. Scaling on the Front.. Se scale horizontally because: ● We can add more Frontends to handle more QPS ● We can add more LiveDB slaves to handle more SQL Queries
  • 35. Backend Services  'compact' & apply operations to the DBMS  runs anti-fraud system  runs contextualizer & crawler  runs semantic analyser  runs reports & suggestions system
  • 36. Building the LiveDB MySQL is the ACID DBMS MySQL is the non-ACID LiveDB. Python & Stored Procedures create LiveDB in a MySQL DBMS slave, MySQL replication pushes to the read-only slaves
  • 37.
  • 38. Availability & Reliability (no downtime please..)
  • 39.
  • 40. Reliability & Fault Tolerance Almost every service/component is redundant. Currently there are only 2 single points of failure:  Master DB server  Master LiveDB server And even if BOTH FAIL, we keep serving ads...
  • 41. Reliability & Fault Tolerance Failure in Master LiveDB server:  We have a hot spare,  Can change master in aprox 5 to 10 minutes Failure in Master DB: ● Data starts to pile up on Backend services ● Backoffices are unable to operate (no new ads) ● if failure lasts a long time: we might serve ads without budget ● Electing a new Master is performed manually Has happened before, no ad serving downtime.
  • 42. Scalability Issues We can scale horizontally in all but two components currently:  Master DBMS MySQL server (but we are far from saturating it..) we currently don't plan to 'solve' this  Master LiveDB server ...
  • 43. Scalability Issues Building LiveDB doesn't scale: ● We build a full new LiveDB everytime ● It isn't distributed nor is it easily made parallel ● Time is proportional to nº of active Bids LiveDB should be updated only with recent changes in ad pool. Impossible to do with current main DB data model and with current LiveDB design We are currently investing heavily on a solution to this, LiveCouchDB
  • 44. Monitoring & Logging (is everything okay?)
  • 45. Monitoring & Logging Bad things happen: Log it, deal with it... We need to know about it: monitor logs trigger alarm if errors on log..
  • 46. Monitoring & Alarmistics frontend code failures intercept error serve blank ad log error trigger alarm
  • 47. Monitoring & Alarmistics network failures reconnect with exponential backoff log error trigger alarm ?
  • 48. Monitoring & Alarmistics machine failures replication & redundancy save state to disk
  • 49. Monitoring & Alarmistics software bugs.. bad (or lack of) data radio silence log error trigger alarm
  • 51. Programming Languages Python (backend) Perl (frontend code) C (1 app only) Java (broker & reporting) PHP (backoffices) SQL Javascript