SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
CONCURRENCY:
                            RUBIES, PLURAL




                               Elise Huard - RubyAndRails 2010
Thursday 21 October 2010
MULTIPROCESSOR/MULTICORE




Thursday 21 October 2010
NETWORK ON CHIP
                            (50..96..100 CORES)




Thursday 21 October 2010
“... for the first time in history, no one is building a
                 much faster sequential processor. If you want your
                 programs to run significantly faster (...) you’re going
                 to have to parallelize your program.”

                 Hennessy and Patterson “Computer Architectures” (4th
                 edition, 2007)



Thursday 21 October 2010
But ...
                           forget all that
                                (mostly)




Thursday 21 October 2010
Your program




                                      language VM



                                           OS
                           (kernel processes, other processes)


                                multicore - multiCPU


Thursday 21 October 2010
Concurrent programs
                               !=
                      Parallel computing


Thursday 21 October 2010
Thursday 21 October 2010
Thursday 21 October 2010
Scheduling


                    • preemptive -> thread is told to yield
                           (by kernel or other thread)
                    • cooperative -> thread yields control

Thursday 21 October 2010
Processes, Threads
                                 memory space              RAM               memory space



                                   Process 1                                  Process 2




                             thread1         thread2                    t1        t2        t3




                                                       scheduler (OS)




                                       CPU                                      CPU




Thursday 21 October 2010
Ruby


                    • Process
                    • Thread - green in MRI 1.8, native
                           threads in MRI 1.9, Rubinius, JRuby




Thursday 21 October 2010
MRI: GIL
                   • only one thread is executed at a time
                   • fair scheduling: timer thread!
                           (10 μs for Linux, 10 ms for Windows)
                   • blocking region to allow limited
                           concurrency



Thursday 21 October 2010
MRI: GIL




                           from http://www.igvita.com/2008/11/13/concurrency-is-a-myth-in-ruby/ @igrigorik




Thursday 21 October 2010
Other Rubies

                    • @evanphx working on removing the
                           GIL on Rubinius (Hydra branch)
                    • JRuby, IronRuby, MacRuby don’t have
                           GIL



Thursday 21 October 2010
Parallel quicksort

                                                          [5, 3, 22, 12, 15, -112, 6]




                                    [-122, 5, 3, 6]                  12                 [22, 15]




                           [-122]        3            [5, 6]




Thursday 21 October 2010
multiprocess

                    •      advantage: separate state
                    • disadvantage: overhead to
                           spawning + context
                           switching


Thursday 21 October 2010
Ruby: multiprocess

                    •      fork and IPC: IO.pipe,
                           Mmap, ...
                    •      DRb


Thursday 21 October 2010
Ruby: multiprocess
                           def execute(&block)
                                   rd, wr = IO.pipe # to retrieve results
                                   pid = fork do
                                            rd.close
                                            result = block.call
                                            wr.write result.to_json
                                            wr.close
                                   end
                                   wr.close
                                   sorted = JSON.parse(rd.read)
                                   rd.close
                                   Process.waitpid(pid)
                                   sorted
                           end




Thursday 21 October 2010
Threads

                           Shared state:
                           Mutex
                           ConditionVariable (semaphore)
                           MonitorMixin, Sync_m



Thursday 21 October 2010
Ruby threads
                           def execute(&block)
                                    sorted = nil
                                    thread = Thread.new do
                                            sorted = block.call
                                    end
                                    thread.join
                                    sorted
                            end




Thursday 21 October 2010
Fibers

                    • cooperative scheduling
                    • coroutines
                    • for MRI: lightweight
                    • JRuby, Rubinius: Fiber mapped to
                           native thread


Thursday 21 October 2010
Ruby: Coroutines
         require 'fiber'

         # coroutines
         ary = []
         f2 = nil
         f1 = Fiber.new{                                    output:
           puts "please give your login"                    please give your login
           login = f2.transfer                              johndoe
           puts login
           puts "give password"
                                                            give password
           pass = f2.transfer                               ultrasecret
           puts pass                                        ***** no cigar *****
           f2.transfer
           f2.transfer('***** no cigar *****')
         }
         f2 = Fiber.new{
            f1.transfer('johndoe')
            f1.transfer('ultrasecret')
            answer = f1.transfer
            puts answer
         }

                                         vaguely inspired by http://sheddingbikes.com/posts/1287306747.html
         f1.resume
Thursday 21 October 2010
MVM
                           Rubinius (2008): no parallel execution
                           of threads in one VM ... so let’s create
                           one VM per native thread

                vm = Rubinius::VM.spawn "blah", "-e", "puts 'hellon'"




Thursday 21 October 2010
Thursday 21 October 2010
shared state:
                           will melt your brain
                    • non-determinism
                    • atomicity
                    • deadlock
                    • livelock
                    • fairness/starvation
                    • race conditions
Thursday 21 October 2010
actor model


                    • named actors: have no shared state
                    • asynchronous message passing (fire
                           and forget)




Thursday 21 October 2010
CSP

                    • member of family of Process Calculi
                           (mathematical theory)
                    • events, processes
                    • synchronous (rendez-vous) message passing
                    • named channels - dual to Actor model

Thursday 21 October 2010
Concurrency oriented
                         languages
                    • Erlang (Actors)
                    • Clojure
                    • Go (CSP)
                    • Haskell (several)
                    • Scala (Actors)
                    • ...
Thursday 21 October 2010
Ideas
                    • functional programming: side effect
                           free function calls
                           - immutable data
                    • nothing shared (advantage: distributed
                           = local)
                    • message passing
Thursday 21 October 2010
erlang

                    • Actor model: Actors, asynchronous
                           message passing
                    • actors = “green processes”
                    • efficient VM (SMP enabled since R12B)
                    • high reliability
                                                             © ericsson 2007



Thursday 21 October 2010
Erlang

               spawn(fun() ->sort(Self, List) end)
               pmap_gather([]) ->
                 [];
               pmap_gather([H|T]) ->
                 receive
                     {H, Ret} -> [Ret|pmap_gather(T)]
                 end;


Thursday 21 October 2010
Rubinius: Actors

                    • actors in the language: threads with
                           inbox
                    • VM actors to communicate between
                           actors in different VMs



Thursday 21 October 2010
Ruby: Revactor

                    • erlang-like semantics: actor spawn/receive,
                           filter
                    • Fibers (so cooperative scheduling)
                    • Revactor::TCP for non-blocking network
                           access (1.9.2) (rev eventloop)



Thursday 21 October 2010
Go
                    • Fairly low-level - fit for systems
                           programming (close to C)
                    • static typing
                    • goroutines: parallel execution - sort of
                           async lightweight thread
                    • channels !

Thursday 21 October 2010
Go
               lessReply = make(chan []int)
               (...)
               lessReq.data = less
               lessReq.replyChannel = lessReply
               go sort(&lessReq) // asyncstart parallel
               execution of sort


               listener:
               append(<-lessReply, pivot, <-greaterReply)

Thursday 21 October 2010
clojure
                           functional, Lisp-like
                           concurrency: Software Transactional
                           Memory System:
                    • Vars = variable state is thread isolated
                    • Refs = shared, and mutation within a
                           transaction (atomic, consistent, isolated) -
                           Multiversion Concurrency Control -


Thursday 21 October 2010
Ruby: STM


                    • @mentalguy thought experiment
                    • @technomancy clojure-gem


Thursday 21 October 2010
others to handle
                                concurrency
                           futures
                           joins
                           see http://moonbase.rydia.net/mental/
                           blog/programming/concurrency-five-
                           ways.html (@mentalguy)


Thursday 21 October 2010
Kernel stuff


                       Some of these problems have
                       been solved before ...



Thursday 21 October 2010
FUN :)




Thursday 21 October 2010
References:

                     http://www.delicious.com/elisehuard/concurrency

                     http://github.com/elisehuard/rubyandrails-2010



                     Elise Huard
                     @elise_huard
                     http://jabberwocky.eu



Thursday 21 October 2010

Contenu connexe

Tendances

Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talkdotCloud
 
Clojure basics
Clojure basicsClojure basics
Clojure basicsKyle Oba
 
Beginners guide-concurrency
Beginners guide-concurrencyBeginners guide-concurrency
Beginners guide-concurrencyMichael Barker
 
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...JAX London
 

Tendances (6)

Scale11x lxc talk
Scale11x lxc talkScale11x lxc talk
Scale11x lxc talk
 
jRuby and TorqueBox
jRuby and TorqueBoxjRuby and TorqueBox
jRuby and TorqueBox
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Beginners guide-concurrency
Beginners guide-concurrencyBeginners guide-concurrency
Beginners guide-concurrency
 
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
 
Tips of Malloc & Free
Tips of Malloc & FreeTips of Malloc & Free
Tips of Malloc & Free
 

En vedette

Barcamp Ghent2009
Barcamp Ghent2009Barcamp Ghent2009
Barcamp Ghent2009ehuard
 
The real-time web
The real-time webThe real-time web
The real-time webehuard
 
Concurrency
ConcurrencyConcurrency
Concurrencyehuard
 
Ruby goes to Hollywood
Ruby goes to HollywoodRuby goes to Hollywood
Ruby goes to Hollywoodehuard
 
12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Application12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Applicationehuard
 
3 Deadly Mistakes of Sales Copy
3 Deadly Mistakes of Sales Copy3 Deadly Mistakes of Sales Copy
3 Deadly Mistakes of Sales CopyTracy Needham
 
how to rate a Rails application
how to rate a Rails applicationhow to rate a Rails application
how to rate a Rails applicationehuard
 
Creating Killer Blog Content that Builds Your Business Can Be Fast & Easy
Creating Killer Blog Content that Builds Your Business Can Be Fast & EasyCreating Killer Blog Content that Builds Your Business Can Be Fast & Easy
Creating Killer Blog Content that Builds Your Business Can Be Fast & EasyTracy Needham
 
Ruby goes to hollywood
Ruby goes to hollywoodRuby goes to hollywood
Ruby goes to hollywoodehuard
 
신규근로장학생 교육용자료
신규근로장학생 교육용자료신규근로장학생 교육용자료
신규근로장학생 교육용자료sodapop83
 

En vedette (13)

Barcamp Ghent2009
Barcamp Ghent2009Barcamp Ghent2009
Barcamp Ghent2009
 
The real-time web
The real-time webThe real-time web
The real-time web
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
FLES
FLESFLES
FLES
 
NoséSiesa[1]..
NoséSiesa[1]..NoséSiesa[1]..
NoséSiesa[1]..
 
Ruby goes to Hollywood
Ruby goes to HollywoodRuby goes to Hollywood
Ruby goes to Hollywood
 
Oauth
OauthOauth
Oauth
 
12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Application12 Hours To Rate A Rails Application
12 Hours To Rate A Rails Application
 
3 Deadly Mistakes of Sales Copy
3 Deadly Mistakes of Sales Copy3 Deadly Mistakes of Sales Copy
3 Deadly Mistakes of Sales Copy
 
how to rate a Rails application
how to rate a Rails applicationhow to rate a Rails application
how to rate a Rails application
 
Creating Killer Blog Content that Builds Your Business Can Be Fast & Easy
Creating Killer Blog Content that Builds Your Business Can Be Fast & EasyCreating Killer Blog Content that Builds Your Business Can Be Fast & Easy
Creating Killer Blog Content that Builds Your Business Can Be Fast & Easy
 
Ruby goes to hollywood
Ruby goes to hollywoodRuby goes to hollywood
Ruby goes to hollywood
 
신규근로장학생 교육용자료
신규근로장학생 교육용자료신규근로장학생 교육용자료
신규근로장학생 교육용자료
 

Similaire à Concurrency

Scaling webappswithrabbitmq
Scaling webappswithrabbitmqScaling webappswithrabbitmq
Scaling webappswithrabbitmqAlvaro Videla
 
Concurrency: Rubies, Plural
Concurrency: Rubies, PluralConcurrency: Rubies, Plural
Concurrency: Rubies, PluralEleanor McHugh
 
Concurrency: Rubies, plural
Concurrency: Rubies, pluralConcurrency: Rubies, plural
Concurrency: Rubies, pluralehuard
 
Pythonic APIs - Anthony Baxter
Pythonic APIs - Anthony BaxterPythonic APIs - Anthony Baxter
Pythonic APIs - Anthony Baxterknappt
 
Jeff mc cune sf 2010
Jeff mc cune sf 2010Jeff mc cune sf 2010
Jeff mc cune sf 2010Puppet
 
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume LaforgeGroovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume LaforgeGuillaume Laforge
 
"Taming the Dragon": ROS2 Robot-to-Anything with Zenoh
"Taming the Dragon": ROS2 Robot-to-Anything with Zenoh"Taming the Dragon": ROS2 Robot-to-Anything with Zenoh
"Taming the Dragon": ROS2 Robot-to-Anything with ZenohZettaScaleTechnology
 
Mobile, Media & Touch
Mobile, Media & TouchMobile, Media & Touch
Mobile, Media & TouchTim Wright
 
Building Scale Free Applications with Hadoop and Cascading
Building Scale Free Applications with Hadoop and CascadingBuilding Scale Free Applications with Hadoop and Cascading
Building Scale Free Applications with Hadoop and Cascadingcwensel
 
Compiling and Optimizing Your Own Browser with WebKit
Compiling and Optimizing Your Own Browser with WebKitCompiling and Optimizing Your Own Browser with WebKit
Compiling and Optimizing Your Own Browser with WebKitSencha
 
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010Guillaume Laforge
 
Scientific Applications with Python
Scientific Applications with PythonScientific Applications with Python
Scientific Applications with PythonEnthought, Inc.
 
Pregel: A System for Large-Scale Graph Processing
Pregel: A System for Large-Scale Graph ProcessingPregel: A System for Large-Scale Graph Processing
Pregel: A System for Large-Scale Graph ProcessingChris Bunch
 
Dojo Basics Js UserGroup Chicago
Dojo Basics Js UserGroup ChicagoDojo Basics Js UserGroup Chicago
Dojo Basics Js UserGroup Chicagowolframkriesing
 
Everything Rubinius
Everything RubiniusEverything Rubinius
Everything RubiniusEngine Yard
 
from Realtime Operating systems to unlocking iPhones in less than 30 slides
from Realtime Operating systems to unlocking iPhones in less than 30 slidesfrom Realtime Operating systems to unlocking iPhones in less than 30 slides
from Realtime Operating systems to unlocking iPhones in less than 30 slidesKai Aras
 
ScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs XboxScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs Xboxdavidsingleton
 

Similaire à Concurrency (20)

Mars - ESUG 2010
Mars - ESUG 2010Mars - ESUG 2010
Mars - ESUG 2010
 
Scaling webappswithrabbitmq
Scaling webappswithrabbitmqScaling webappswithrabbitmq
Scaling webappswithrabbitmq
 
Concurrency: Rubies, Plural
Concurrency: Rubies, PluralConcurrency: Rubies, Plural
Concurrency: Rubies, Plural
 
Concurrency: Rubies, plural
Concurrency: Rubies, pluralConcurrency: Rubies, plural
Concurrency: Rubies, plural
 
Pythonic APIs - Anthony Baxter
Pythonic APIs - Anthony BaxterPythonic APIs - Anthony Baxter
Pythonic APIs - Anthony Baxter
 
Jeff mc cune sf 2010
Jeff mc cune sf 2010Jeff mc cune sf 2010
Jeff mc cune sf 2010
 
Developing Distributed Semantic Systems
Developing Distributed Semantic SystemsDeveloping Distributed Semantic Systems
Developing Distributed Semantic Systems
 
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume LaforgeGroovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
 
"Taming the Dragon": ROS2 Robot-to-Anything with Zenoh
"Taming the Dragon": ROS2 Robot-to-Anything with Zenoh"Taming the Dragon": ROS2 Robot-to-Anything with Zenoh
"Taming the Dragon": ROS2 Robot-to-Anything with Zenoh
 
Mobile, Media & Touch
Mobile, Media & TouchMobile, Media & Touch
Mobile, Media & Touch
 
Building Scale Free Applications with Hadoop and Cascading
Building Scale Free Applications with Hadoop and CascadingBuilding Scale Free Applications with Hadoop and Cascading
Building Scale Free Applications with Hadoop and Cascading
 
Is these a bug
Is these a bugIs these a bug
Is these a bug
 
Compiling and Optimizing Your Own Browser with WebKit
Compiling and Optimizing Your Own Browser with WebKitCompiling and Optimizing Your Own Browser with WebKit
Compiling and Optimizing Your Own Browser with WebKit
 
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
 
Scientific Applications with Python
Scientific Applications with PythonScientific Applications with Python
Scientific Applications with Python
 
Pregel: A System for Large-Scale Graph Processing
Pregel: A System for Large-Scale Graph ProcessingPregel: A System for Large-Scale Graph Processing
Pregel: A System for Large-Scale Graph Processing
 
Dojo Basics Js UserGroup Chicago
Dojo Basics Js UserGroup ChicagoDojo Basics Js UserGroup Chicago
Dojo Basics Js UserGroup Chicago
 
Everything Rubinius
Everything RubiniusEverything Rubinius
Everything Rubinius
 
from Realtime Operating systems to unlocking iPhones in less than 30 slides
from Realtime Operating systems to unlocking iPhones in less than 30 slidesfrom Realtime Operating systems to unlocking iPhones in less than 30 slides
from Realtime Operating systems to unlocking iPhones in less than 30 slides
 
ScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs XboxScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs Xbox
 

Plus de ehuard

Euroclojure 2017
Euroclojure 2017Euroclojure 2017
Euroclojure 2017ehuard
 
Ruby hollywood nordic
Ruby hollywood nordicRuby hollywood nordic
Ruby hollywood nordicehuard
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywoodehuard
 
12 hours to rate a rails application
12 hours to rate a rails application12 hours to rate a rails application
12 hours to rate a rails applicationehuard
 
Tokyo Cabinet
Tokyo CabinetTokyo Cabinet
Tokyo Cabinetehuard
 
Rails and the internet of things
Rails and the internet of thingsRails and the internet of things
Rails and the internet of thingsehuard
 

Plus de ehuard (6)

Euroclojure 2017
Euroclojure 2017Euroclojure 2017
Euroclojure 2017
 
Ruby hollywood nordic
Ruby hollywood nordicRuby hollywood nordic
Ruby hollywood nordic
 
Ruby hollywood
Ruby hollywoodRuby hollywood
Ruby hollywood
 
12 hours to rate a rails application
12 hours to rate a rails application12 hours to rate a rails application
12 hours to rate a rails application
 
Tokyo Cabinet
Tokyo CabinetTokyo Cabinet
Tokyo Cabinet
 
Rails and the internet of things
Rails and the internet of thingsRails and the internet of things
Rails and the internet of things
 

Dernier

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
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
 
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
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
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
 
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
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
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
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
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
 

Dernier (20)

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
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
 
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
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
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.
 
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
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
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
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
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
 

Concurrency

  • 1. CONCURRENCY: RUBIES, PLURAL Elise Huard - RubyAndRails 2010 Thursday 21 October 2010
  • 3. NETWORK ON CHIP (50..96..100 CORES) Thursday 21 October 2010
  • 4. “... for the first time in history, no one is building a much faster sequential processor. If you want your programs to run significantly faster (...) you’re going to have to parallelize your program.” Hennessy and Patterson “Computer Architectures” (4th edition, 2007) Thursday 21 October 2010
  • 5. But ... forget all that (mostly) Thursday 21 October 2010
  • 6. Your program language VM OS (kernel processes, other processes) multicore - multiCPU Thursday 21 October 2010
  • 7. Concurrent programs != Parallel computing Thursday 21 October 2010
  • 10. Scheduling • preemptive -> thread is told to yield (by kernel or other thread) • cooperative -> thread yields control Thursday 21 October 2010
  • 11. Processes, Threads memory space RAM memory space Process 1 Process 2 thread1 thread2 t1 t2 t3 scheduler (OS) CPU CPU Thursday 21 October 2010
  • 12. Ruby • Process • Thread - green in MRI 1.8, native threads in MRI 1.9, Rubinius, JRuby Thursday 21 October 2010
  • 13. MRI: GIL • only one thread is executed at a time • fair scheduling: timer thread! (10 μs for Linux, 10 ms for Windows) • blocking region to allow limited concurrency Thursday 21 October 2010
  • 14. MRI: GIL from http://www.igvita.com/2008/11/13/concurrency-is-a-myth-in-ruby/ @igrigorik Thursday 21 October 2010
  • 15. Other Rubies • @evanphx working on removing the GIL on Rubinius (Hydra branch) • JRuby, IronRuby, MacRuby don’t have GIL Thursday 21 October 2010
  • 16. Parallel quicksort [5, 3, 22, 12, 15, -112, 6] [-122, 5, 3, 6] 12 [22, 15] [-122] 3 [5, 6] Thursday 21 October 2010
  • 17. multiprocess • advantage: separate state • disadvantage: overhead to spawning + context switching Thursday 21 October 2010
  • 18. Ruby: multiprocess • fork and IPC: IO.pipe, Mmap, ... • DRb Thursday 21 October 2010
  • 19. Ruby: multiprocess def execute(&block) rd, wr = IO.pipe # to retrieve results pid = fork do rd.close result = block.call wr.write result.to_json wr.close end wr.close sorted = JSON.parse(rd.read) rd.close Process.waitpid(pid) sorted end Thursday 21 October 2010
  • 20. Threads Shared state: Mutex ConditionVariable (semaphore) MonitorMixin, Sync_m Thursday 21 October 2010
  • 21. Ruby threads def execute(&block) sorted = nil thread = Thread.new do sorted = block.call end thread.join sorted end Thursday 21 October 2010
  • 22. Fibers • cooperative scheduling • coroutines • for MRI: lightweight • JRuby, Rubinius: Fiber mapped to native thread Thursday 21 October 2010
  • 23. Ruby: Coroutines require 'fiber' # coroutines ary = [] f2 = nil f1 = Fiber.new{ output: puts "please give your login" please give your login login = f2.transfer johndoe puts login puts "give password" give password pass = f2.transfer ultrasecret puts pass ***** no cigar ***** f2.transfer f2.transfer('***** no cigar *****') } f2 = Fiber.new{ f1.transfer('johndoe') f1.transfer('ultrasecret') answer = f1.transfer puts answer } vaguely inspired by http://sheddingbikes.com/posts/1287306747.html f1.resume Thursday 21 October 2010
  • 24. MVM Rubinius (2008): no parallel execution of threads in one VM ... so let’s create one VM per native thread vm = Rubinius::VM.spawn "blah", "-e", "puts 'hellon'" Thursday 21 October 2010
  • 26. shared state: will melt your brain • non-determinism • atomicity • deadlock • livelock • fairness/starvation • race conditions Thursday 21 October 2010
  • 27. actor model • named actors: have no shared state • asynchronous message passing (fire and forget) Thursday 21 October 2010
  • 28. CSP • member of family of Process Calculi (mathematical theory) • events, processes • synchronous (rendez-vous) message passing • named channels - dual to Actor model Thursday 21 October 2010
  • 29. Concurrency oriented languages • Erlang (Actors) • Clojure • Go (CSP) • Haskell (several) • Scala (Actors) • ... Thursday 21 October 2010
  • 30. Ideas • functional programming: side effect free function calls - immutable data • nothing shared (advantage: distributed = local) • message passing Thursday 21 October 2010
  • 31. erlang • Actor model: Actors, asynchronous message passing • actors = “green processes” • efficient VM (SMP enabled since R12B) • high reliability © ericsson 2007 Thursday 21 October 2010
  • 32. Erlang spawn(fun() ->sort(Self, List) end) pmap_gather([]) -> []; pmap_gather([H|T]) -> receive {H, Ret} -> [Ret|pmap_gather(T)] end; Thursday 21 October 2010
  • 33. Rubinius: Actors • actors in the language: threads with inbox • VM actors to communicate between actors in different VMs Thursday 21 October 2010
  • 34. Ruby: Revactor • erlang-like semantics: actor spawn/receive, filter • Fibers (so cooperative scheduling) • Revactor::TCP for non-blocking network access (1.9.2) (rev eventloop) Thursday 21 October 2010
  • 35. Go • Fairly low-level - fit for systems programming (close to C) • static typing • goroutines: parallel execution - sort of async lightweight thread • channels ! Thursday 21 October 2010
  • 36. Go lessReply = make(chan []int) (...) lessReq.data = less lessReq.replyChannel = lessReply go sort(&lessReq) // asyncstart parallel execution of sort listener: append(<-lessReply, pivot, <-greaterReply) Thursday 21 October 2010
  • 37. clojure functional, Lisp-like concurrency: Software Transactional Memory System: • Vars = variable state is thread isolated • Refs = shared, and mutation within a transaction (atomic, consistent, isolated) - Multiversion Concurrency Control - Thursday 21 October 2010
  • 38. Ruby: STM • @mentalguy thought experiment • @technomancy clojure-gem Thursday 21 October 2010
  • 39. others to handle concurrency futures joins see http://moonbase.rydia.net/mental/ blog/programming/concurrency-five- ways.html (@mentalguy) Thursday 21 October 2010
  • 40. Kernel stuff Some of these problems have been solved before ... Thursday 21 October 2010
  • 41. FUN :) Thursday 21 October 2010
  • 42. References: http://www.delicious.com/elisehuard/concurrency http://github.com/elisehuard/rubyandrails-2010 Elise Huard @elise_huard http://jabberwocky.eu Thursday 21 October 2010