Jun 20, 2015
About me
• Senior Software
Architect at Experian
Decision Analytics
• 10 years of experience in • 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 analyticsanalytics
• 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 systemsin which several computations areexecuting simultaneously, andpotentially interacting with each otherpotentially 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
Parallel SplitUser
Parallel Split
“Your request is
being process”
Charge Credit Card
Check availability
Reserve product
Email confirmation
Business case for concurrency
• Financial – credit verification
Apply Credit CardCCRIS
Credential Verification Equifax
Experian
Approve/Not
User
Decision making
Business case for concurrency
• LogisticsArrival of merchandises
For every merchandise
…
Parallel Split
Custom & Port authority
Warehousing Quality check
Transportation
Business case for concurrency
• Many others …
Model for concurrency management
• Actors
• Agents
• Dataflow
• Stm• Stm
• Data paralellism
– Concurrent collections
– Asynchronous functions (closure)
– Fork/Join
Model for concurrency management
• Actors
• Agents
• Dataflow
• Stm• 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 • 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 – 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!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? …make me a drink? …
I’m going to ponderabout 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 was watching TV. Go make the drink
yourself!
2 hours later
make me a drink? …
I’m going to ponderabout the meaning of life in the meantime
Actors
Queue Queue
OneActor AnotherActor
“sending a
message”
Actors
Queue Queue“reply to a
message”
OneActor AnotherActor
Actors
• Example:class MyActor extends DefaultActor {
Actor anotherActor
void act() {
loop {
anotherActor.send “Hello” //send message to someone
react { String message -> //message could be any POGOreact { 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 • 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
• 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– 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– A task is run as soon as all its input are available
Dataflow
Task
print z
Task
z = a+b
Not executed
Task
a=20
Task
b=32
z = a+b
Dataflow
Task
print z
Task
z = a+b
Not executed
Task
print z
Task
z = a+b
First round Executed
Task
a=20
Task
b=32
z = a+b
Task
a=20
Task
b=32
z = a+b
No input needed
Dataflow
Task
print z
Task
z = a+b
Not executed
Task
print z
Task
z = a+b
First round
Task
print z
Task
z = a+b
Second round Executed
Task
a=20
Task
b=32
z = a+b
Task
a=20
Task
b=32
z = a+b
Task
a=20
Task
b=32
z = a+b
Input, a and b,becomes available
Dataflow
Task
print z
Task
z = a+b
Not executed
Task
print z
Task
z = a+b
First round
Task
print z
Task
z = a+b
Second round
Task
print z
Task
z = a+b
Third round
Input, z,becomes available
Task
a=20
Task
b=32
z = a+b
Task
a=20
Task
b=32
z = a+b
Task
a=20
Task
b=32
z = a+b
Task
a=20
Task
b=32
z = a+b
Dataflow: code
final def x = new DataFlowVariable()
final def y = new DataFlowVariable()
final def z = new DataFlowVariable()
task {
z << x.val + y.val
}
task {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 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– 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 processApply Credit Card
CCRIS Equifax Experian
Parallel split
Approve/Not
Decision making
Parallel join
Dataflow in business processApply Credit Card
CCRIS Equifax Experian
Parallel splitDo business users really
think in Parallel
executions?
Approve/Not
Decision making
Parallel join
executions?
Dataflow in business process
I want to verify user credentials against
CCRIS, Experian and Equifax
You need parallelprocessing
Business
stakeholder
Solution architect
Dataflow in business process
I want to verify user credentials against
CCRIS, Experian and Equifax
You need parallelprocessing
Suggestion by the solution architect
Business
stakeholder
Solution architect
Dataflow in business process
• Meanwhile, in a parallel universe … pun intended ☺
I want to verify user credentials against
CCRIS, Experian and Equifax
Apply Credit Card
CCRIS
Equifax
OK?Dataflow Tasks
Business
stakeholder
Solution architect
Equifax
Experian
Approve/Not
Decision making
Dataflow in business process
• Meanwhile, in a parallel universe
Hey, I totally get that!
I totally want to give you more business!
Parallel execution is
done automatically
by GParsDataflow
Would you like a pony too?
Business
stakeholder
Solution architect
Dataflow in business process
• Meanwhile, in a parallel universe
Yes please
Solution architect
Conclusion
• Actor
– Asynchronous messaging
• Dataflow
– “Declarative” concurrency– “Declarative” concurrency
Conclusion
• What we see is merely the tip of the iceberg
• Explore yourself
– http://gpars.codehaus.org/
– http://groovy.codehaus.org/– http://groovy.codehaus.org/
– http://en.wikipedia.org/wiki/Actor_model
– http://en.wikipedia.org/wiki/Dataflow
• My contact: [email protected]