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 fr...
About Experian• In Cyberjaya   – Other R&D Centres in     Nottingham, Monaco,     Washington• Financial analytics, market ...
Introduction• What is concurrency        Concurrency is a property of systems        in which several computations are    ...
Introduction• Why concurrent applications are important
Introduction• Our business processes are getting more  complex!
Business case for concurrency• E-commerce                                Buy Product                                  Onli...
Business case for concurrency• Financial – credit verification                                              CCRIS         ...
Business case for concurrency• Logistics                Arrival of merchandises                For every merchandise      ...
Business case for concurrency• Many others …
Model for concurrency management•   Actors•   Agents•   Dataflow•   Stm•   Data paralellism    – Concurrent collections   ...
Model for concurrency management•   Actors•   Agents•   Dataflow•   Stm•   Data paralellism    – Concurrent collections   ...
GPARS
GPars• Gpars is a concurrency  management library for  Groovy and Java• Allow running models  presented above• http://gpar...
ACTORS
Actors• Why couldn’t they call ‘em actresses instead?• A body of code that:  – Receive a message asynchronously  – React t...
Actor• Synchronous messaging = immediate reply          The Nora Elena        actress is soo cute!                        ...
Actor• Asynchronous messaging = non-immediate  reply  – We can do other things while waiting                 Could you ple...
Actor• Asynchronous messaging = non-immediate  reply  – We can do other things while waiting                 Could you ple...
Actors       Queue                          Queue               “sending aOneActor       message”     AnotherActor
Actors       Queue    “reply to a             Queue                message”OneActor                      AnotherActor
Actors• Example: DefaultActor {  class MyActor extends      Actor anotherActor      void act() {          loop {          ...
Actors• Two types  – Stateless : DynamicDispatchActor  – Stateful: DefaultActor• Actors are can share a common  threadpool...
Actor• Some methods  – loop     • Infinite loop on the actor  – react     • React on message received  – send     • Send a...
Actor• Cool stuff  – Loop counting  – Code in actors are guaranteed to be thread safe  – Life cycle methods  – Dealing wit...
DATAFLOW
Dataflow• First introduced in a language called Oz  – Composed of tasks  – Each task has input and output  – A task is run...
DataflowNot executed    Task   print z    Task   z = a+b  Task  b=32  Task  a=20
DataflowNot executed   First round                       Executed    Task          Task   print z       print z    Task   ...
DataflowNot executed   First round    Second round               Executed    Task          Task          Task   print z   ...
DataflowNot executed   First round       Second round   Third round    Task          Task              Task          Task ...
Dataflow: codefinal def x = new DataFlowVariable()final def y = new DataFlowVariable()final def z = new DataFlowVariable()...
Dataflow: principles• Create a dataflow variable   – The variable can be written once     only• Read it   – If it has no v...
Dataflow: beauty• “Declarative” concurrency• Clean code  – Business logic is much more obvious  – Business logic can be se...
Dataflow in business process               Apply Credit Card                 Parallel split       CCRIS        Equifax    ...
Dataflow in business process                       Apply Credit CardDo business              Parallel splitusers really  t...
Dataflow in business process I want to verify user  credentials againstCCRIS, Experian and       You need parallel       E...
Dataflow in business process                         Suggestion by the solution architect I want to verify user  credentia...
Dataflow in business process• Meanwhile, in a parallel universe … pun intended ☺    I want to verify user   Dataflow Tasks...
Dataflow in business process• Meanwhile, in a parallel universe                Parallel                                   ...
Dataflow in business process• Meanwhile, in a parallel universe                                  Yes please               ...
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://groo...
Upcoming SlideShare
Loading in...5
×

Concurrency for dummies

1,799

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,799
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
28
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Concurrency for dummies

  1. 1. Concurrency for dummies and for real people too By Azrul Hasni Mad Isa(azrul.madisa@my.experian.com)
  2. 2. About me• Senior Software Architect at Experian Decision Analytics• 10 years of experience in IT and such• Graduated from France (INSA)
  3. 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. 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. 5. Introduction• Why concurrent applications are important
  6. 6. Introduction• Our business processes are getting more complex!
  7. 7. Business case for concurrency• E-commerce Buy Product OnlineUser Parallel Split Charge Credit Card “Your request is being process” Check availability Reserve product Email confirmation
  8. 8. Business case for concurrency• Financial – credit verification CCRIS Apply Credit Card Credential Verification EquifaxUser Decision making Experian Approve/Not
  9. 9. Business case for concurrency• Logistics Arrival of merchandises For every merchandise Parallel Split Custom & Port Warehousing Quality check … authority Transportation
  10. 10. Business case for concurrency• Many others …
  11. 11. Model for concurrency management• Actors• Agents• Dataflow• Stm• Data paralellism – Concurrent collections – Asynchronous functions (closure) – Fork/Join
  12. 12. Model for concurrency management• Actors• Agents• Dataflow• Stm• Data paralellism – Concurrent collections – Asynchronous functions (closure) – Fork/Join
  13. 13. GPARS
  14. 14. GPars• Gpars is a concurrency management library for Groovy and Java• Allow running models presented above• http://gpars.codehaus.org/
  15. 15. ACTORS
  16. 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. 17. Actor• Synchronous messaging = immediate reply The Nora Elena actress is soo cute! Why You !! You !!... I’ll kill you!!
  18. 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. 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. 20. Actors Queue Queue “sending aOneActor message” AnotherActor
  21. 21. Actors Queue “reply to a Queue message”OneActor AnotherActor
  22. 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. 23. Actors• Two types – Stateless : DynamicDispatchActor – Stateful: DefaultActor• Actors are can share a common threadpool• Threadpool + statelessness = SCALABILITY• No remote actors yet
  24. 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. 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
  26. 26. DATAFLOW
  27. 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. 28. DataflowNot executed Task print z Task z = a+b Task b=32 Task a=20
  29. 29. DataflowNot 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. 30. DataflowNot 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. 31. DataflowNot 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. 32. Dataflow: codefinal 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. 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. 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. 35. Dataflow in business process Apply Credit Card Parallel split CCRIS Equifax Experian Parallel join Decision making Approve/Not
  36. 36. Dataflow in business process Apply Credit CardDo business Parallel splitusers really think in CCRIS Equifax Experian Parallelexecutions? Parallel join Decision making Approve/Not
  37. 37. Dataflow in business process I want to verify user credentials againstCCRIS, Experian and You need parallel Equifax processingBusiness Solution architectstakeholder
  38. 38. Dataflow in business process Suggestion by the solution architect I want to verify user credentials againstCCRIS, Experian and You need parallel Equifax processingBusiness Solution architectstakeholder
  39. 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. 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. 41. Dataflow in business process• Meanwhile, in a parallel universe Yes please Solution architect
  42. 42. Conclusion• Actor – Asynchronous messaging• Dataflow – “Declarative” concurrency
  43. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×