SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
How Do You Solve a Problem Like
        Santa Claus ?
      Prototyping Join Patterns with
     stackless.py for Stackless Python
              Andrew Francis
         af.stackless@gmail.com
           Montreal Python 26
           December 17th, 2011
Exploring           Feedback
         Play
                      Fearless Programming
 Trial-and-error
                                 Learning
   Serendipity      Syncretism

Innovation      Baling wire and Chewing Gum

      Challenges        Friendship
The Santa Claus Problem

Santa repeatedly sleeps until wakened by either all of his nine rein-
deer, back from their holidays, or by a group of three of his ten
elves. If awakened by the reindeer, he harnesses each of them to his
sleigh, delivers toys with them and finally unharnesses them
(allowing them to go off on holiday). If awakened by a group of
elves, he shows each of the group into his study, consults with them
on toy R&D and finally shows them each out (allowing them to go
back to work).

Santa should give priority to the reindeer in the case that there is
both a group of elves and a group of reindeer waiting.
Perception




Taken from The Santa Claus Problem: Thread Synchronization
Reality




http://www.youtube.com/watch?v=pqO6tKN2lc4
Solutions Through The Years

Year    Language        Mechanism
1994    C               Semaphores
1997    Ada 95          Protected objects,
                        Rendezvous (select)
2003    Polyphonic C#   Join Patterns
2007    Haskell         Software
                        Transactional
                        Memory
Join Patterns a la Polyphonic C#
 class Join2 {
    void wait(out int i, out int j)
    & async first(int r1)
    & async second(int r2) {
          i = r1; j = r2; return;
    }
 }

 //client code
 int i,j;
 Join2 x = new Join2();
 ...
 //synchronous method will block
 x.wait(i,j);
 // do something with i and j
Chord Rules
• When pending method calls match a pattern, its
  body runs.
• If there is no match, the invocations are queued
  up.
• If there are several matches, an unspecified
  pattern is selected.
• If receiver is synchronous, body executes in
  receiver’s thread.
• If only asynchronous methods, the body runs in a
  new thread.
Stackless Python
• Superset of CPython.
  – Inspired by Bell Labs Limbo language
• Reputation for user space threads too cheap
  to meter.
• Cooperative and pre-emptive multi-tasking.
Example
import stackless

def producer(aChannel):
    aChannel.send("hello")

def consumer(aChannel):
    print aChannel.receive()

aChannel = stackless.channel()
stackless.tasklet(producer)(aChannel)
stackless.tasklet(consumer)(aChannel)
stackless.schedule()
Synchronous Channels
Before: [producer, …+scheduler
        (producer, send,“hello”) -> [ ] receive

After : [producer]scheduler
        * (producer, send, “hello”) ]send

Before: (consumer, receive, null) -> [(Producer)]send
After: (1) consumer.val = “hello”
       (2) [(producer, send, “hello”),…]send
       (3) *…, Producer+scheduler
The Select Algorithm
Question


Question: Why is knowing about
select() important?
Answers
• Stackless Python did not originally implement
  select().
  – This is proof-of-concept that we can modify
    stackless.py to create new features
• Select() is used under the hood to implement
  join patterns
• We are going to extend the select algorithm
  developed in “Prototyping Go’s Select with
  stackless.py” to include join patterns.
Christian Tismer’s Sleight of Hand
• Stackless Python does not support select()
• Eliminated a queue
• Created a channel property: balance
  – > 0 : senders on the queue
  – < 0 : receivers on the queue
  – 0: empty
stackless.py
• A PyPy module that implements the Stackless
  Python API
• Written in Python!
• Low level concurrency provided by different
  packages
  – greenlets
  – Continulets
Strategy
• Implemented sub-set of join pattern’s
  behaviour
  – Synchronous receiver
  – No built-in asynchrony


• object.method = channel.receive()
  – i.e., join2.wait() equivalent to join2.receive()
  – Simplifies API
Strategy
• Why implement a method body (and class) for
  synchronization patterns?
  – we already have channels.
  – Message bodies seem to exist to store internal
    messages and compute a return value ?
• Rather
  – return all internally queued values associated with
    pattern.
  – let receiver decide what to do.
Another Sleight of Hand

              JoinPattern

     action()
                      chanop     chanop         chanop
      add()

     ready()

    remove()




-   A join pattern is a composite channel operation
-   A join pattern uses the same interface as a channel
    operation
-   Now we can express disjunctions of conjunctions!
Famous Last Words
(Le Mot de Cambronne)
“All or Nothing” (“Atomicity”)

   (Dancer), (Dasher),(Vixen),(Comet),(Cupid),(Doner),(Blitzen),(Rudolph)


                                                                (“stackless scheduler”)

                                                                     application

 Reindeer Join Pattern

(Dancer), (Dasher),(Vixen),(Comet),(Cupid),(Doner),(Blitzen),(Rudolph)



       Transfer all the data if and only if all nine reindeer
       channels are ready
New Rules

Postpone Rendezvous (lazy acquire)

Before: (rudolph, S, msg) -> [(Santa,JR) ] rudolph-receive
After : [ (rudolph,join-send, msg) ]rudolph-send


Steal

Before: (Mrs Claus, R, Null) -> [(rudolph,JS,msg)send
After : Mrs Claus.val = msg
        [(Santa,JR) ] rudolph-receive
Words of Wisdom

Hence plan to throw one away; you
will, anyhow.

--Fred Brooks (on pilot projects)
Lessons Learnt
• Asynchrony matters
  – Prototype not powerful enough to handle Dining
    Philosophers
  – Synchronous channels with buffers.
• Atomicity a powerful feature.
  – In case of Dining Philosophers, just does the right
    thing
• “Transactional” logic and expressiveness
  come to the forefront quickly.
Status
• Prototype is still held together by baling wire
  and chewing gum.
• A lot of work needs to be done before it is
  prime time
A New Language: Conversation with
   Scalable Join Pattern’s Authors

            Concurrent ML
                                     Atomic transactions

 Transactional events
                               Eager and lazy acquire

        Composibility
                               Lock-free data structures
Optimistic locking protocols

                     Inevitability
The Ghosts of Software Present, Past,
            and Future
            The Present: Concurrent ML:
                   guard(event, f)

  The Past: Chandler Notification Manager 2.0 (R.I.P):
       eval(“city == MTL and band == Interpol”)

    The Future: C.E.P & S.0.A with Stackless Python:
   Guard(function(chanop.val), concertFeedChannel)
 return eval(“city=MTL and band==Hannah Georgas”)
References
•   The Santa Claus Problem: Thread Synchronization,
    http://www.youtube.com/watch?v=pqO6tKN2lc4
•   Scalable Join Patterns, Claudo Russo & Aaron Turon,
    http://www.ccs.neu.edu/home/turon/scalable-joins.pdf
•   Jingle Bells, Solving the Santa Claus Problem in Polyphonic #C,
    http://research.microsoft.com/en-us/um/people/nick/polyphony/
•   The Polyphonic #C Bedroom Poster, http://research.microsoft.com/en-
    us/um/people/nick/polyphony/polyphoniccsharpposter2002.ppt
•   http://swtch.com/usr/local/plan9/src/libthread/channel.c, Russ Cox
•   Concurrent Programming in ML.
    John H. Reppy. Cambridge University Press, Cambridge, England, 1999.
•   The Notification Manager, http://www.osafoundation.org/archives/2003_11.html
•   stackless.py (with select),
    http://stacklessexamples.googlecode.com/svn/trunk/sandbox/select/stackless.py
•   Prototyping Go’s Select with stackless.py for Stackless Python,
    http://andrewfr.files.wordpress.com/2010/07/july31revised.pdf
For More information



http://andrewfr.wordpress.com
Joyeux Noël

Contenu connexe

Tendances

What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...Simplilearn
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Databricks
 
Anil Thomas - Object recognition
Anil Thomas - Object recognitionAnil Thomas - Object recognition
Anil Thomas - Object recognitionIntel Nervana
 
Modeling Electronic Health Records with Recurrent Neural Networks
Modeling Electronic Health Records with Recurrent Neural NetworksModeling Electronic Health Records with Recurrent Neural Networks
Modeling Electronic Health Records with Recurrent Neural NetworksJosh Patterson
 
Deep Learning through Examples
Deep Learning through ExamplesDeep Learning through Examples
Deep Learning through ExamplesSri Ambati
 

Tendances (9)

What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
What is TensorFlow? | Introduction to TensorFlow | TensorFlow Tutorial For Be...
 
Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0Introduction to TensorFlow 2.0
Introduction to TensorFlow 2.0
 
Anil Thomas - Object recognition
Anil Thomas - Object recognitionAnil Thomas - Object recognition
Anil Thomas - Object recognition
 
Modeling Electronic Health Records with Recurrent Neural Networks
Modeling Electronic Health Records with Recurrent Neural NetworksModeling Electronic Health Records with Recurrent Neural Networks
Modeling Electronic Health Records with Recurrent Neural Networks
 
Deep Learning through Examples
Deep Learning through ExamplesDeep Learning through Examples
Deep Learning through Examples
 
Math synonyms
Math synonymsMath synonyms
Math synonyms
 
Sync considered unethical
Sync considered unethicalSync considered unethical
Sync considered unethical
 
2017 10 17_quantum_program_v2
2017 10 17_quantum_program_v22017 10 17_quantum_program_v2
2017 10 17_quantum_program_v2
 
Quantum programming
Quantum programmingQuantum programming
Quantum programming
 

En vedette

Mp26 : Tachyon, sloppiness is bliss
Mp26 : Tachyon, sloppiness is blissMp26 : Tachyon, sloppiness is bliss
Mp26 : Tachyon, sloppiness is blissMontreal Python
 
Mp25: Optical Music Recognition with Python
Mp25: Optical Music Recognition with PythonMp25: Optical Music Recognition with Python
Mp25: Optical Music Recognition with PythonMontreal Python
 
Mp25 Message Switching for Actor Based Designs
Mp25 Message Switching for Actor Based DesignsMp25 Message Switching for Actor Based Designs
Mp25 Message Switching for Actor Based DesignsMontreal Python
 
Mp24: Fabulous Mobile Development with and without Python
Mp24: Fabulous Mobile Development with and without PythonMp24: Fabulous Mobile Development with and without Python
Mp24: Fabulous Mobile Development with and without PythonMontreal Python
 
Mp26 : Connecting Startups with Talents
Mp26 : Connecting Startups with TalentsMp26 : Connecting Startups with Talents
Mp26 : Connecting Startups with TalentsMontreal Python
 
Mp25: Audio Fingerprinting and metadata correction with Python
Mp25: Audio Fingerprinting and metadata correction with PythonMp25: Audio Fingerprinting and metadata correction with Python
Mp25: Audio Fingerprinting and metadata correction with PythonMontreal Python
 
Mp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook gameMp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook gameMontreal Python
 

En vedette (7)

Mp26 : Tachyon, sloppiness is bliss
Mp26 : Tachyon, sloppiness is blissMp26 : Tachyon, sloppiness is bliss
Mp26 : Tachyon, sloppiness is bliss
 
Mp25: Optical Music Recognition with Python
Mp25: Optical Music Recognition with PythonMp25: Optical Music Recognition with Python
Mp25: Optical Music Recognition with Python
 
Mp25 Message Switching for Actor Based Designs
Mp25 Message Switching for Actor Based DesignsMp25 Message Switching for Actor Based Designs
Mp25 Message Switching for Actor Based Designs
 
Mp24: Fabulous Mobile Development with and without Python
Mp24: Fabulous Mobile Development with and without PythonMp24: Fabulous Mobile Development with and without Python
Mp24: Fabulous Mobile Development with and without Python
 
Mp26 : Connecting Startups with Talents
Mp26 : Connecting Startups with TalentsMp26 : Connecting Startups with Talents
Mp26 : Connecting Startups with Talents
 
Mp25: Audio Fingerprinting and metadata correction with Python
Mp25: Audio Fingerprinting and metadata correction with PythonMp25: Audio Fingerprinting and metadata correction with Python
Mp25: Audio Fingerprinting and metadata correction with Python
 
Mp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook gameMp24: The Bachelor, a facebook game
Mp24: The Bachelor, a facebook game
 

Similaire à How Do You Solve the Santa Claus Problem with Join Patterns

Music recommendations @ MLConf 2014
Music recommendations @ MLConf 2014Music recommendations @ MLConf 2014
Music recommendations @ MLConf 2014Erik Bernhardsson
 
The Nature of Code via Cinder - Modeling the Natural World in C++
The Nature of Code via Cinder - Modeling the Natural World in C++The Nature of Code via Cinder - Modeling the Natural World in C++
The Nature of Code via Cinder - Modeling the Natural World in C++Nathan Koch
 
Cuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An IntroductionCuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An IntroductionXin-She Yang
 
Using R in remote computer clusters
Using R in remote computer clustersUsing R in remote computer clusters
Using R in remote computer clustersBurak Himmetoglu
 
H2O Open Source Deep Learning, Arno Candel 03-20-14
H2O Open Source Deep Learning, Arno Candel 03-20-14H2O Open Source Deep Learning, Arno Candel 03-20-14
H2O Open Source Deep Learning, Arno Candel 03-20-14Sri Ambati
 
Internet of Things Data Science
Internet of Things Data ScienceInternet of Things Data Science
Internet of Things Data ScienceAlbert Bifet
 
Online learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and HadoopOnline learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and HadoopHéloïse Nonne
 
Automatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsAutomatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsEmery Berger
 
Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingFilip De Sutter
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
 
Pwl rewal-slideshare
Pwl rewal-slidesharePwl rewal-slideshare
Pwl rewal-slidesharepalvaro
 
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...Andrew Phillips
 
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Andrew Phillips
 
Peter Norvig - NYC Machine Learning 2013
Peter Norvig - NYC Machine Learning 2013Peter Norvig - NYC Machine Learning 2013
Peter Norvig - NYC Machine Learning 2013Michael Scovetta
 
Next.ml Boston: Data Science Dev Ops
Next.ml Boston: Data Science Dev OpsNext.ml Boston: Data Science Dev Ops
Next.ml Boston: Data Science Dev OpsEric Chiang
 
Java and Deep Learning (Introduction)
Java and Deep Learning (Introduction)Java and Deep Learning (Introduction)
Java and Deep Learning (Introduction)Oswald Campesato
 
Threading Is Not A Model
Threading Is Not A ModelThreading Is Not A Model
Threading Is Not A Modelguest2a5acfb
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford MapR Technologies
 
Separating Hype from Reality in Deep Learning with Sameer Farooqui
 Separating Hype from Reality in Deep Learning with Sameer Farooqui Separating Hype from Reality in Deep Learning with Sameer Farooqui
Separating Hype from Reality in Deep Learning with Sameer FarooquiDatabricks
 

Similaire à How Do You Solve the Santa Claus Problem with Join Patterns (20)

Music recommendations @ MLConf 2014
Music recommendations @ MLConf 2014Music recommendations @ MLConf 2014
Music recommendations @ MLConf 2014
 
The Nature of Code via Cinder - Modeling the Natural World in C++
The Nature of Code via Cinder - Modeling the Natural World in C++The Nature of Code via Cinder - Modeling the Natural World in C++
The Nature of Code via Cinder - Modeling the Natural World in C++
 
Cuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An IntroductionCuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An Introduction
 
Using R in remote computer clusters
Using R in remote computer clustersUsing R in remote computer clusters
Using R in remote computer clusters
 
H2O Open Source Deep Learning, Arno Candel 03-20-14
H2O Open Source Deep Learning, Arno Candel 03-20-14H2O Open Source Deep Learning, Arno Candel 03-20-14
H2O Open Source Deep Learning, Arno Candel 03-20-14
 
Inferno Scalable Deep Learning on Spark
Inferno Scalable Deep Learning on SparkInferno Scalable Deep Learning on Spark
Inferno Scalable Deep Learning on Spark
 
Internet of Things Data Science
Internet of Things Data ScienceInternet of Things Data Science
Internet of Things Data Science
 
Online learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and HadoopOnline learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and Hadoop
 
Automatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsAutomatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory Errors
 
Presentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional ProgrammingPresentation of GetTogether on Functional Programming
Presentation of GetTogether on Functional Programming
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Pwl rewal-slideshare
Pwl rewal-slidesharePwl rewal-slideshare
Pwl rewal-slideshare
 
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
BASE Meetup: "Analysing Scala Puzzlers: Essential and Accidental Complexity i...
 
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
Scala Up North: "Analysing Scala Puzzlers: Essential and Accidental Complexit...
 
Peter Norvig - NYC Machine Learning 2013
Peter Norvig - NYC Machine Learning 2013Peter Norvig - NYC Machine Learning 2013
Peter Norvig - NYC Machine Learning 2013
 
Next.ml Boston: Data Science Dev Ops
Next.ml Boston: Data Science Dev OpsNext.ml Boston: Data Science Dev Ops
Next.ml Boston: Data Science Dev Ops
 
Java and Deep Learning (Introduction)
Java and Deep Learning (Introduction)Java and Deep Learning (Introduction)
Java and Deep Learning (Introduction)
 
Threading Is Not A Model
Threading Is Not A ModelThreading Is Not A Model
Threading Is Not A Model
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford
 
Separating Hype from Reality in Deep Learning with Sameer Farooqui
 Separating Hype from Reality in Deep Learning with Sameer Farooqui Separating Hype from Reality in Deep Learning with Sameer Farooqui
Separating Hype from Reality in Deep Learning with Sameer Farooqui
 

Dernier

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
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
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
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
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
 
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
 
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
 
[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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
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
 
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
 
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
 
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
 
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
 
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
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
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
 

Dernier (20)

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
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
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)
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
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
 
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...
 
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
 
[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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
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
 
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
 
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
 
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
 
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
 
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
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 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
 

How Do You Solve the Santa Claus Problem with Join Patterns

  • 1. How Do You Solve a Problem Like Santa Claus ? Prototyping Join Patterns with stackless.py for Stackless Python Andrew Francis af.stackless@gmail.com Montreal Python 26 December 17th, 2011
  • 2. Exploring Feedback Play Fearless Programming Trial-and-error Learning Serendipity Syncretism Innovation Baling wire and Chewing Gum Challenges Friendship
  • 3. The Santa Claus Problem Santa repeatedly sleeps until wakened by either all of his nine rein- deer, back from their holidays, or by a group of three of his ten elves. If awakened by the reindeer, he harnesses each of them to his sleigh, delivers toys with them and finally unharnesses them (allowing them to go off on holiday). If awakened by a group of elves, he shows each of the group into his study, consults with them on toy R&D and finally shows them each out (allowing them to go back to work). Santa should give priority to the reindeer in the case that there is both a group of elves and a group of reindeer waiting.
  • 4. Perception Taken from The Santa Claus Problem: Thread Synchronization
  • 6. Solutions Through The Years Year Language Mechanism 1994 C Semaphores 1997 Ada 95 Protected objects, Rendezvous (select) 2003 Polyphonic C# Join Patterns 2007 Haskell Software Transactional Memory
  • 7. Join Patterns a la Polyphonic C# class Join2 { void wait(out int i, out int j) & async first(int r1) & async second(int r2) { i = r1; j = r2; return; } } //client code int i,j; Join2 x = new Join2(); ... //synchronous method will block x.wait(i,j); // do something with i and j
  • 8. Chord Rules • When pending method calls match a pattern, its body runs. • If there is no match, the invocations are queued up. • If there are several matches, an unspecified pattern is selected. • If receiver is synchronous, body executes in receiver’s thread. • If only asynchronous methods, the body runs in a new thread.
  • 9. Stackless Python • Superset of CPython. – Inspired by Bell Labs Limbo language • Reputation for user space threads too cheap to meter. • Cooperative and pre-emptive multi-tasking.
  • 10. Example import stackless def producer(aChannel): aChannel.send("hello") def consumer(aChannel): print aChannel.receive() aChannel = stackless.channel() stackless.tasklet(producer)(aChannel) stackless.tasklet(consumer)(aChannel) stackless.schedule()
  • 11. Synchronous Channels Before: [producer, …+scheduler (producer, send,“hello”) -> [ ] receive After : [producer]scheduler * (producer, send, “hello”) ]send Before: (consumer, receive, null) -> [(Producer)]send After: (1) consumer.val = “hello” (2) [(producer, send, “hello”),…]send (3) *…, Producer+scheduler
  • 13. Question Question: Why is knowing about select() important?
  • 14. Answers • Stackless Python did not originally implement select(). – This is proof-of-concept that we can modify stackless.py to create new features • Select() is used under the hood to implement join patterns • We are going to extend the select algorithm developed in “Prototyping Go’s Select with stackless.py” to include join patterns.
  • 15. Christian Tismer’s Sleight of Hand • Stackless Python does not support select() • Eliminated a queue • Created a channel property: balance – > 0 : senders on the queue – < 0 : receivers on the queue – 0: empty
  • 16. stackless.py • A PyPy module that implements the Stackless Python API • Written in Python! • Low level concurrency provided by different packages – greenlets – Continulets
  • 17. Strategy • Implemented sub-set of join pattern’s behaviour – Synchronous receiver – No built-in asynchrony • object.method = channel.receive() – i.e., join2.wait() equivalent to join2.receive() – Simplifies API
  • 18. Strategy • Why implement a method body (and class) for synchronization patterns? – we already have channels. – Message bodies seem to exist to store internal messages and compute a return value ? • Rather – return all internally queued values associated with pattern. – let receiver decide what to do.
  • 19. Another Sleight of Hand JoinPattern action() chanop chanop chanop add() ready() remove() - A join pattern is a composite channel operation - A join pattern uses the same interface as a channel operation - Now we can express disjunctions of conjunctions!
  • 20. Famous Last Words (Le Mot de Cambronne)
  • 21. “All or Nothing” (“Atomicity”) (Dancer), (Dasher),(Vixen),(Comet),(Cupid),(Doner),(Blitzen),(Rudolph) (“stackless scheduler”) application Reindeer Join Pattern (Dancer), (Dasher),(Vixen),(Comet),(Cupid),(Doner),(Blitzen),(Rudolph) Transfer all the data if and only if all nine reindeer channels are ready
  • 22. New Rules Postpone Rendezvous (lazy acquire) Before: (rudolph, S, msg) -> [(Santa,JR) ] rudolph-receive After : [ (rudolph,join-send, msg) ]rudolph-send Steal Before: (Mrs Claus, R, Null) -> [(rudolph,JS,msg)send After : Mrs Claus.val = msg [(Santa,JR) ] rudolph-receive
  • 23. Words of Wisdom Hence plan to throw one away; you will, anyhow. --Fred Brooks (on pilot projects)
  • 24.
  • 25. Lessons Learnt • Asynchrony matters – Prototype not powerful enough to handle Dining Philosophers – Synchronous channels with buffers. • Atomicity a powerful feature. – In case of Dining Philosophers, just does the right thing • “Transactional” logic and expressiveness come to the forefront quickly.
  • 26. Status • Prototype is still held together by baling wire and chewing gum. • A lot of work needs to be done before it is prime time
  • 27. A New Language: Conversation with Scalable Join Pattern’s Authors Concurrent ML Atomic transactions Transactional events Eager and lazy acquire Composibility Lock-free data structures Optimistic locking protocols Inevitability
  • 28. The Ghosts of Software Present, Past, and Future The Present: Concurrent ML: guard(event, f) The Past: Chandler Notification Manager 2.0 (R.I.P): eval(“city == MTL and band == Interpol”) The Future: C.E.P & S.0.A with Stackless Python: Guard(function(chanop.val), concertFeedChannel) return eval(“city=MTL and band==Hannah Georgas”)
  • 29. References • The Santa Claus Problem: Thread Synchronization, http://www.youtube.com/watch?v=pqO6tKN2lc4 • Scalable Join Patterns, Claudo Russo & Aaron Turon, http://www.ccs.neu.edu/home/turon/scalable-joins.pdf • Jingle Bells, Solving the Santa Claus Problem in Polyphonic #C, http://research.microsoft.com/en-us/um/people/nick/polyphony/ • The Polyphonic #C Bedroom Poster, http://research.microsoft.com/en- us/um/people/nick/polyphony/polyphoniccsharpposter2002.ppt • http://swtch.com/usr/local/plan9/src/libthread/channel.c, Russ Cox • Concurrent Programming in ML. John H. Reppy. Cambridge University Press, Cambridge, England, 1999. • The Notification Manager, http://www.osafoundation.org/archives/2003_11.html • stackless.py (with select), http://stacklessexamples.googlecode.com/svn/trunk/sandbox/select/stackless.py • Prototyping Go’s Select with stackless.py for Stackless Python, http://andrewfr.files.wordpress.com/2010/07/july31revised.pdf