Driving Behavioral Change for Information Management through Data-Driven Gree...
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
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
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
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
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