W-JAX Performance Workshop - Database Performance

922 views
891 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
922
On SlideShare
0
From Embeds
0
Number of Embeds
350
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Working with caches
  • Working with caches
  • W-JAX Performance Workshop - Database Performance

    1. 1. Java Enterprise Performance Database Performance
    2. 2. <ul><li>Architectural Considerations </li></ul>
    3. 3. Database Application from 10.000 ft
    4. 4. Database Applicaction X-Rayed
    5. 5. <ul><li>O/R Mapping </li></ul>
    6. 6. Peristence Frameworks <ul><li>Enable </li></ul><ul><ul><li>easy object-oriented access to relational data </li></ul></ul><ul><ul><li>faster development of database-centric applications </li></ul></ul><ul><ul><li>out-of-the-box generic database access logic </li></ul></ul><ul><ul><li>neglecting the complexity of SQL-based database access </li></ul></ul><ul><li>Require </li></ul><ul><ul><li>Deep understanding </li></ul></ul><ul><ul><li>Thorough tuning </li></ul></ul><ul><ul><li>Runtime Analysis </li></ul></ul>
    7. 7. Persistence (JPA) Frameworks <ul><li>Work ID oriented </li></ul><ul><li>Are object based </li></ul><ul><li>Seperate data loading and construction </li></ul><ul><li>Require query/loading tuning </li></ul><ul><li>Provide multi-level caching </li></ul>
    8. 8. Lazy vs. Eager loading Application Database select ... from master select ... from detail select ... from detail select ... from detail Application Database select ... from master, detail where ..
    9. 9. Too many SQL calls (N+1 Query) Application Database select ... where id=1 select ... where id=1 select ... where id=100 <ul><li>O/R Mapper Configuration </li></ul><ul><li>Container managed persistence </li></ul><ul><li>Bad coding practices </li></ul>
    10. 10. <ul><li>Live Demo </li></ul>
    11. 11. <ul><li>Caching </li></ul>
    12. 12. Generic Caching Architecture Persistence Framework JDBC Layer Database Execution Plan Cache Prepared Statement Cache Cross Session Cache Session Caches Query Cache(s)
    13. 13. Caching <ul><li>Avoid unnecessary database access </li></ul><ul><li>Consumes system resources </li></ul><ul><li>Requires good configuration based on usage patterns </li></ul><ul><li>Checklist </li></ul><ul><ul><li>Data is only read or also written </li></ul></ul><ul><ul><li>Data is used at many places in the applications </li></ul></ul><ul><ul><li>Data changes infrequently </li></ul></ul><ul><ul><li>Data is only used in current application </li></ul></ul>
    14. 14. <ul><li>Live Demo </li></ul>
    15. 15. <ul><li>The JDBC Layer </li></ul>
    16. 16. Prepared Statements <ul><li>Can speed up SQL execution </li></ul><ul><li>Execution plan of statement can be cached </li></ul><ul><li>Actual implementation depends on DB driver </li></ul><ul><ul><li>always check impact </li></ul></ul><ul><ul><li>verify your implementation </li></ul></ul><ul><li>Might consume expensive resources (DB cursors) </li></ul><ul><ul><li>use with care </li></ul></ul><ul><ul><li>understand your SQL driver </li></ul></ul>
    17. 17. Connection Pooling Application Database <ul><li>Connection Pools are shared resources </li></ul><ul><li>Scaling depends on actual load </li></ul><ul><li>Wrong scaling may lead to volatile response times </li></ul>
    18. 18. Connection Handling Increased time to connect while DB and app stays stable <ul><li>1 DB connection </li></ul><ul><li>10 DB connections </li></ul><ul><li>1 DB connection 200 ms less connection usage </li></ul>
    19. 19. Query more data then needed Application First Name Last Name Country Mike Tom Frank Sinatra Jones Myers Germany firstname lastname birthdate USA Person Address street streetNo city country Austria Database select * from person, address
    20. 20. Release Connections early Application Connection getConnection() closeConnection() Connection locked Application Connection getConnection() closeConnection() Connection locked Code requiring DB access Code NOT requiring DB access
    21. 21. <ul><li>Problem Patterns </li></ul>
    22. 22. Antipattern – Application vs. Data Design <ul><li>Description </li></ul><ul><li>Application and Database view of application do not match, resulting in bad performance </li></ul><ul><li>Resolution </li></ul><ul><li>Common design session between DBA and application developer </li></ul>
    23. 23. Antipattern – Bulk Operations via Framework <ul><li>Description </li></ul><ul><li>Running bulk operations via O/R mappers consumes massive memory and results in unnecessary database operations </li></ul><ul><li>Resolution </li></ul><ul><li>Direct Maninpulation at SQL level </li></ul>
    24. 24. Antipattern – Wrong Loading Strategy <ul><li>Description </li></ul><ul><li>Wrong usage of lazy and eager loading results in unnecessary database calls . </li></ul><ul><li>Resolution </li></ul><ul><li>Make everything lazy first and define eager fetching based on runtime behaviour </li></ul>
    25. 25. Antipattern – Wrong Caching Strategy <ul><li>Description </li></ul><ul><li>Although caching is used the application is extremely slow and memory consumption is high. </li></ul><ul><li>Resolution </li></ul><ul><li>Verify caching works properly by runtime analysis and tune accordingly </li></ul>
    26. 26. <ul><li>Testing </li></ul>
    27. 27. What to consider during testing <ul><li>Combine read/write queries </li></ul><ul><li>Vary input parameters </li></ul><ul><li>Test in realistic concurrency scenarios </li></ul><ul><li>Test at different load levels </li></ul>
    28. 28. Questions to Answer <ul><li>Prepared Statement Usage </li></ul><ul><li>Duplicate queries </li></ul><ul><li>Long lasting queries </li></ul><ul><li>Queries per use case (transaction) </li></ul><ul><li>Time to get/use connection </li></ul><ul><li>Used access patterns </li></ul>
    29. 29. <ul><li>Monitoring </li></ul><ul><li>& Diagnosis </li></ul>
    30. 30. Statement Statistics are your friend
    31. 31. Monitoring your Connection Pools <ul><li>Used Connections </li></ul><ul><li>Available/Idle Connections </li></ul><ul><li>Connection Wait Time </li></ul><ul><li>Connections created </li></ul><ul><li>Connections destroyed </li></ul>
    32. 32. Monitoring your Cache Usage <ul><li>Cache Hits/Misses </li></ul><ul><li>Cache Size </li></ul><ul><li>In case of problems </li></ul><ul><ul><li>Actual cache requests </li></ul></ul><ul><ul><li>Time between requests for same object </li></ul></ul>
    33. 33. alois.reitbauer@dynatrace.com Mail blog.dynatrace.com Blog AloisReitbauer Twitter

    ×