Profiling Concurrency

Profiling Concurrency

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

661bb4dee881617e676c4d954ce97a70?s=128

Konrad Reiche

August 18, 2011
Tweet

Transcript

  1. Bachelor Thesis Presentation Konrad Johannes Reiche Supervised by Prof. Dr.

    Marcel Kyas Profiling Concurrency
  2. 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
  3. 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
  4. 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?
  5. 5 JVMTI Java Virtual Machine Tool Interface Profiling Concurrency, August

    18, 2011
  6. 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
  7. 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
  8. 8 How do you measure concurrent program execution? Profiling Concurrency,

    August 18, 2011
  9. 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
  10. 10 FUNCTIONALITY What are the results? Profiling Concurrency, August 18,

    2011
  11. 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
  12. 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?
  13. 13 Start the Profiling Profiling Concurrency, August 18, 2011

  14. 14 General View Profiling Concurrency, August 18, 2011

  15. 15 Monitor Log Profiling Concurrency, August 18, 2011

  16. 16 Monitor Log Profiling Concurrency, August 18, 2011

  17. 17 Monitor Profiling Concurrency, August 18, 2011

  18. 18 Deadlock Detection Profiling Concurrency, August 18, 2011

  19. 19 Method Profiling Profiling Concurrency, August 18, 2011

  20. 20 Method Profiling Profiling Concurrency, August 18, 2011

  21. 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
  22. 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; }
  23. 23 EVALUATION How can it be evaluated? Profiling Concurrency, August

    18, 2011
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. 32 CONCLUSION What is the bottom line? Profiling Concurrency, August

    18, 2011
  33. 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
  34. 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
  35. 35 Thank you! Feel free to clone my project on

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