1 / 46

Static Analysis in Search of Performance Anti-Patterns

Static Analysis in Search of Performance Anti-Patterns. Patrycja Wegrzynowicz Founder and CTO, Yonita Inc. Founder and CTO, Yon Labs and Yon Consulting. About me. Past 10+ years of pr ofessional experience as software developer, architect, and head of software R&D

eljah
Télécharger la présentation

Static Analysis in Search of Performance Anti-Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Static Analysis in Search of Performance Anti-Patterns Patrycja Wegrzynowicz Founder and CTO, Yonita Inc. Founder and CTO, Yon Labs and Yon Consulting

  2. About me • Past • 10+ years of professionalexperience as software developer, architect, and head of software R&D • PhD in Computer Science (automated code analysis) • Speaker at JavaOne, JavaZone, ASE, OOPSLA, Jazoon, and others • Present • Founder and CTO of Yonita Inc., Yon Labs, and Yon Consulting • Bridge the gap between the industry and the academia • Future • Who cares? Seize the day!

  3. Agenda • Performance issues • Performance bottlenecks and how to deal with them • Automated code analysis • Semantic code query system • Performance anti-patterns • Code samples • Code queries

  4. Performance Issues

  5. This is Java.

  6. Is Java slow? • On most Intels Java is as fast or faster than C • The Gaia Satellie and Data Processing • William O’Mullane from European Space Astronomy Centre • Jazoon 2010

  7. Limited Resources Locks Pools Application FD Memory OS Threads Network Processors Hardware RAM HD

  8. Sun’s SDK, Arrays.binarySearch, Joshua Bloch

  9. The Way We Write Software • Business Requirements • Technology Stack • Software Teams struts JSP awt GWT Tapestry Swing JSF RMI JNDI JMS EJB JTA JPA iBatis hibernate JDO

  10. Performance Issues • Root causes • Bad architecture, design, or code • Wrong configuration (app/db server, OS, RDBMS) • Rarely insufficient hardware • Bottlenecks usually unnoticed until happen • Special conditions to happen: size of data, number of users • The later discovered the more expensive to solve

  11. Performance Tuning • MIF cycle • Dynamic analysis • Log/traces • Profiles • Environments • Testing • Production

  12. Our Code

  13. A Single Spaghetti is Hard to See

  14. (Anti-)Patterns in Our Spaghetti

  15. Automated Code Performance Tuning + Automated code analysis Definions of performance anti-patterns

  16. Detection of Performance Anti-Patterns • Benefits • Hints on performance on higher level of abstraction (architecture, design, programming constructs) instead of in terms of lower level concepts (CPU usage, memory consumptions etc.) • Supports developers and development phase • Promotes best practices (refactored solutions) • Problems • Lack of formalization, high-level concepts, textual description • Implementation variants • Size of code

  17. Think? Why think! We have computers to do that for us. – Jean Rostand Automated Code Analysis

  18. Semantic Code Query System • Code query systems • Explore relationships among program elements • Structural and call-related predicates • CodeQuest, JQuery • Semantic code query systems • Focus on behavior (in-depth data flow analysis) • Behavioral predicates in addition to structural ones • D-CUBED – my PhD thesis (focus on design patterns) • Yonita – rewrite + queries

  19. How does Yonita work? Bytecode or Sources SQL or Prolog (anti-)patterns bugs vulnerabilities ... Asm/Recoder Parser Query Analyses analyses: structural, call flow, data flow transitive closures Store relational (MySQL) or deductive (XSB) database

  20. Metamodel • Structural elements • Very similar to CodeQuest and Jquery • Statements • Instances • Symbolic instances • Behavioral predicates supporting call and data flows • Output and input values • Assignments

  21. Instances • Null • New • This • Parameter • Exception • Multiple Return Instance This Instance Param Instance Except. Instance New Instance Null Instance Instance Instance … Instance … Instance …

  22. Behavioral Predicates • Calls • makesCallConditionally(Callable, Callable) • makesCallAlways(Callable, Callable) • Input and output values • hasInput(Callable, Instance) • hasInput(Statement, Instance) • hasOutput(Callable, Instance) • hasOutput(Statement, Instance) • Assignments • assigns(Field, Instance)

  23. Running Yonita Prototype • Run Yonita to parse an application • yonita [classes] [libs] –prolog –mysql • MySQL configuration • hibernate.cfg.xml • Run MySQL console and ask queries (SQL) • Prolog configuration • -Dprolog.file=output.P -prolog=output.P • Run XSB Prolog console and ask queries (Prolog) • Yonita on Google App Engine • In progress

  24. Performance Anti-Patterns

  25. Redundant Work – Example 1 (Web)

  26. Redundant Work – Example 1 (Web) • Multiple calls to database (7 calls!) • Multiple security check • Each call to getUser checks permissions • What if getUser were a remote method?!

  27. Redundant Work – Example 2 (agilefant)

  28. Redundant Work – Example 2 (agilefant)

  29. Redundant Work – Example 2 (agilefant – sourceforge project) Thank you hibernate! Open Session in View Session cache

  30. Redundant Work – Example 3 (agilefant) AJAX Calls

  31. Redundant Work – Example 3 (agilefant) AJAX Calls

  32. Redundant Work – Example 3 (agilefant) AJAX Calls

  33. Redundant Work • Description • A time-consuming method is called many times on a single execution path • Consequences • A slower execution time • Refactored solution • Call the heavy method only once and store the result for further re-use Heavy Heavy Heavy

  34. Redundant Work – Code Query redundantWork(X, Heavy) :- // method Heavy called at least twice... method(X), method(Heavy), isHeavy(Heavy), hasChild(X, Invocation1), methodInvocation(Invocation1, Heavy), hasChild(X, Invocation2), methodInvocation(Invocation2, Heavy), // ...with the same parameters setof(I1, (hasInput(Invocation1, newInstance(I1)), All), setof(I2, (hasInput(Invocation2, newInstance(I2)), All). isHeavy(X) :- isWebService(X). isHeavy(X) :- isDatabaseService(X).

  35. Fine Grained Remote Calls • Entity Beans • EJB1 • EJB2 • Remote Calls • Remote calls have significant impact on application performance Bean getX() Client getY() getZ()

  36. One by One Processing – Example 1 • Add users to a group • Performed in the web layer one by one • Multiple calls to the service layer • Multiple loads and updates each in a separate transaction! • Multiple authorization!

  37. One by One Processing – Example 2 • Delete a group • Detach a group from every user in a group one by one

  38. One by One Processing • Description • The objects in a collection are processed one by one and a single processing requires a call to a time-consuming method (e.g. database access, remote call) • Consequences • A significant increase in time with the increase of collection size • Refactored solution • Consider batch processing Heavy Heavy Heavy Heavy

  39. Unused Object – Example (richfaces 3.2.2)

  40. Unused Object • Description • An object created (usually retrieved from a database), passed to further methods (usually a long chain of method calls), and than not used • Consequences • Higher memory consumption that may lead to performance issues • Refactored solution • Create objects only if you need them.

  41. Unused Objects – Hibernate Mapping

  42. Unused Objects - Standard Collection Mapping

  43. Unused Objects - Immutable Collection

  44. Summary • We need to write better code! • Performance anti-patterns • High-level concepts • Many implenentation variants • Static analysis can help in discovery of performance issues • Useful tool but it does not replace a traditional approach to performance tuning (measure, identify, fix)

  45. Contact • Patrycja • patrycja@YonLabs.com • twitter.com/YonLabs • Yonita • http://www.Yonita.com • http://www.YonLabs.com • http://www.YonConsulting.com

More Related