4. What concurrency
offers
reduce latency
divide and conquer, run in parallel reduce
the latency
hide latency
asynchronous
increase throughput
more tasks can be run without wasting
available computing power
Thursday, January 20, 2011
5. What we do with
Java Concurrency
State , That’s all of the about.
Atomicity - keep state intact
Visibility - make right state access
Thursday, January 20, 2011
8. What We Will Talk
Today
Share-State Concurrency
Share-Nothing Concurrency
Software Transaction Memory
Data-Flow Concurrency
Thursday, January 20, 2011
9. Share-State
Concurrency
Thursday, January 20, 2011
10. JMM Simplified
Picture borrowed from <<Java >>
Thursday, January 20, 2011
12. How to deal with?
How many ways can you count?
Here we go...
Thursday, January 20, 2011
13. Immutability
immutable anytime
Immutable Object
immutable before publishing
Map & ConcurrencyMap
(1)To Find More in book <<Java Concurrency In Practice>>
Thursday, January 20, 2011
16. Gotchas With
Synchronization
Deadlock
how to prevent it?
Live lock
Starvation
Thursday, January 20, 2011
17. Gotchas With
Synchronization
Deadlock
how to prevent it?
Resource Re-ordering
Live lock
Starvation
Thursday, January 20, 2011
18. Gotchas With
Synchronization
Deadlock
how to prevent it?
Resource Re-ordering
Periodic Retry
Live lock
Starvation
Thursday, January 20, 2011
19. Performance Tuning
with Synchronization
reduce the time of holding locks
break global locks into fine-grained locks
what coming next?
Thursday, January 20, 2011
20. CAS
Compare-And-Set | Compare-And-Swap
java.util.concurrent.atomic after Java5
AtomicInteger
AtomicLong
AtomicBoolean
AtomicReference
Thursday, January 20, 2011
21. Section Conclusion
Pessimistic Model
Lock-Based
Optimistic Model
Lock-Free
Thursday, January 20, 2011
22. Share-Nothing
Concurrency
Thursday, January 20, 2011
23. Share-Nothing
Concurrency
AKA. Message Passing Concurrency
Confinement In a Big Picture
Thursday, January 20, 2011
24. Actor Model
First proposed by Carl Hewitt in 1973
improved by Gul Agha
An Actor Can:
change internal state
send messages to peer actors
create new actors
migrate to another computing host
Thursday, January 20, 2011
25. Actor Rocks
more light weight
event based actors of akka can create
6.5million on 4 G RAM (600 bytes each)
much easier, just send messages
counter ! tick
Thursday, January 20, 2011
26. Actors Available
Erlang Platform
Scala Platform
TBA, EBA
Lift Actor, Akka Actor
Java Platform
Kilim, SALSA(simple actor language, system
and architecture)
Other
Thursday, January 20, 2011
27. Actor Almighty?
when we really have shared states, e.g. bank
account?
when we need to form unified consensus
when we need synchronous behavior
a bit verbose compared to method dispatch
Thursday, January 20, 2011
28. Section Conclusion
Actor Model Rocks In Some Situations, But not
all
Share Nothing Simplify the Architecture Design
Prefer Share Nothing to Share State If Possible
Thursday, January 20, 2011
30. Case Study I
Session Management
Centralized Storage
memcached, database...
Client-Specific Storage
secure cookie
other local-storage mechanism
Thursday, January 20, 2011
31. Case Study II
Map-Reduce
When Share Nothing can rock in
When Share State Is a Must
Thursday, January 20, 2011
32. Case Study III
Symmetric Cluster
Share Nothing
Asymmetric Cluster
Share State
Thursday, January 20, 2011
33. STM
Software Transaction Memory
Transaction operations execute in the own
thread in parallel, commit will cause One to be
successful and others to abort or retry
Thursday, January 20, 2011
34. Sounds Familiar?
Optimistic Model
Can be nested
Simple Programming Model
Thursday, January 20, 2011
35. Available Solutions
Clojure
Concurrent Haskell
STM .Net
More...
Thursday, January 20, 2011
36. Cons
All operations in scope of a transaction:
need to be idempotent
can’t have side-effects
Memory Concern
Conflicting Rate Concern
Thursday, January 20, 2011
37. Section Conclusion
optimistic model
simple programming model
with restrictions
which may cause limitations(MS drops STM)
Thursday, January 20, 2011
38. Data-Flow
Concurrency
AKA. Declarative Concurrency
Thursday, January 20, 2011