O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

How to Troubleshoot & Optimize Database Query Performance for Your Application

How to Troubleshoot & Optimize Database Query Performance for Your Application

According to the recent DZone Performance Guide, “database performance problems are the most challenging to fix” with manual firefighting and lack of actionable insights being the top monitoring challenges. When these three issues converge on your application delivery chain it can mean a long time and a lot of effort to find and fix critical issues.

Is it really your database that's slow? Or is it the way your OR-Mapper or code accesses the database? A misconfigured connection pool on one of your servers? Or a missing table index, a full tablespace, or simply an I/O issue?

In this webinar we show you how Dynatrace AppMon extends traditional APM through its new Database Agent, providing a view that both Developers and DBAs can trust and use to identify:

• Problematic SQL Queries, unprepared statements or misconfigured connection pools
• Performance impacting database sessions, slow queries, waits and locks on your database instances
• Optimizations by looking at the Execution Plans of your application-specific SQL queries
• Query patterns like n+1 being implemented in your application

Eliminate wasted cycles by bridging the Dev-DBA collaboration gap with a consistent view based on app-focused database access metrics, database instance system and performance metrics, and execution plans for your critical SQL queries. Buck the trends that DZone is seeing! Get tips you can use right away.

  • Entre para ver os comentários

How to Troubleshoot & Optimize Database Query Performance for Your Application

  1. 1. Confidential, Dynatrace, LLC Asad Ali Director, Product Specialist @AsadThoughts Dynatrace How to Troubleshoot & Optimize Database Query Performance for Your Application
  2. 2. Let the blame game start! Web Server Application Server Database DEV Team DBA Team Blame the database for all performance issues Blame the SW/HW or system administrators Network?
  3. 3. Database Heavy: 66.51% (40.27s) Time Spent in SQL Execs
  4. 4. Excessive SQL: 24889! Calls to Database Database Heavy: 66.51% (40.27s) Time Spent in SQL Execs
  5. 5. Database Performance hotspots Application Design DB Design DB Queries Server/Infrastructure
  6. 6. Database Performance Hotspots Application Design Database Infrastructure Application
  7. 7. of database performance issues can be solved by developers70%
  8. 8. Database Performance Hotspots • Lack of use of bind values • Too many SQL statements per user action • Database server overloaded • DB connection pool monitoring
  9. 9. Example 1: performance tuning by using bind variables
  10. 10. Oracle SQL Cache <?php $db = new PDO('oci:dbname=sid', 'username', 'password'); $data = Array(); $data[] = $db->query("select * from country where code = 'AT'"); $data[] = $db->query("select * from country where code = 'AU'"); $data[] = $db->query("select * from country where code = 'NZ'"); $data[] = $db->query("select * from country where code = 'ES'"); ?>
  11. 11. Query Plan Evaluation
  12. 12. MSSQL Cache
  13. 13. MSSQL Cache
  14. 14. Little Bobby Tables addStudentInfo(String lname, String fname) { String query = “insert into Student(last_name, first_name) values (‘”+lname + ”’, ‘” + fname + “’)”; } Normal Operation: First Name: Asad Last Name : Ali insert into Student (‘Ali’, ‘Asad’) Malicious Operation: First Name: Asad’); Drop table Student; Last Name : Ali insert into Student (‘Ali’, ‘Asad’); Drop table Student
  15. 15. Little Bobby Tables
  16. 16. Oracle SQL Cache <?php $db = new PDO('oci:dbname=sid', 'username', 'password'); $data = Array(); $ps = $db->prepare("select * from country where code = :code"); $data[] = $ps->execute(array("code" => "AT")); $data[] = $ps->execute(array("code" => "AU")); $data[] = $ps->execute(array("code" => "NZ")); $data[] = $ps->execute(array("code" => "ES")); ?>
  17. 17. Example 2: application performing too many SQL statements
  18. 18. Excessive SQL: 24889! Calls to Database Database Heavy: 66.51% (40.27s) Time Spent in SQL Execs
  19. 19. Why are there so many SQL statements? $schools = new SchoolEntities(); foreach ($schools as $school) { foreach ($school->departments as $department) { foreach ($department->courses as $course) { echo $department->name . ": " . $course->title); } } }
  20. 20. N+1 problem • 10 schools • 20 departments per school • 50 courses per department => 10 x 20 x 50 = 10001 single database statements !!!
  21. 21. Retrieving too many records $schools = new SchoolEntities(); foreach ($schools->departments as $department) { foreach ($department->courses as $course) { if ($course->category == "SQL" && $course->level == "expert")) { echo $department->name . ": " . $course->title); } } } => 3 records, still 10001 queries
  22. 22. Solution: use a JOIN query with a WHERE clause $rows = $db->query (" select department.name as department, course.title as course from school join department on school_id = school.id join course on department_id = department.id where course.category = 'SQL' and course.level = 'expert' "); foreach ($rows as $row) { echo $department . ": " . $course); } => ONE database statement !!!
  23. 23. Example 3: overloaded database server
  24. 24. Major database performance problem
  25. 25. Example 4: database connection pool settings
  26. 26. Database Connection Pool
  27. 27. Database Connection Pool
  28. 28. Database Connection Pool
  29. 29. Auto DB Pattern Detection
  30. 30. Live Demo
  31. 31. Q & A @AsadThoughts
  32. 32. Performance Tuning – best practices • Use bind variables to leverage SQL caching • Use join queries to avoid N+1 problems • Avoid index killers in queries • Use stored procedures for complex functionality • Leverage connection pooling • Watch for other processes / application on your database http://apmblog.dynatrace.com/2016/05/23/improve-oracle-database-performance-using-bind-variables/ https://www.infoq.com/articles/Diagnose-Microservice-Performance-Anti-Patterns

×