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 full-size 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 full-size 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 full-size 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 full-size slide

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

    View full-size 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 full-size 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 full-size slide

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

    View full-size 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 full-size slide

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

    View full-size 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 full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  17. 17
    Monitor
    Profiling Concurrency, August 18, 2011

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size 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 full-size slide

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

    View full-size 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 full-size 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 full-size 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 full-size 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 full-size 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 full-size 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 full-size 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 full-size 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 full-size slide

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

    View full-size 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 full-size 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 full-size 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 full-size slide