SlideShare a Scribd company logo
Concurrency for dummies
 and for real people too




               By
       Azrul Hasni Mad Isa
(azrul.madisa@my.experian.com)
About me
• Senior Software
  Architect at Experian
  Decision Analytics
• 10 years of experience in
  IT and such
• Graduated from France
  (INSA)
About Experian
• In Cyberjaya
   – Other R&D Centres in
     Nottingham, Monaco,
     Washington
• Financial analytics, market
  analytics
• 200+ people and growing
• We use Scrum
• We are looking for people
   – Java, PHP, Perl, C#
   – Dev, QA, Architects, Team
     lead
Introduction
• What is concurrency
        Concurrency is a property of systems
        in which several computations are
        executing        simultaneously,      and
        potentially interacting with each other


        -- Wikipedia
Introduction
• Why concurrent applications are important
Introduction
• Our business processes are getting more
  complex!
Business case for concurrency
• E-commerce
                                Buy Product
                                  Online

User
                                Parallel Split


                                          Charge Credit Card
             “Your request is
             being process”                 Check availability

                                            Reserve product

                                           Email confirmation
Business case for concurrency
• Financial – credit verification

                                              CCRIS
                      Apply Credit Card


                    Credential Verification   Equifax
User

                      Decision making
                                              Experian

                        Approve/Not
Business case for concurrency
• Logistics
                Arrival of merchandises


                For every merchandise


                              Parallel Split



              Custom & Port       Warehousing     Quality check
     …          authority



                                 Transportation
Business case for concurrency
• Many others …
Model for concurrency management
•   Actors
•   Agents
•   Dataflow
•   Stm
•   Data paralellism
    – Concurrent collections
    – Asynchronous functions (closure)
    – Fork/Join
Model for concurrency management
•   Actors
•   Agents
•   Dataflow
•   Stm
•   Data paralellism
    – Concurrent collections
    – Asynchronous functions (closure)
    – Fork/Join
GPARS
GPars
• Gpars is a concurrency
  management library for
  Groovy and Java
• Allow running models
  presented above
• http://gpars.codehaus.org/
ACTORS
Actors
• Why couldn’t they call ‘em actresses instead?
• A body of code that:
  – Receive a message asynchronously
  – React to a message if it can
  – Queue a received message if it’s busy
  – Asynchronous messaging (JMS)
Actor
• Synchronous messaging = immediate reply

          The Nora Elena
        actress is soo cute!




                                   Why You !! You !!...
                                     I’ll kill you!!
Actor
• Asynchronous messaging = non-immediate
  reply
  – We can do other things while waiting
                 Could you please
                make me a drink? …
                I’m going to ponder
               about the meaning of
                life in the meantime
Actor
• Asynchronous messaging = non-immediate
  reply
  – We can do other things while waiting
                 Could you please
                make me a drink? …
                I’m going to ponder
               about the meaning of               2 hours later
                life in the meantime




                                       I was watching TV.
                                       Go make the drink
                                            yourself!
Actors


       Queue                          Queue


               “sending a
OneActor       message”     AnotherActor
Actors


       Queue    “reply to a             Queue
                message”


OneActor                      AnotherActor
Actors
• Example: DefaultActor {
  class MyActor extends
      Actor anotherActor
      void act() {
          loop {
                       anotherActor.send “Hello” //send message to someone
                       react { String message -> //message could be any POGO
                      …//do something
                       reply someReply //some reply is any POGO
                       …
                       terminate() //kill the actor *gasp!*
                  }
              }
          }
      }
  }
Actors
• Two types
  – Stateless : DynamicDispatchActor
  – Stateful: DefaultActor
• Actors are can share a common
  threadpool
• Threadpool + statelessness =
  SCALABILITY
• No remote actors yet
Actor
• Some methods
  – loop
     • Infinite loop on the actor
  – react
     • React on message received
  – send
     • Send a message
  – reply
     • Reply to a message
Actor
• Cool stuff
  – Loop counting
  – Code in actors are guaranteed to be thread safe
  – Life cycle methods
  – Dealing with unsent messages
     • Business Process Compensation
  – Remote actors – coming
DATAFLOW
Dataflow
• First introduced in a language called Oz
  – Composed of tasks
  – Each task has input and output
  – A task is run as soon as all its input are available
Dataflow
Not executed

    Task
   print z

    Task
   z = a+b

  Task
  b=32

  Task
  a=20
Dataflow
Not executed   First round                       Executed

    Task          Task
   print z       print z

    Task         Task
   z = a+b       z = a+b

  Task          Task
  b=32          b=32           No input needed

  Task          Task
  a=20          a=20
Dataflow
Not executed   First round    Second round               Executed

    Task          Task          Task
   print z       print z       print z

    Task         Task           Task
   z = a+b       z = a+b       z = a+b
                                             Input, a and b,
  Task          Task           Task             becomes
  b=32          b=32           b=32             available

  Task          Task           Task
  a=20          a=20           a=20
Dataflow
Not executed   First round       Second round   Third round

    Task          Task              Task          Task
   print z       print z     Input,print z
                                    z,            print z
                             becomes
    Task         Task        available
                                    Task          Task
   z = a+b       z = a+b           z = a+b       z = a+b

  Task          Task              Task           Task
  b=32          b=32              b=32           b=32

  Task          Task              Task           Task
  a=20          a=20              a=20           a=20
Dataflow: code
final def x = new DataFlowVariable()
final def y = new DataFlowVariable()
final def z = new DataFlowVariable()

task {
  z << x.val + y.val
}

task {
  x << 10
}

task {
  y << 5
}

println "Result: ${z.val}"
Dataflow: principles
• Create a dataflow variable
   – The variable can be written once
     only
• Read it
   – If it has no value yet, the program
     will wait for the new value while
     executing other tasks
• Write to it
   – The moment a variable is written
     (or bounded) any task waiting for
     this variable will be reactivated
Dataflow: beauty
• “Declarative” concurrency
• Clean code
  – Business logic is much more obvious
  – Business logic can be sequential
• Flow is deterministic
• If no deadlock in unit test, it is guaranteed
  that there will be no deadlocks in production.
Dataflow in business process
               Apply Credit Card


                 Parallel split


       CCRIS        Equifax        Experian


                  Parallel join

               Decision making


                 Approve/Not
Dataflow in business process
                       Apply Credit Card


Do business              Parallel split
users really
  think in
               CCRIS        Equifax        Experian
  Parallel
executions?
                          Parallel join

                       Decision making


                         Approve/Not
Dataflow in business process
 I want to verify user
  credentials against
CCRIS, Experian and       You need parallel
       Equifax               processing




Business                 Solution
                         architect
stakeholder
Dataflow in business process
                         Suggestion by the solution architect

 I want to verify user
  credentials against
CCRIS, Experian and              You need parallel
       Equifax                      processing




Business                        Solution
                                architect
stakeholder
Dataflow in business process
• Meanwhile, in a parallel universe … pun intended ☺

    I want to verify user   Dataflow Tasks        OK?
     credentials against    Apply Credit Card
   CCRIS, Experian and
          Equifax                CCRIS
                                Equifax
                               Experian
                            Decision making
                              Approve/Not
                                                Solution
    Business                                    architect
   stakeholder
Dataflow in business process
• Meanwhile, in a parallel universe                Parallel
                                                 execution is
                                                    done
              Hey, I totally get that!          automatically
              I totally want to give              by GPars
              you more business!                  Dataflow
                Would you like a
                  pony too?



   Business                              Solution
                                         architect
  stakeholder
Dataflow in business process
• Meanwhile, in a parallel universe

                                  Yes please




                                  Solution
                                  architect
Conclusion
• Actor
  – Asynchronous messaging
• Dataflow
  – “Declarative” concurrency
Conclusion
• What we see is merely the tip of
  the iceberg
• Explore yourself
   – http://gpars.codehaus.org/
   – http://groovy.codehaus.org/
   – http://en.wikipedia.org/wiki/Acto
     r_model
   – http://en.wikipedia.org/wiki/Data
     flow
• My contact:
  azrul.madisa@my.experian.com

More Related Content

PPTX
Thinking in C/C++, coding in Java
PDF
BangaloreJUG introduction to kotlin
PDF
Enterprise javascriptsession3
KEY
ClojureScript Anatomy
PDF
Kotlin for Android Developers - 1
PPTX
Asynchronous programming
PPT
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
PDF
Beyond Horizontal Scalability: Concurrency and Messaging Using Spring
Thinking in C/C++, coding in Java
BangaloreJUG introduction to kotlin
Enterprise javascriptsession3
ClojureScript Anatomy
Kotlin for Android Developers - 1
Asynchronous programming
About Those Python Async Concurrent Frameworks - Fantix @ OSTC 2014
Beyond Horizontal Scalability: Concurrency and Messaging Using Spring

Similar to Concurrency for dummies (20)

PDF
GR8Conf 2011: GPars
PDF
PDF
Disrupting disruptor
PPTX
The Actor Model - Towards Better Concurrency
PDF
Groovy concurrency
PPTX
Indic threads pune12-typesafe stack software development on the jvm
PDF
Introduction to concurrent programming with akka actors
PDF
Introduction to concurrent programming with Akka actors
PDF
Concurrent and Distributed Applications with Akka, Java and Scala
ODP
GPars (Groovy Parallel Systems)
PDF
Concurrency and Parallelism with Scala
PPTX
Reactive Programming using Actor Model in Akka
PPT
Unit 3(advanced state modeling & interaction meodelling)
PDF
Gpars workshop
PPTX
Concurrency Constructs Overview
PDF
Introduction to Actor Model and Akka
PDF
Actors: Not Just for Movies Anymore
PDF
Actors in a New "Highly Parallel" World
PPTX
Diagrams
GR8Conf 2011: GPars
Disrupting disruptor
The Actor Model - Towards Better Concurrency
Groovy concurrency
Indic threads pune12-typesafe stack software development on the jvm
Introduction to concurrent programming with akka actors
Introduction to concurrent programming with Akka actors
Concurrent and Distributed Applications with Akka, Java and Scala
GPars (Groovy Parallel Systems)
Concurrency and Parallelism with Scala
Reactive Programming using Actor Model in Akka
Unit 3(advanced state modeling & interaction meodelling)
Gpars workshop
Concurrency Constructs Overview
Introduction to Actor Model and Akka
Actors: Not Just for Movies Anymore
Actors in a New "Highly Parallel" World
Diagrams
Ad

Recently uploaded (20)

PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Hybrid model detection and classification of lung cancer
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
August Patch Tuesday
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
1. Introduction to Computer Programming.pptx
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Encapsulation theory and applications.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
A comparative study of natural language inference in Swahili using monolingua...
Tartificialntelligence_presentation.pptx
Chapter 5: Probability Theory and Statistics
Hybrid model detection and classification of lung cancer
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
August Patch Tuesday
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Web App vs Mobile App What Should You Build First.pdf
A Presentation on Artificial Intelligence
SOPHOS-XG Firewall Administrator PPT.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Zenith AI: Advanced Artificial Intelligence
1. Introduction to Computer Programming.pptx
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Unlocking AI with Model Context Protocol (MCP)
Enhancing emotion recognition model for a student engagement use case through...
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Encapsulation theory and applications.pdf
Ad

Concurrency for dummies

  • 1. Concurrency for dummies and for real people too By Azrul Hasni Mad Isa (azrul.madisa@my.experian.com)
  • 2. About me • Senior Software Architect at Experian Decision Analytics • 10 years of experience in IT and such • Graduated from France (INSA)
  • 3. About Experian • In Cyberjaya – Other R&D Centres in Nottingham, Monaco, Washington • Financial analytics, market analytics • 200+ people and growing • We use Scrum • We are looking for people – Java, PHP, Perl, C# – Dev, QA, Architects, Team lead
  • 4. Introduction • What is concurrency Concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other -- Wikipedia
  • 5. Introduction • Why concurrent applications are important
  • 6. Introduction • Our business processes are getting more complex!
  • 7. Business case for concurrency • E-commerce Buy Product Online User Parallel Split Charge Credit Card “Your request is being process” Check availability Reserve product Email confirmation
  • 8. Business case for concurrency • Financial – credit verification CCRIS Apply Credit Card Credential Verification Equifax User Decision making Experian Approve/Not
  • 9. Business case for concurrency • Logistics Arrival of merchandises For every merchandise Parallel Split Custom & Port Warehousing Quality check … authority Transportation
  • 10. Business case for concurrency • Many others …
  • 11. Model for concurrency management • Actors • Agents • Dataflow • Stm • Data paralellism – Concurrent collections – Asynchronous functions (closure) – Fork/Join
  • 12. Model for concurrency management • Actors • Agents • Dataflow • Stm • Data paralellism – Concurrent collections – Asynchronous functions (closure) – Fork/Join
  • 13. GPARS
  • 14. GPars • Gpars is a concurrency management library for Groovy and Java • Allow running models presented above • http://gpars.codehaus.org/
  • 16. Actors • Why couldn’t they call ‘em actresses instead? • A body of code that: – Receive a message asynchronously – React to a message if it can – Queue a received message if it’s busy – Asynchronous messaging (JMS)
  • 17. Actor • Synchronous messaging = immediate reply The Nora Elena actress is soo cute! Why You !! You !!... I’ll kill you!!
  • 18. Actor • Asynchronous messaging = non-immediate reply – We can do other things while waiting Could you please make me a drink? … I’m going to ponder about the meaning of life in the meantime
  • 19. Actor • Asynchronous messaging = non-immediate reply – We can do other things while waiting Could you please make me a drink? … I’m going to ponder about the meaning of 2 hours later life in the meantime I was watching TV. Go make the drink yourself!
  • 20. Actors Queue Queue “sending a OneActor message” AnotherActor
  • 21. Actors Queue “reply to a Queue message” OneActor AnotherActor
  • 22. Actors • Example: DefaultActor { class MyActor extends Actor anotherActor void act() { loop { anotherActor.send “Hello” //send message to someone react { String message -> //message could be any POGO …//do something reply someReply //some reply is any POGO … terminate() //kill the actor *gasp!* } } } } }
  • 23. Actors • Two types – Stateless : DynamicDispatchActor – Stateful: DefaultActor • Actors are can share a common threadpool • Threadpool + statelessness = SCALABILITY • No remote actors yet
  • 24. Actor • Some methods – loop • Infinite loop on the actor – react • React on message received – send • Send a message – reply • Reply to a message
  • 25. Actor • Cool stuff – Loop counting – Code in actors are guaranteed to be thread safe – Life cycle methods – Dealing with unsent messages • Business Process Compensation – Remote actors – coming
  • 27. Dataflow • First introduced in a language called Oz – Composed of tasks – Each task has input and output – A task is run as soon as all its input are available
  • 28. Dataflow Not executed Task print z Task z = a+b Task b=32 Task a=20
  • 29. Dataflow Not executed First round Executed Task Task print z print z Task Task z = a+b z = a+b Task Task b=32 b=32 No input needed Task Task a=20 a=20
  • 30. Dataflow Not executed First round Second round Executed Task Task Task print z print z print z Task Task Task z = a+b z = a+b z = a+b Input, a and b, Task Task Task becomes b=32 b=32 b=32 available Task Task Task a=20 a=20 a=20
  • 31. Dataflow Not executed First round Second round Third round Task Task Task Task print z print z Input,print z z, print z becomes Task Task available Task Task z = a+b z = a+b z = a+b z = a+b Task Task Task Task b=32 b=32 b=32 b=32 Task Task Task Task a=20 a=20 a=20 a=20
  • 32. Dataflow: code final def x = new DataFlowVariable() final def y = new DataFlowVariable() final def z = new DataFlowVariable() task { z << x.val + y.val } task { x << 10 } task { y << 5 } println "Result: ${z.val}"
  • 33. Dataflow: principles • Create a dataflow variable – The variable can be written once only • Read it – If it has no value yet, the program will wait for the new value while executing other tasks • Write to it – The moment a variable is written (or bounded) any task waiting for this variable will be reactivated
  • 34. Dataflow: beauty • “Declarative” concurrency • Clean code – Business logic is much more obvious – Business logic can be sequential • Flow is deterministic • If no deadlock in unit test, it is guaranteed that there will be no deadlocks in production.
  • 35. Dataflow in business process Apply Credit Card Parallel split CCRIS Equifax Experian Parallel join Decision making Approve/Not
  • 36. Dataflow in business process Apply Credit Card Do business Parallel split users really think in CCRIS Equifax Experian Parallel executions? Parallel join Decision making Approve/Not
  • 37. Dataflow in business process I want to verify user credentials against CCRIS, Experian and You need parallel Equifax processing Business Solution architect stakeholder
  • 38. Dataflow in business process Suggestion by the solution architect I want to verify user credentials against CCRIS, Experian and You need parallel Equifax processing Business Solution architect stakeholder
  • 39. Dataflow in business process • Meanwhile, in a parallel universe … pun intended ☺ I want to verify user Dataflow Tasks OK? credentials against Apply Credit Card CCRIS, Experian and Equifax CCRIS Equifax Experian Decision making Approve/Not Solution Business architect stakeholder
  • 40. Dataflow in business process • Meanwhile, in a parallel universe Parallel execution is done Hey, I totally get that! automatically I totally want to give by GPars you more business! Dataflow Would you like a pony too? Business Solution architect stakeholder
  • 41. Dataflow in business process • Meanwhile, in a parallel universe Yes please Solution architect
  • 42. Conclusion • Actor – Asynchronous messaging • Dataflow – “Declarative” concurrency
  • 43. Conclusion • What we see is merely the tip of the iceberg • Explore yourself – http://gpars.codehaus.org/ – http://groovy.codehaus.org/ – http://en.wikipedia.org/wiki/Acto r_model – http://en.wikipedia.org/wiki/Data flow • My contact: azrul.madisa@my.experian.com