Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Profiling Concurrency

Profiling Concurrency

Bachelor thesis presentation on how to approach the development of a Java profiler with emphasis on concurrent program information.

Konrad Reiche

August 18, 2011
Tweet

More Decks by Konrad Reiche

Other Decks in Programming

Transcript

  1. 2 Threads are everywhere • Writing correct programs is hard

    • But, writing correct concurrent programs is even harder • Sharing resources without synchronization: Concurrency Bugs Non-deterministic Scheduling • Example: NetBeans – trying to patch a single class over 14 times for fixing a thread related problem Profiling Concurrency, August 18, 2011
  2. 3 Quality Assurance • quality assurance cannot only reached by

    carefully considered design • instead: use testing tools – Analytical Quality Assurance Profiler Dynamic Program Analysis • measure program routines and memory consumption • monitor and trace events, measure the costs • kind of measured values depends on the requirements Profiling Concurrency, August 18, 2011
  3. 4 Problem Statement • trace information about threads • trace

    information about their interactions with each other • make access to synchronized data visible • reveal information about classes thread-safety • measure events related to monitors and higher synchronization primitives – Semaphore, Barrier, etc. • visualize the collected data Profiling Concurrency, August 18, 2011 What should be achieved?
  4. 6 JVMTI Naive approach: direct profiling with printf debugging Better:

    JVMTI decouples JVM and presentation of the profiling information Profiling Concurrency, August 18, 2011 Profiler Process Profiler Front End JVM Process Java Virtual Machine Profiling Agent Tool Interface Event Control Communication Protocol
  5. 7 Event-Based Profiling Instrumentation: Ability to monitor or measure the

    product’s performance and diagnose possible errors What kind of events? … and many more Profiling Concurrency, August 18, 2011 Thread Start/End Method Entry/Exit Monitor Contention
  6. 9 Design Profiling Concurrency, August 18, 2011 Profiler Process Profiler

    Front End JVM Process Java Virtual Machine Profiling Agent Tool Interface Event Control Communication Protocol C++ Shared Library Event Callbacks Message Service Utilities View Controller Model Service protobuf
  7. 11 public class EnhancedSynchronizedList<T> { public List<T> list = Collections.synchronizedList(new

    ArrayList<T>()); public boolean putIfAbsent(T x) { boolean isAbsent = !list.contains(x); if (isAbsent) { list.add(x); } return isAbsent; } } Use Case: Extending a Thread-Safe Class Profiling Concurrency, August 18, 2011 synchronized
  8. 12 public class EnhancedSynchronizedList<T> { public List<T> list = Collections.synchronizedList(new

    ArrayList<T>()); public boolean putIfAbsent(T x) { boolean isAbsent = !list.contains(x); if (isAbsent) { list.add(x); } return isAbsent; } } Use Case: Extending a Thread-Safe Class Profiling Concurrency, August 18, 2011 synchronized Is it still thread-safe?
  9. 21 Use Case: Extending a Thread-Safe Class public class EnhancedSynchronizedList<T>

    { public List<T> list = Collections.synchronizedList(new ArrayList<T>()); public synchronized boolean putIfAbsent(T x) { boolean isAbsent = !list.contains(x); if (isAbsent) { list.add(x); } return isAbsent; } } Profiling Concurrency, August 18, 2011 Class Context EnhancedSynchronizedList EnhancedSynchronizedList.putIfAbsent java.util.Collections$SynchronizedCollection Collections$SynchronizedCollection.add
  10. 22 Use Case: Extending a Thread-Safe Class public class EnhancedSynchronizedList<T>

    { public List<T> list = Collections.synchronizedList(new ArrayList<T>()); Profiling Concurrency, August 18, 2011 Class Context EnhancedSynchronizedList EnhancedSynchronizedList.putIfAbsent java.util.Collections$SynchronizedCollection Collections$SynchronizedCollection.add public boolean putIfAbsent(T x) { synchronized (list) { boolean isAbsent = !list.contains(x); if (isAbsent) { list.add(x); } } return isAbsent; }
  11. 24 Use Cases Profiling Concurrency, August 18, 2011 • Extending

    a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Already little information helps to identify design flaws
  12. 25 Use Cases Profiling Concurrency, August 18, 2011 • Extending

    a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Profiling many threads leads to information overload Solution: introducing filters
  13. 26 Use Cases Profiling Concurrency, August 18, 2011 • Extending

    a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Stack traces put the traced events into a context
  14. 27 Use Cases Profiling Concurrency, August 18, 2011 • Extending

    a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Profiling many threads leads to information overload Solution: introducing filters
  15. 28 Use Cases Profiling Concurrency, August 18, 2011 • Extending

    a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Method profiling can lead to huge overhead Application took over 240 times longer to execute
  16. 29 Use Cases Profiling Concurrency, August 18, 2011 • Extending

    a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Relying on event callbacks only is not sufficient in order to profile higher synchronization primitives
  17. 30 Use Cases Profiling Concurrency, August 18, 2011 • Extending

    a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Profiler is able to detect deadlocks dynamically
  18. 31 Use Cases Profiling Concurrency, August 18, 2011 • Extending

    a Thread-Safe Class • Overhead of Santa Claus Problem • Fairness of Bounded Buffer • Bottleneck in Concurrent Merge Sort • Instrumenting Explicit Locks • Dynamic Lock-Ordering Deadlock • Synchronizing on Strings Already little information helps to identify design flaws
  19. 33 Conclusion Profiling Concurrency, August 18, 2011 • noticeable information

    gain • successful tracking of synchronization events • reveals information about thread-safety • can inspect a past state of the program • visualization helps to examine the data • depending on the application: overhead • fails for higher synchronization primitives • limited to tracking monitor events and performing method profiling
  20. 34 Summary and Further Work • JVMTI eases development of

    a decoupled profiler • tracing events is easy when the type of event is supported • using event callbacks only is not sufficient and inefficient • overhead can be reduced through heavy use of filters and byte code instrumentation • extend profiler by using bytecode instrumentation • record scheduling decisions • reduce overhead • compare with alternative profiling methods Profiling Concurrency, August 18, 2011
  21. 35 Thank you! Feel free to clone my project on

    GitHub: https://github.com/platzhirsch/Profiling-Concurrency Profiling Concurrency, August 18, 2011