You are on page 1of 13

Java Concurrency and Performance Workshop

Training Content 28th, 29th & 30th June 2013 By


MOVAA Technologies

MOVAA Technologies 2 Java Concurrency and Performance

JAVA CONCURRENCY
(The most important reason for most applications(Enterprise and real-time) to fail or underperform is improper design for concurrency. This is especially true because of multi cores/processor becoming ubiquitous. This training course takes a wholistic view of concurrency including designing for multi-cores/processors(including NUMA).)

Pre-requisites: Basic knowledge of Java (introductory course or equivalent practical experience). Target Audience: The target group is programmers who want to know foundations of concurrent programming and existing concurrent programming environments, in order, now or in future, to develop multithreaded applications for multi-core processors and shared memory multiprocessors. Objective: x Understand concurrency control issues in general. x Know the instruments available in Java. x Avoid common errors and pitfalls. x Understand concurrency control idioms. What you will learn: x Designing applications for multi-core/multi-processor environments through detailed concurrency patterns and design principles. x Will understand the use of highly concurrent data structures and their design, well enough to be applied in software design. x Dealing with threads and collections on a multi core .
2

MOVAA Technologies | www.movaatechnologies.com

MOVAA Technologies 3 Java Concurrency and Performance

x JDK 5,6,7 which have Features and Classes to harness the power of the underlying technologies. x Detecting Deadlocks and Livelocks in existing applications by following Concurrency Patterns to avoid the above mentioned. x Will understand the use of Hardware based Locking. x To quickly identify the root causes of poor performance in your applications. x Eliminate conditions that will prevent you from finding performance bottlenecks.

MOVAA Technologies | www.movaatechnologies.com

MOVAA Technologies 5 Java Concurrency and Performance

Detailed Table of Contents


Producer Consumer(Basic Hand-Off) (Part-1)
c

Why wait-notify require Synchronization


locking handling done by OS Hidden queue Structural modification to hidden queue by wait-notify use cases for notify-notifyAll notifyAll used as work around design issues with synchronization

Common Issues with thread


c c c

problem with stop Dealing with InterruptedStatus Uncaught Exception Handler

Java Memory Model(JMM)


c c

Sequential Consistency would disallow common optimizations Instruction Reordering


heavily pipelines processors super-scalar processors NUMA(Non uniform memory access)

Cache Coherency

c c c c

Real Meaning and effect of synchronization Volatile Final The changes in JMM
5

Applied Threading techniques


c c

Thread Local Storage Safe Construction techniques


MOVAA Technologies | www.movaatechnologies.com

MOVAA Technologies 6 Java Concurrency and Performance

c c

UnSafe Construction techniques Thread safety levels

Building Blocks for Highly Concurrent Design


c

CAS Hardware based locking


Optimistic Design ABA problem Markable reference Stamped reference weakCompareAndSet

Wait-free Stack implementation Wait-free Queue implementation Design issues with synchronization Multiple user conditions and wait queues Lock Polling techniques Reentrant Lock ReentrantReadWriteLock ReentrantLock

Lock Implementation

Based on CAS Lock Striping on table Lock Striping on LinkNodes. segregating them based on Thread safety levels

Lock Striping

Indentifying scalability bottlenecks in java.util.Collection

MOVAA Technologies | www.movaatechnologies.com

MOVAA Technologies 7 Java Concurrency and Performance

Highly Concurrent Data StructuresPart1


c

ConcurrentHashMap

Structure Almost immutability Using volatile to detect interference Read does not block in common code path remove/put/resize lock

c c

Weakly Consistent Iterators vs Fail Fast Iterators LockFreeHashMap


For systems with more than 100 cpus/cores Constant Time key-value mapping no locks even during resize all CAS spin loop bounded faster than ConcurrentHashMap State based Reasoning

Designing For Concurrency


c c c c c c

Confinement Immutability Almost Immutability Atomicity Visibility Restructuring and refactoring


7

Canned Synchronizers
c

Synchronous Queue Framework


MOVAA Technologies | www.movaatechnologies.com

MOVAA Technologies 8 Java Concurrency and Performance

c c c c c c c

Future Semaphore Mutex Barrier Latches SynchronousQueue Exchanger

Highly Concurrent Data Structures-Part2


c c

CopyOnWriteArray(List/Set) Queue interfaces


Queue BlockingQueue Deque BlockingDeque

Queue Implementations

ConcurrentLinkedQueue LinkedBlockingQueue and LinkedBlockingDeque ArrayBlockingDeque ArrayDeque and ArrayBlockingDeque WorkStealing using Deques LinkedTransferQueue ConcurrentSkipList(Map/Set) Sequential Skiplist Lock based concurrent Skiplist Lock free concurrent Skiplist Concurrent Skiplist
8

Skiplists

MOVAA Technologies | www.movaatechnologies.com

MOVAA Technologies 9 Java Concurrency and Performance

Executor FrameWork

Configuration Hardware shapes programming idiom Exposing fine grained parallelism Divide and conquer Fork and Join Anatomy of Fork and Join Work Stealing Fork -join decomposition ParallelArray Limitations

Fork and Join Framework


Crash course in Mordern hardware


c c

Amdahl's Law Cache Direct mapped Address mapping in cache read write cache controller

Memory Architectures

UMA NUMA

Concurrent Reasoning
c c c c

Sequential Consistency Linearizability Quiescent Consistency Compositionality


MOVAA Technologies | www.movaatechnologies.com 9

JAVA MEMORY MANAGEMENT


GARBAGE COLLECTION TUNING + SIZING MEMORY GENERATIONS

OVERVIEW
z

Theory and concepts:


   

JVM memory areas GC Tuning SAP standards HPJMeter JVMStat SAP Memory Analyser

Tools for logfile analysis






z z

Case Study Discussion

JAVA VS C++
# include < string> int ma in ( int a rgc, cha r ** a rgv) { int i; string * va r; for (i = 0; i < 1000; i + + ) { va r = ne w string (me mory le a king or not); de le te (va r); } }

JAVA VS C++
import ja va .la ng.String; public sta tic void ma in ( String [] a rgume nts) { int i; String va r; for (i = 0; i < 1000; i + + ) { va r = ne w String (me mory ne ve r le a king); } }

TOWARDS HOTSPOT JVM

You might also like