SlideShare a Scribd company logo
1 of 17
Download to read offline
Kevin	
  Ballard	
  
    kevin(at)tellapart(dot)com	
  




Image	
  ©2003-­‐2012	
  `DivineError	
  
TellApart’s	
  Infrastructure	
  Overview	
  
 •  Millions	
  of	
  daily	
  acIve	
  users	
  

 •  Page-­‐views	
  across	
  mulIple	
  sites	
  

 •  Real-­‐Time	
  Bidding	
  integraIon	
  
          - Very	
  high	
  volume,	
  low	
  latency	
  
          - Response	
  Ime:	
  50	
  percenIle:	
  17ms,	
  95	
  percenIle:	
  50	
  ms	
  	
  

 •  All	
  requests	
  require	
  user	
  data	
  

 •  EnIrely	
  Amazon	
  Web	
  Services	
  (AWS),	
  in	
  2	
  parallel	
  regions	
  



  2	
  
What	
  is	
  gevent?	
  



              gevent	
  is	
  a	
  corouIne-­‐based	
  Python	
  
              networking	
  library	
  that	
  uses	
  greenlet	
  to	
  
              provide	
  a	
  high-­‐level	
  synchronous	
  API	
  on	
  
              top	
  of	
  the	
  libevent	
  event	
  loop.	
  



  •  EssenIally,	
  allows	
  normally	
  synchronous	
  code	
  to	
  run	
  
     asynchronously	
  


  3	
  
What	
  is	
  gevent?	
  

  lib·∙e·∙vent	
  (ˈlib-­‐i-­‐ˈvent):	
  efficient	
  cross-­‐pla]orm	
  library	
  for	
  
        execuIng	
  callbacks	
  when	
  specific	
  events	
  occur	
  or	
  a	
  
        Imeout	
  has	
  been	
  reached.	
  Includes	
  several	
  
        networking	
  libraries	
  (e.g.	
  DNS,	
  HTTP)	
  
  	
  
  green·∙let	
  (ˈgrēn-­‐lət):	
  lightweight	
  co-­‐rouInes	
  for	
  in-­‐process	
  
        concurrent	
  programming.	
  Ported	
  from	
  Stackless	
  
        Python	
  as	
  a	
  library	
  for	
  the	
  CPython	
  interpreter	
  
  	
  
  	
  
  	
  
  4	
  
How	
  does	
  gevent	
  work?	
  

 •  One	
  gevent	
  “hub”	
  per	
  process	
  

 •  Monkey-­‐patch	
  blocking	
  libraries	
  
          - socket,	
  thread,	
  select,	
  etc.	
  


 •  Use	
  greenlets	
  like	
  threads	
  

 •  Blocking	
  calls	
  switch	
  to	
  another	
  (ready)	
  greenlet	
  



  5	
  
Example	
  Server	
  
mod_wsgi:	
             gevent:	
  




   6	
  
Example	
  Server	
  

 •  Server	
  implementaIon	
  is	
  the	
  same	
  

 •  DB	
  lookup	
  blocks	
  on	
  network	
  IO	
  

 •  With	
  gevent,	
  greenlet	
  gets	
  swapped	
  out	
  so	
  another	
  
    request	
  can	
  be	
  served	
  

 •  When	
  the	
  DB	
  request	
  finishes,	
  the	
  greenlet	
  will	
  
      conInue	
  where	
  it	
  lej	
  off	
  
 	
  

  7	
  
Advantages	
  
 •  Write	
  code	
  as	
  though	
  it	
  were	
  synchronous	
  (mostly)	
  
         - No	
  ‘callback	
  spaghen’	
  like	
  with	
  a	
  callback	
  framework	
  
         - Exact	
  same	
  code	
  can	
  run	
  synchronously	
  (e.g.	
  unit	
  tests)	
  

 •  Greenlets	
  are	
  very	
  lightweight	
  
         - 100’s	
  or	
  1000’s	
  can	
  run	
  concurrently	
  
         - No	
  context	
  switch	
  
              o    Same	
  order	
  of	
  magnitude	
  as	
  a	
  funcIon	
  call	
  
         - No	
  GIL	
  related	
  performance	
  issues	
  
         	
  
 •  Co-­‐operaIve	
  concurrency	
  makes	
  synchronizaIon	
  easy	
  
         - Greenlets	
  cannot	
  be	
  preempted	
  
         - No	
  need	
  for	
  in-­‐process	
  atomic	
  locks	
  
         - Ojen	
  eliminates	
  the	
  need	
  for	
  synchronizaIon	
  
              o    As	
  long	
  as	
  there	
  are	
  no	
  blocking	
  calls	
  in	
  the	
  criIcal	
  secIon	
  

 8	
  
Advantages	
  (conInued)	
  
 •  gevent	
  is	
  fast	
  
         - Very	
  thorough	
  set	
  of	
  benchmarks	
  by	
  Nicholas	
  Piël
           hrp://nichol.as/benchmark-­‐of-­‐python-­‐web-­‐servers	
  



            And	
  then	
  there	
  is	
  Gevent	
  [...]	
  
            	
  
            […]	
  if	
  you	
  want	
  to	
  dive	
  into	
  high	
  performance	
  websockets	
  with	
  
            lots	
  of	
  concurrent	
  connecIons	
  you	
  really	
  have	
  to	
  go	
  with	
  an	
  
            asynchronous	
  framework.	
  Gevent	
  seems	
  like	
  the	
  perfect	
  
            companion	
  for	
  that,	
  at	
  least	
  that	
  is	
  what	
  we	
  are	
  going	
  to	
  use.	
  
            	
  




 9	
  
Problems	
  
 •  Monkey-­‐patching	
  
          - Doesn’t	
  play	
  well	
  with	
  C	
  extensions	
  
               o    Blocking	
  code	
  in	
  C	
  libraries	
  will	
  cause	
  the	
  process	
  to	
  block	
  
          - Can	
  confuse	
  some	
  libraries	
  
               o    e.g.	
  thread-­‐local	
  storage	
  


 •  Breaks	
  analysis	
  tools	
  
          - cProfile	
  produces	
  garbage	
  
          - AlternaIve	
  tools	
  available	
  
               o    gevent-­‐profiler	
  (Meebo)	
  
               o    gevent_request_profiler	
  (TellApart)	
  

 •  Co-­‐operaIve	
  scheduling	
  
          - Rogue	
  greenlets	
  can	
  Ie	
  up	
  the	
  enIre	
  process	
  
               o    e.g.	
  CPU	
  bound	
  background	
  worker	
  
          - Long-­‐running	
  tasks	
  have	
  to	
  periodically	
  yield	
  
 10	
  
Problems	
  
               •  Same	
  server	
  as	
  before	
  
                  	
  
               •  Processing	
  in	
  loop	
  can	
  take	
  long	
  
                     •  Can	
  hurt	
  latency	
  of	
  other	
  requests	
  


               •  Add	
  ‘gevent.sleep(0)’	
  to	
  loop	
  

               •  Allows	
  other	
  greenlets	
  to	
  run	
  




 11	
  
Uses	
  

  •  We	
  use	
  gevent	
  everywhere	
  we	
  use	
  Python	
  

  •  TellApart	
  Front	
  End	
  (TAFE)	
  
           - gevent	
  WSGI	
  server	
  with	
  a	
  micro-­‐framework	
  
           - One	
  process	
  per	
  core	
  
           - Nginx	
  reverse-­‐proxy	
  in	
  front	
  

  •  Database	
  Proxy	
  (moxie)	
  
           - Thrij	
  service	
  
           - ConnecIon	
  pooling	
  across	
  clients	
  
           - Minimal	
  addiIonal	
  latency	
  (~2ms)	
  


  12	
  
Case	
  Study	
  -­‐	
  Taba	
  

  •  Taba	
  is	
  a	
  distributed	
  Event	
  AggregaIon	
  Service	
  

  •  Provides	
  near	
  real-­‐Ime	
  metrics	
  from	
  across	
  a	
  cluster	
  

  •  At	
  TellApart:	
  
           - 10,000	
  individual	
  Tabs	
  
           - 100’s	
  of	
  event	
  source	
  clients	
  
           - 20,000,000	
  events	
  /	
  minute	
  
           - 25	
  seconds	
  latency	
  from	
  real-­‐Ime	
  



  13	
  
Case	
  Study	
  -­‐	
  Taba	
  

                                   •  Implement	
  Imeouts	
  	
  
                                      very	
  easily	
  

                                   •  FuncIon	
  doesn’t	
  need	
  	
  
                                      to	
  know	
  it’s	
  being	
  Imed	
  




  14	
  
Case	
  Study	
  –	
  Taba	
  

                                 •  Perform	
  simultaneous	
  
                                    lookups	
  to	
  a	
  sharded	
  
                                    database	
  

                                 •  No	
  thread	
  pools	
  
                                    	
  
                                 •  No	
  need	
  for	
  locking	
  




  15	
  
Case	
  Study	
  –	
  Taba	
  

                                 •  Streaming	
  from	
  DB	
  in	
  
                                    batches	
  

                                 •  No	
  thread	
  pool	
  

                                 •  Trivial	
  synchronizaIon	
  

                                 •  Process	
  data	
  while	
  the	
  
                                    next	
  batch	
  is	
  retrieved	
  




  16	
  
Thank	
  you!	
  
                   	
  
                Kevin	
  Ballard	
  
         kevin(at)tellapart(dot)com	
  
                        	
  




17	
  

More Related Content

What's hot

On heap cache vs off-heap cache
On heap cache vs off-heap cacheOn heap cache vs off-heap cache
On heap cache vs off-heap cachergrebski
 
Cassandra and Storm at Health Market Sceince
Cassandra and Storm at Health Market SceinceCassandra and Storm at Health Market Sceince
Cassandra and Storm at Health Market SceinceP. Taylor Goetz
 
Scaling Apache Storm (Hadoop Summit 2015)
Scaling Apache Storm (Hadoop Summit 2015)Scaling Apache Storm (Hadoop Summit 2015)
Scaling Apache Storm (Hadoop Summit 2015)Robert Evans
 
PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.DECK36
 
Realtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQRealtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQXin Wang
 
Multi-Tenant Storm Service on Hadoop Grid
Multi-Tenant Storm Service on Hadoop GridMulti-Tenant Storm Service on Hadoop Grid
Multi-Tenant Storm Service on Hadoop GridDataWorks Summit
 
Storm: The Real-Time Layer - GlueCon 2012
Storm: The Real-Time Layer  - GlueCon 2012Storm: The Real-Time Layer  - GlueCon 2012
Storm: The Real-Time Layer - GlueCon 2012Dan Lynn
 
Storm Real Time Computation
Storm Real Time ComputationStorm Real Time Computation
Storm Real Time ComputationSonal Raj
 
Experience with Kafka & Storm
Experience with Kafka & StormExperience with Kafka & Storm
Experience with Kafka & StormOtto Mok
 
Resource Scheduling using Apache Mesos in Cloud Native Environments
Resource Scheduling using Apache Mesos in Cloud Native EnvironmentsResource Scheduling using Apache Mesos in Cloud Native Environments
Resource Scheduling using Apache Mesos in Cloud Native EnvironmentsSharma Podila
 
Real-Time Big Data at In-Memory Speed, Using Storm
Real-Time Big Data at In-Memory Speed, Using StormReal-Time Big Data at In-Memory Speed, Using Storm
Real-Time Big Data at In-Memory Speed, Using StormNati Shalom
 
Real-time Big Data Processing with Storm
Real-time Big Data Processing with StormReal-time Big Data Processing with Storm
Real-time Big Data Processing with Stormviirya
 
Improved Reliable Streaming Processing: Apache Storm as example
Improved Reliable Streaming Processing: Apache Storm as exampleImproved Reliable Streaming Processing: Apache Storm as example
Improved Reliable Streaming Processing: Apache Storm as exampleDataWorks Summit/Hadoop Summit
 
Apache Storm and twitter Streaming API integration
Apache Storm and twitter Streaming API integrationApache Storm and twitter Streaming API integration
Apache Storm and twitter Streaming API integrationUday Vakalapudi
 
Kubernetes Observability with Prometheus by Example
Kubernetes Observability with Prometheus by ExampleKubernetes Observability with Prometheus by Example
Kubernetes Observability with Prometheus by ExampleThomas Riley
 
Stream Processing Frameworks
Stream Processing FrameworksStream Processing Frameworks
Stream Processing FrameworksSirKetchup
 

What's hot (20)

On heap cache vs off-heap cache
On heap cache vs off-heap cacheOn heap cache vs off-heap cache
On heap cache vs off-heap cache
 
Cassandra and Storm at Health Market Sceince
Cassandra and Storm at Health Market SceinceCassandra and Storm at Health Market Sceince
Cassandra and Storm at Health Market Sceince
 
Storm
StormStorm
Storm
 
Resource Aware Scheduling in Apache Storm
Resource Aware Scheduling in Apache StormResource Aware Scheduling in Apache Storm
Resource Aware Scheduling in Apache Storm
 
Scaling Apache Storm (Hadoop Summit 2015)
Scaling Apache Storm (Hadoop Summit 2015)Scaling Apache Storm (Hadoop Summit 2015)
Scaling Apache Storm (Hadoop Summit 2015)
 
Introduction to Apache Storm
Introduction to Apache StormIntroduction to Apache Storm
Introduction to Apache Storm
 
PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.PHP Backends for Real-Time User Interaction using Apache Storm.
PHP Backends for Real-Time User Interaction using Apache Storm.
 
Realtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQRealtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQ
 
Multi-Tenant Storm Service on Hadoop Grid
Multi-Tenant Storm Service on Hadoop GridMulti-Tenant Storm Service on Hadoop Grid
Multi-Tenant Storm Service on Hadoop Grid
 
Storm: The Real-Time Layer - GlueCon 2012
Storm: The Real-Time Layer  - GlueCon 2012Storm: The Real-Time Layer  - GlueCon 2012
Storm: The Real-Time Layer - GlueCon 2012
 
Storm Real Time Computation
Storm Real Time ComputationStorm Real Time Computation
Storm Real Time Computation
 
Apache Storm
Apache StormApache Storm
Apache Storm
 
Experience with Kafka & Storm
Experience with Kafka & StormExperience with Kafka & Storm
Experience with Kafka & Storm
 
Resource Scheduling using Apache Mesos in Cloud Native Environments
Resource Scheduling using Apache Mesos in Cloud Native EnvironmentsResource Scheduling using Apache Mesos in Cloud Native Environments
Resource Scheduling using Apache Mesos in Cloud Native Environments
 
Real-Time Big Data at In-Memory Speed, Using Storm
Real-Time Big Data at In-Memory Speed, Using StormReal-Time Big Data at In-Memory Speed, Using Storm
Real-Time Big Data at In-Memory Speed, Using Storm
 
Real-time Big Data Processing with Storm
Real-time Big Data Processing with StormReal-time Big Data Processing with Storm
Real-time Big Data Processing with Storm
 
Improved Reliable Streaming Processing: Apache Storm as example
Improved Reliable Streaming Processing: Apache Storm as exampleImproved Reliable Streaming Processing: Apache Storm as example
Improved Reliable Streaming Processing: Apache Storm as example
 
Apache Storm and twitter Streaming API integration
Apache Storm and twitter Streaming API integrationApache Storm and twitter Streaming API integration
Apache Storm and twitter Streaming API integration
 
Kubernetes Observability with Prometheus by Example
Kubernetes Observability with Prometheus by ExampleKubernetes Observability with Prometheus by Example
Kubernetes Observability with Prometheus by Example
 
Stream Processing Frameworks
Stream Processing FrameworksStream Processing Frameworks
Stream Processing Frameworks
 

Viewers also liked

London React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor CharyparLondon React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor CharyparReact London Community
 
Airbnb tech talk: Levi Weintraub on webkit
Airbnb tech talk: Levi Weintraub on webkitAirbnb tech talk: Levi Weintraub on webkit
Airbnb tech talk: Levi Weintraub on webkitnaseemh
 
Анонимные записи в Haskell. Никита Волков
Анонимные записи в Haskell. Никита ВолковАнонимные записи в Haskell. Никита Волков
Анонимные записи в Haskell. Никита ВолковЮрий Сыровецкий
 
Монады для барабанщиков. Антон Холомьёв
Монады для барабанщиков. Антон ХоломьёвМонады для барабанщиков. Антон Холомьёв
Монады для барабанщиков. Антон ХоломьёвЮрий Сыровецкий
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional ProgrammingHugo Firth
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
DNS Security Presentation ISSA
DNS Security Presentation ISSADNS Security Presentation ISSA
DNS Security Presentation ISSASrikrupa Srivatsan
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013mumrah
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.Taras Matyashovsky
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & FeaturesDataStax Academy
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureDan McKinley
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeperSaurav Haloi
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
 
Image Optimization for the Web at php|works
Image Optimization for the Web at php|worksImage Optimization for the Web at php|works
Image Optimization for the Web at php|worksStoyan Stefanov
 
Building a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
Building a Simple Mobile-optimized Web App Using the jQuery Mobile FrameworkBuilding a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
Building a Simple Mobile-optimized Web App Using the jQuery Mobile FrameworkSt. Petersburg College
 
Introduction to jQuery Mobile - Web Deliver for All
Introduction to jQuery Mobile - Web Deliver for AllIntroduction to jQuery Mobile - Web Deliver for All
Introduction to jQuery Mobile - Web Deliver for AllMarc Grabanski
 

Viewers also liked (20)

London React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor CharyparLondon React August - GraphQL at The Financial Times - Viktor Charypar
London React August - GraphQL at The Financial Times - Viktor Charypar
 
Airbnb tech talk: Levi Weintraub on webkit
Airbnb tech talk: Levi Weintraub on webkitAirbnb tech talk: Levi Weintraub on webkit
Airbnb tech talk: Levi Weintraub on webkit
 
Анонимные записи в Haskell. Никита Волков
Анонимные записи в Haskell. Никита ВолковАнонимные записи в Haskell. Никита Волков
Анонимные записи в Haskell. Никита Волков
 
Монады для барабанщиков. Антон Холомьёв
Монады для барабанщиков. Антон ХоломьёвМонады для барабанщиков. Антон Холомьёв
Монады для барабанщиков. Антон Холомьёв
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
DNS Security Presentation ISSA
DNS Security Presentation ISSADNS Security Presentation ISSA
DNS Security Presentation ISSA
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & Features
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds Architecture
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeper
 
Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBase
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
Apache Spark Architecture
Apache Spark ArchitectureApache Spark Architecture
Apache Spark Architecture
 
Image Optimization for the Web at php|works
Image Optimization for the Web at php|worksImage Optimization for the Web at php|works
Image Optimization for the Web at php|works
 
Business Quotes for 2011
Business Quotes for 2011Business Quotes for 2011
Business Quotes for 2011
 
Building a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
Building a Simple Mobile-optimized Web App Using the jQuery Mobile FrameworkBuilding a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
Building a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
 
Introduction to jQuery Mobile - Web Deliver for All
Introduction to jQuery Mobile - Web Deliver for AllIntroduction to jQuery Mobile - Web Deliver for All
Introduction to jQuery Mobile - Web Deliver for All
 

Similar to gevent at TellApart

Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Studyelliando dias
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Martijn Verburg
 
Scale your Alfresco Solutions
Scale your Alfresco Solutions Scale your Alfresco Solutions
Scale your Alfresco Solutions Alfresco Software
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Martijn Verburg
 
High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2ScribbleLive
 
Tale of two streaming frameworks- Apace Storm & Apache Flink
Tale of two streaming frameworks- Apace Storm & Apache FlinkTale of two streaming frameworks- Apace Storm & Apache Flink
Tale of two streaming frameworks- Apace Storm & Apache FlinkKarthik Deivasigamani
 
Tale of two streaming frameworks (Karthik D - Walmart)
Tale of two streaming frameworks (Karthik D - Walmart)Tale of two streaming frameworks (Karthik D - Walmart)
Tale of two streaming frameworks (Karthik D - Walmart)KafkaZone
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640LLC NewLink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Newlink
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInLinkedIn
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
Parallel and Asynchronous Programming -  ITProDevConnections 2012 (Greek)Parallel and Asynchronous Programming -  ITProDevConnections 2012 (Greek)
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)Panagiotis Kanavos
 
Multi core programming 2
Multi core programming 2Multi core programming 2
Multi core programming 2Robin Aggarwal
 
Ceph in the GRNET cloud stack
Ceph in the GRNET cloud stackCeph in the GRNET cloud stack
Ceph in the GRNET cloud stackNikos Kormpakis
 

Similar to gevent at TellApart (20)

Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
Why Play Framework is fast
Why Play Framework is fastWhy Play Framework is fast
Why Play Framework is fast
 
Scale your Alfresco Solutions
Scale your Alfresco Solutions Scale your Alfresco Solutions
Scale your Alfresco Solutions
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
 
High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2High Scalability Toronto: Meetup #2
High Scalability Toronto: Meetup #2
 
Tale of two streaming frameworks- Apace Storm & Apache Flink
Tale of two streaming frameworks- Apace Storm & Apache FlinkTale of two streaming frameworks- Apace Storm & Apache Flink
Tale of two streaming frameworks- Apace Storm & Apache Flink
 
Tale of two streaming frameworks (Karthik D - Walmart)
Tale of two streaming frameworks (Karthik D - Walmart)Tale of two streaming frameworks (Karthik D - Walmart)
Tale of two streaming frameworks (Karthik D - Walmart)
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640Xen and-the-art-of-rails-deployment2640
Xen and-the-art-of-rails-deployment2640
 
Concept of thread
Concept of threadConcept of thread
Concept of thread
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
Parallel and Asynchronous Programming -  ITProDevConnections 2012 (Greek)Parallel and Asynchronous Programming -  ITProDevConnections 2012 (Greek)
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
 
Async programming in c#
Async programming in c#Async programming in c#
Async programming in c#
 
Multi core programming 2
Multi core programming 2Multi core programming 2
Multi core programming 2
 
Background processing with hangfire
Background processing with hangfireBackground processing with hangfire
Background processing with hangfire
 
Ceph in the GRNET cloud stack
Ceph in the GRNET cloud stackCeph in the GRNET cloud stack
Ceph in the GRNET cloud stack
 

Recently uploaded

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
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
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
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
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
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
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
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
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 

gevent at TellApart

  • 1. Kevin  Ballard   kevin(at)tellapart(dot)com   Image  ©2003-­‐2012  `DivineError  
  • 2. TellApart’s  Infrastructure  Overview   •  Millions  of  daily  acIve  users   •  Page-­‐views  across  mulIple  sites   •  Real-­‐Time  Bidding  integraIon   - Very  high  volume,  low  latency   - Response  Ime:  50  percenIle:  17ms,  95  percenIle:  50  ms     •  All  requests  require  user  data   •  EnIrely  Amazon  Web  Services  (AWS),  in  2  parallel  regions   2  
  • 3. What  is  gevent?   gevent  is  a  corouIne-­‐based  Python   networking  library  that  uses  greenlet  to   provide  a  high-­‐level  synchronous  API  on   top  of  the  libevent  event  loop.   •  EssenIally,  allows  normally  synchronous  code  to  run   asynchronously   3  
  • 4. What  is  gevent?   lib·∙e·∙vent  (ˈlib-­‐i-­‐ˈvent):  efficient  cross-­‐pla]orm  library  for   execuIng  callbacks  when  specific  events  occur  or  a   Imeout  has  been  reached.  Includes  several   networking  libraries  (e.g.  DNS,  HTTP)     green·∙let  (ˈgrēn-­‐lət):  lightweight  co-­‐rouInes  for  in-­‐process   concurrent  programming.  Ported  from  Stackless   Python  as  a  library  for  the  CPython  interpreter         4  
  • 5. How  does  gevent  work?   •  One  gevent  “hub”  per  process   •  Monkey-­‐patch  blocking  libraries   - socket,  thread,  select,  etc.   •  Use  greenlets  like  threads   •  Blocking  calls  switch  to  another  (ready)  greenlet   5  
  • 6. Example  Server   mod_wsgi:   gevent:   6  
  • 7. Example  Server   •  Server  implementaIon  is  the  same   •  DB  lookup  blocks  on  network  IO   •  With  gevent,  greenlet  gets  swapped  out  so  another   request  can  be  served   •  When  the  DB  request  finishes,  the  greenlet  will   conInue  where  it  lej  off     7  
  • 8. Advantages   •  Write  code  as  though  it  were  synchronous  (mostly)   - No  ‘callback  spaghen’  like  with  a  callback  framework   - Exact  same  code  can  run  synchronously  (e.g.  unit  tests)   •  Greenlets  are  very  lightweight   - 100’s  or  1000’s  can  run  concurrently   - No  context  switch   o  Same  order  of  magnitude  as  a  funcIon  call   - No  GIL  related  performance  issues     •  Co-­‐operaIve  concurrency  makes  synchronizaIon  easy   - Greenlets  cannot  be  preempted   - No  need  for  in-­‐process  atomic  locks   - Ojen  eliminates  the  need  for  synchronizaIon   o  As  long  as  there  are  no  blocking  calls  in  the  criIcal  secIon   8  
  • 9. Advantages  (conInued)   •  gevent  is  fast   - Very  thorough  set  of  benchmarks  by  Nicholas  Piël hrp://nichol.as/benchmark-­‐of-­‐python-­‐web-­‐servers   And  then  there  is  Gevent  [...]     […]  if  you  want  to  dive  into  high  performance  websockets  with   lots  of  concurrent  connecIons  you  really  have  to  go  with  an   asynchronous  framework.  Gevent  seems  like  the  perfect   companion  for  that,  at  least  that  is  what  we  are  going  to  use.     9  
  • 10. Problems   •  Monkey-­‐patching   - Doesn’t  play  well  with  C  extensions   o  Blocking  code  in  C  libraries  will  cause  the  process  to  block   - Can  confuse  some  libraries   o  e.g.  thread-­‐local  storage   •  Breaks  analysis  tools   - cProfile  produces  garbage   - AlternaIve  tools  available   o  gevent-­‐profiler  (Meebo)   o  gevent_request_profiler  (TellApart)   •  Co-­‐operaIve  scheduling   - Rogue  greenlets  can  Ie  up  the  enIre  process   o  e.g.  CPU  bound  background  worker   - Long-­‐running  tasks  have  to  periodically  yield   10  
  • 11. Problems   •  Same  server  as  before     •  Processing  in  loop  can  take  long   •  Can  hurt  latency  of  other  requests   •  Add  ‘gevent.sleep(0)’  to  loop   •  Allows  other  greenlets  to  run   11  
  • 12. Uses   •  We  use  gevent  everywhere  we  use  Python   •  TellApart  Front  End  (TAFE)   - gevent  WSGI  server  with  a  micro-­‐framework   - One  process  per  core   - Nginx  reverse-­‐proxy  in  front   •  Database  Proxy  (moxie)   - Thrij  service   - ConnecIon  pooling  across  clients   - Minimal  addiIonal  latency  (~2ms)   12  
  • 13. Case  Study  -­‐  Taba   •  Taba  is  a  distributed  Event  AggregaIon  Service   •  Provides  near  real-­‐Ime  metrics  from  across  a  cluster   •  At  TellApart:   - 10,000  individual  Tabs   - 100’s  of  event  source  clients   - 20,000,000  events  /  minute   - 25  seconds  latency  from  real-­‐Ime   13  
  • 14. Case  Study  -­‐  Taba   •  Implement  Imeouts     very  easily   •  FuncIon  doesn’t  need     to  know  it’s  being  Imed   14  
  • 15. Case  Study  –  Taba   •  Perform  simultaneous   lookups  to  a  sharded   database   •  No  thread  pools     •  No  need  for  locking   15  
  • 16. Case  Study  –  Taba   •  Streaming  from  DB  in   batches   •  No  thread  pool   •  Trivial  synchronizaIon   •  Process  data  while  the   next  batch  is  retrieved   16  
  • 17. Thank  you!     Kevin  Ballard   kevin(at)tellapart(dot)com     17