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. Bachelor Thesis Presentation
    Konrad Johannes Reiche
    Supervised by Prof. Dr. Marcel Kyas
    Profiling Concurrency

    View Slide

  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

    View Slide

  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

    View Slide

  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?

    View Slide

  5. 5
    JVMTI
    Java Virtual Machine Tool Interface
    Profiling Concurrency, August 18, 2011

    View Slide

  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

    View Slide

  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

    View Slide

  8. 8
    How do you measure concurrent program execution?
    Profiling Concurrency, August 18, 2011

    View Slide

  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

    View Slide

  10. 10
    FUNCTIONALITY
    What are the results?
    Profiling Concurrency, August 18, 2011

    View Slide

  11. 11
    public class EnhancedSynchronizedList {
    public List list =
    Collections.synchronizedList(new ArrayList());
    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

    View Slide

  12. 12
    public class EnhancedSynchronizedList {
    public List list =
    Collections.synchronizedList(new ArrayList());
    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?

    View Slide

  13. 13
    Start the Profiling
    Profiling Concurrency, August 18, 2011

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  17. 17
    Monitor
    Profiling Concurrency, August 18, 2011

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  21. 21
    Use Case: Extending a Thread-Safe Class
    public class EnhancedSynchronizedList {
    public List list =
    Collections.synchronizedList(new ArrayList());
    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

    View Slide

  22. 22
    Use Case: Extending a Thread-Safe Class
    public class EnhancedSynchronizedList {
    public List list =
    Collections.synchronizedList(new ArrayList());
    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;
    }

    View Slide

  23. 23
    EVALUATION
    How can it be evaluated?
    Profiling Concurrency, August 18, 2011

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  32. 32
    CONCLUSION
    What is the bottom line?
    Profiling Concurrency, August 18, 2011

    View Slide

  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

    View Slide

  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

    View Slide

  35. 35
    Thank you!
    Feel free to clone my project on GitHub:
    https://github.com/platzhirsch/Profiling-Concurrency
    Profiling Concurrency, August 18, 2011

    View Slide