www.ExigenServices.comNon-blocking algorithms at trafficconditionsAlina Ziyatova
Your Reliable IT Business Solution ProviderHow to control shared resources?
Your Reliable IT Business Solution ProviderRacesABvalue -> 7 7 + 1 -> 8 value = 8value -> 7 7 + 1 -> 8 value = 8
Your Reliable IT Business Solution ProviderIncrement operationlong i = 0;i ++;readmodifyset
Your Reliable IT Business Solution ProviderGuaranteed:Visibility of changesAtomicity of operationsDisadvantages:Throughput...
Your Reliable IT Business Solution ProviderThe worst caseDeadlockResource 1 Resource 2Thread 1 Thread 2I am waiting… I am ...
Your Reliable IT Business Solution ProviderAtomic packageAtomicLong i = new AtomicLong(0);i.getAndIncrement();readmodifyset
Your Reliable IT Business Solution ProviderCompare & Set operationsRead the valueReturn falseIs it differ from expected on...
Your Reliable IT Business Solution ProviderCompare & Set operationsRead a valueof thevariablePerform anintermediatecomputi...
Your Reliable IT Business Solution ProviderNon-blocking algorithmsWait-freeNon-blockingLock-free
Your Reliable IT Business Solution ProviderStackHEADLast In – First Out1 2null32 3
Your Reliable IT Business Solution ProviderTreiber’s algorithm for StackNodestatic class Node<E> {final E item;Node<E> nex...
Your Reliable IT Business Solution ProviderTreiber’s algorithm for Stackimport java.util.concurrent.atomic.AtomicReference...
Your Reliable IT Business Solution ProviderTreiber’s algorithm for StackHEAD123Push a new NodeRead referenceUpdate next fi...
Your Reliable IT Business Solution ProviderTreiber’s algorithm for StackRemove a NodeHEAD13Read reference to next itemCAS....
Your Reliable IT Business Solution ProviderPerformance comparison020000004000000600000080000001000000012000000140000001600...
Your Reliable IT Business Solution ProviderPerformance comparisonWin7 Enterprise, Intel Core i5-2500Add probability = 0.2,...
Your Reliable IT Business Solution ProviderConclusionChoose a type of Collectionsdepending on your taskNon-blocking algori...
Your Reliable IT Business Solution ProviderPerformance comparisonWin7 Enterprise, Intel Core i5-2500Add probability = 0.6,...
Your Reliable IT Business Solution ProviderQuestions
Upcoming SlideShare
Loading in …5
×

Non Blocking Algorithms at Traffic Conditions

373 views

Published on

Java Day 2013 Presentation
Presenter: Alina Ziyatova

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
373
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Non Blocking Algorithms at Traffic Conditions

  1. 1. www.ExigenServices.comNon-blocking algorithms at trafficconditionsAlina Ziyatova
  2. 2. Your Reliable IT Business Solution ProviderHow to control shared resources?
  3. 3. Your Reliable IT Business Solution ProviderRacesABvalue -> 7 7 + 1 -> 8 value = 8value -> 7 7 + 1 -> 8 value = 8
  4. 4. Your Reliable IT Business Solution ProviderIncrement operationlong i = 0;i ++;readmodifyset
  5. 5. Your Reliable IT Business Solution ProviderGuaranteed:Visibility of changesAtomicity of operationsDisadvantages:Throughputpublic synchronize void method() {// reading or modification}Modifier synchronize
  6. 6. Your Reliable IT Business Solution ProviderThe worst caseDeadlockResource 1 Resource 2Thread 1 Thread 2I am waiting… I am waiting too…
  7. 7. Your Reliable IT Business Solution ProviderAtomic packageAtomicLong i = new AtomicLong(0);i.getAndIncrement();readmodifyset
  8. 8. Your Reliable IT Business Solution ProviderCompare & Set operationsRead the valueReturn falseIs it differ from expected one?ModifyReturn true
  9. 9. Your Reliable IT Business Solution ProviderCompare & Set operationsRead a valueof thevariablePerform anintermediatecomputingRead a value of thevariable again andcompare withprevious oneHas the valuechanged?YesNo
  10. 10. Your Reliable IT Business Solution ProviderNon-blocking algorithmsWait-freeNon-blockingLock-free
  11. 11. Your Reliable IT Business Solution ProviderStackHEADLast In – First Out1 2null32 3
  12. 12. Your Reliable IT Business Solution ProviderTreiber’s algorithm for StackNodestatic class Node<E> {final E item;Node<E> next;public Node(E item) {this.item = item;}}1 2
  13. 13. Your Reliable IT Business Solution ProviderTreiber’s algorithm for Stackimport java.util.concurrent.atomic.AtomicReference;public class ConcurrentStack<E> {AtomicReference<Node<E>> head =new AtomicReference<Node<E>>();//. . .}HEAD1 2
  14. 14. Your Reliable IT Business Solution ProviderTreiber’s algorithm for StackHEAD123Push a new NodeRead referenceUpdate next fieldCAS. . .1 22 310 10
  15. 15. Your Reliable IT Business Solution ProviderTreiber’s algorithm for StackRemove a NodeHEAD13Read reference to next itemCAS. . .Read head reference222 3121
  16. 16. Your Reliable IT Business Solution ProviderPerformance comparison02000000400000060000008000000100000001200000014000000160000001 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16ConcurrentHashMapConcurrentSkipListMapSynchronizedHashMapSynchronizedTreeMapHashtableNumber of threadsWin7 Enterprise, Intel Core i5-2500Add probability = 0.6, Remove probability = 0.1Java version 1.6.0_37
  17. 17. Your Reliable IT Business Solution ProviderPerformance comparisonWin7 Enterprise, Intel Core i5-2500Add probability = 0.2, Remove probability = 0.605000000100000001500000020000000250000001 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16ConcurrentHashMapConcurrentSkipListMapSynchronizedHashMapSynchronizedTreeMapHashtableJava version 1.6.0_37Number of threads
  18. 18. Your Reliable IT Business Solution ProviderConclusionChoose a type of Collectionsdepending on your taskNon-blocking algorithms mayconsume full resources of a server
  19. 19. Your Reliable IT Business Solution ProviderPerformance comparisonWin7 Enterprise, Intel Core i5-2500Add probability = 0.6, Remove probability = 0.1050000001000000015000000200000002500000030000000350000001 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16Java 1.7.0Java 1.6.0_37ConcurrentHashMapNumber of threads
  20. 20. Your Reliable IT Business Solution ProviderQuestions

×