SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler 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	
  

Mais conteúdo relacionado

Mais procurados

Ceph Day Melbourne - Scale and performance: Servicing the Fabric and the Work...
Ceph Day Melbourne - Scale and performance: Servicing the Fabric and the Work...Ceph Day Melbourne - Scale and performance: Servicing the Fabric and the Work...
Ceph Day Melbourne - Scale and performance: Servicing the Fabric and the Work...Ceph Community
 
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorganShared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorganHazelcast
 
Ceph Day Melabourne - Community Update
Ceph Day Melabourne - Community UpdateCeph Day Melabourne - Community Update
Ceph Day Melabourne - Community UpdateCeph Community
 
Kubernetes at NU.nl (Kubernetes meetup 2019-09-05)
Kubernetes at NU.nl   (Kubernetes meetup 2019-09-05)Kubernetes at NU.nl   (Kubernetes meetup 2019-09-05)
Kubernetes at NU.nl (Kubernetes meetup 2019-09-05)Tibo Beijen
 
Include os @ flossuk 2018
Include os @ flossuk 2018Include os @ flossuk 2018
Include os @ flossuk 2018Per Buer
 
Open HFT libraries in @Java
Open HFT libraries in @JavaOpen HFT libraries in @Java
Open HFT libraries in @JavaPeter Lawrey
 
Global deduplication for Ceph - Myoungwon Oh
Global deduplication for Ceph - Myoungwon OhGlobal deduplication for Ceph - Myoungwon Oh
Global deduplication for Ceph - Myoungwon OhCeph Community
 
Deterministic behaviour and performance in trading systems
Deterministic behaviour and performance in trading systemsDeterministic behaviour and performance in trading systems
Deterministic behaviour and performance in trading systemsPeter Lawrey
 
Accelerating Ceph with iWARP RDMA over Ethernet - Brien Porter, Haodong Tang
Accelerating Ceph with iWARP RDMA over Ethernet - Brien Porter, Haodong TangAccelerating Ceph with iWARP RDMA over Ethernet - Brien Porter, Haodong Tang
Accelerating Ceph with iWARP RDMA over Ethernet - Brien Porter, Haodong TangCeph Community
 
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...ScyllaDB
 
High perf-networking
High perf-networkingHigh perf-networking
High perf-networkingmtimjones
 
WebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsWebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsMaarten Smeets
 
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex LauDoing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex LauCeph Community
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.jsNitin Gupta
 
Low latency for high throughput
Low latency for high throughputLow latency for high throughput
Low latency for high throughputPeter Lawrey
 
High Frequency Trading and NoSQL database
High Frequency Trading and NoSQL databaseHigh Frequency Trading and NoSQL database
High Frequency Trading and NoSQL databasePeter Lawrey
 
Low level java programming
Low level java programmingLow level java programming
Low level java programmingPeter Lawrey
 
Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...
Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...
Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...Ceph Community
 

Mais procurados (20)

Ceph Day Melbourne - Scale and performance: Servicing the Fabric and the Work...
Ceph Day Melbourne - Scale and performance: Servicing the Fabric and the Work...Ceph Day Melbourne - Scale and performance: Servicing the Fabric and the Work...
Ceph Day Melbourne - Scale and performance: Servicing the Fabric and the Work...
 
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorganShared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
 
OpenStack@NBU
OpenStack@NBUOpenStack@NBU
OpenStack@NBU
 
Ceph Day Melabourne - Community Update
Ceph Day Melabourne - Community UpdateCeph Day Melabourne - Community Update
Ceph Day Melabourne - Community Update
 
Kubernetes at NU.nl (Kubernetes meetup 2019-09-05)
Kubernetes at NU.nl   (Kubernetes meetup 2019-09-05)Kubernetes at NU.nl   (Kubernetes meetup 2019-09-05)
Kubernetes at NU.nl (Kubernetes meetup 2019-09-05)
 
Include os @ flossuk 2018
Include os @ flossuk 2018Include os @ flossuk 2018
Include os @ flossuk 2018
 
Open HFT libraries in @Java
Open HFT libraries in @JavaOpen HFT libraries in @Java
Open HFT libraries in @Java
 
Global deduplication for Ceph - Myoungwon Oh
Global deduplication for Ceph - Myoungwon OhGlobal deduplication for Ceph - Myoungwon Oh
Global deduplication for Ceph - Myoungwon Oh
 
Deterministic behaviour and performance in trading systems
Deterministic behaviour and performance in trading systemsDeterministic behaviour and performance in trading systems
Deterministic behaviour and performance in trading systems
 
Accelerating Ceph with iWARP RDMA over Ethernet - Brien Porter, Haodong Tang
Accelerating Ceph with iWARP RDMA over Ethernet - Brien Porter, Haodong TangAccelerating Ceph with iWARP RDMA over Ethernet - Brien Porter, Haodong Tang
Accelerating Ceph with iWARP RDMA over Ethernet - Brien Porter, Haodong Tang
 
Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...Keeping Latency Low and Throughput High with Application-level Priority Manag...
Keeping Latency Low and Throughput High with Application-level Priority Manag...
 
High perf-networking
High perf-networkingHigh perf-networking
High perf-networking
 
WebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsWebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck Threads
 
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex LauDoing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
 
Evented Ruby VS Node.js
Evented Ruby VS Node.jsEvented Ruby VS Node.js
Evented Ruby VS Node.js
 
Low latency for high throughput
Low latency for high throughputLow latency for high throughput
Low latency for high throughput
 
High Frequency Trading and NoSQL database
High Frequency Trading and NoSQL databaseHigh Frequency Trading and NoSQL database
High Frequency Trading and NoSQL database
 
Os Lamothe
Os LamotheOs Lamothe
Os Lamothe
 
Low level java programming
Low level java programmingLow level java programming
Low level java programming
 
Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...
Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...
Ceph Day London 2014 - Best Practices for Ceph-powered Implementations of Sto...
 

Semelhante a 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-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
 
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
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudyJohn Adams
 

Semelhante a 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
 
John adams talk cloudy
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudy
 

Último

Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 

Último (20)

Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 
How Tech Giants Cut Corners to Harvest Data for A.I.
How Tech Giants Cut Corners to Harvest Data for A.I.How Tech Giants Cut Corners to Harvest Data for A.I.
How Tech Giants Cut Corners to Harvest Data for A.I.
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 

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