samedi, juin 27, 2009

Jazoon Day 1: Concurrency and Performance reloaded

Already lots of issues in single-threaded applications.
Moore's law is continued by multiple cores.
Concurrent programming is not possible yet, we can only cope with it.

Sadly (or not) concurrency is the main programming focus nowadays.

We have to deal with concurrency explicitely while before you could just wait for the platforms to improve and gain performances ;)

Problems:
- Hardware components are not shareable.
- Access to shared data has to be serialized.
- Databases offer access to shared data.
- Serialization limits scalability.

He then talks about Amdahl's law (parallel computing is limited by the time needed for the sequential part of the computing)
and Little's law (Throughput is inversely proportional to service time).

In Java: locking is pessimistic. Huge problem.

In fact 99% of locks are almost never really contended, and a large part of those will never be contended at all by design.

In Java 1.5, we have Java Locks and system level locks (hotspot profiles the application and determines if a lock is contended or not, and choose one or the other)

Lock coarsening uses one lock only for nearby equivalently locked operations.

Compare And Swap (CAS) used in Atomic classes. Fails only if another threads updates the data during your access. Needs less locking.

Biased Locking:
If a thread continuously acquires a lock, CAS is not used, and the thread keeps the lock until another one is reclaiming it (unbiasing)

How to code this correctly:

java.util.concurrent of course (Atomic*)
Lock striping (ConcurrentHashMap)
Teaching threads to steal (after all Garbage collecting is doing it).

In 1.7: Fork-Join

Fully concurrent lock-free algorithms:
No blocking, threads are never waiting for anything.
Wait free is different of course but should be achieve
Parallel reads, serialized writes

NonBlockingHashMap scales very well up to 1000 CPUs even for R/W, when ConcurrentHashMap doesn't.


Fully concurrent lock-less FIFO?
What does FIFO mean in multicore?
=> Doug Lea's wait-free queue (getAndSet(V))

Things that don't make sense
Iterator
Size
Contains

These are not relevant in highly concurrent environment.
APIs must therefore be re-thought through.

Very nice yet intricate talk. Too bad there's not more time for Dirk Pepperdine to go more into details!