Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Why my query is slow and how to fix this
t WITH PASSION TO TECHNOLOGY
Denis Reznik
.NET CONFERENCE #1 IN UKRAINE, KYIV 2018
t .NET LEVEL UP
KYIV 2018
About Me
• Denis Reznik
• Kyiv, Ukraine
• Data Architect at Intapp, Inc.
• Microsoft Data Platfo...
t .NET LEVEL UP
KYIV 2018
Agenda
• Query Execution Time
• Slow Queries
• Optimization Algorithm
• First-Level Root Cause(s...
t .NET LEVEL UP
KYIV 2018
Query Execution Time
Duration (Elapsed Time)
CPU (CPU Time) Wait (Wait Time)
Query Execution
Thread Pool
Running
Suspended
Runnable
Sleeping
Scheduler
Logical CPU
Worker (Thread)
Connection
CPU – Cooperative Multitasking
0
CPUsQueries
1
2
3
Time Quantum Length for each Scheduler is 4 ms
Тема доклада
Тема доклада
Тема доклада
KYIV 2018
High CPU – High Duration
.NET CONFERENCE #1 IN UKRAINE
Demo
Тема доклада
Тема доклада
Тема доклада
KYIV 2018
Various Waits
.NET CONFERENCE #1 IN UKRAINE
Waits
SOS_SCHEDULER_YIELD Wait
0
SchedulersRunnable Queue
1
2
3
Suspended Queue
Time Quantum Length for each Scheduler is 4 ms
LCK_M_* Waits
0
SchedulersRunnable Queue
1
2 1
Suspended Queue
2
SELECT * FROM Users
WHERE Name LIKE 'K%'
UPDATE Users
SET...
PAGEIOLATCH_* Waits
0
SchedulersRunnable Queue
1
2
3
1
Suspended Queue
1
SELECT * FROM Users
WHERE Name LIKE 'P%'
1
1
PAGE...
ASYNC_NETWORK_IO Wait
0
SchedulersRunnable Queue
1
2
3
1
Suspended Queue
1
SELECT * FROM Users1
1
ASYNC_NETWORK_IO
ASYNC_N...
CX_PACKET
Thread 1
Thread 2
Thread 3
Thread 4
1s2s
Thread 0CXPACKET WaitCXPACKET Wait
CXPACKET Wait
CXPACKET Wait
CXPACKET...
THREADPOOL Wait
Runnable Queue
Suspended Queue
Thread Pool
Connection
Тема доклада
Тема доклада
Тема доклада
KYIV 2018
Low CPU – High Duration
.NET CONFERENCE #1 IN UKRAINE
Demo
Тема доклада
Тема доклада
Тема доклада
KYIV 2018
High CPU – Low Duration
.NET CONFERENCE #1 IN UKRAINE
Demo
Тема доклада
Тема доклада
Тема доклада
KYIV 2018
High CPU – High Duration
.NET CONFERENCE #1 IN UKRAINE
Demo
t .NET LEVEL UP
KYIV 2018
Summary
• Query Execution Time
• Slow Queries
• Optimization Algorithm
• First-Level Root Cause(...
Тема доклада
Тема доклада
Тема доклада
KYIV 2018
.NET LEVEL UP
.NET CONFERENCE #1 IN UKRAINE
Denis Reznik
Twitter: @denisr...
Nächste SlideShare
Wird geladen in …5
×

.NET Fest 2018. Денис Резник. Почему мой запрос тормозит и как это исправить

200 Aufrufe

Veröffentlicht am

По большому счёту, вариантов почему запрос работает медленно всего два: или запрос сам по себе работает долго (CPU Time) или ждёт определённого ресурса (Wait Time). Все остальные причины медленной работы запросов являются производными этих двух вариантов. В ходе доклада мы научимся чётко определять, что является причиной долгой работы запроса, посмотрим чего может запрос ждать и как можно его ускорить

Veröffentlicht in: Bildung
  • Login to see the comments

.NET Fest 2018. Денис Резник. Почему мой запрос тормозит и как это исправить

  1. 1. Why my query is slow and how to fix this t WITH PASSION TO TECHNOLOGY Denis Reznik .NET CONFERENCE #1 IN UKRAINE, KYIV 2018
  2. 2. t .NET LEVEL UP KYIV 2018 About Me • Denis Reznik • Kyiv, Ukraine • Data Architect at Intapp, Inc. • Microsoft Data Platform MVP • Co-Founder of Ukrainian Data Community Kyiv • PASS Regional Mentor, CEE • Co-author of “SQL Server MVP Deep Dives 2”
  3. 3. t .NET LEVEL UP KYIV 2018 Agenda • Query Execution Time • Slow Queries • Optimization Algorithm • First-Level Root Cause(s) • Second-Level Root Cause(s) • Query/Server/Database/Application Optimization
  4. 4. t .NET LEVEL UP KYIV 2018 Query Execution Time Duration (Elapsed Time) CPU (CPU Time) Wait (Wait Time)
  5. 5. Query Execution Thread Pool Running Suspended Runnable Sleeping Scheduler Logical CPU Worker (Thread) Connection
  6. 6. CPU – Cooperative Multitasking 0 CPUsQueries 1 2 3 Time Quantum Length for each Scheduler is 4 ms
  7. 7. Тема доклада Тема доклада Тема доклада KYIV 2018 High CPU – High Duration .NET CONFERENCE #1 IN UKRAINE Demo
  8. 8. Тема доклада Тема доклада Тема доклада KYIV 2018 Various Waits .NET CONFERENCE #1 IN UKRAINE Waits
  9. 9. SOS_SCHEDULER_YIELD Wait 0 SchedulersRunnable Queue 1 2 3 Suspended Queue Time Quantum Length for each Scheduler is 4 ms
  10. 10. LCK_M_* Waits 0 SchedulersRunnable Queue 1 2 1 Suspended Queue 2 SELECT * FROM Users WHERE Name LIKE 'K%' UPDATE Users SET Name = 'Jesse Pinkman' WHERE Id = 3 Id Name 1 John Snow 2 Peter Partner 3 Kirill Nenahov 4 Jane Dow 1 Users 2 3 2 Id Name 1 John Snow 2 Peter Partner 3 Jesse Pinkman 4 Jane Dow LCK_M_X LCK_M_X 2 X S
  11. 11. PAGEIOLATCH_* Waits 0 SchedulersRunnable Queue 1 2 3 1 Suspended Queue 1 SELECT * FROM Users WHERE Name LIKE 'P%' 1 1 PAGEIOLATCH_SH PAGEIOLATCH_SH 1 Buffer Pool Database File … A .. Z A .. C C .. Q X .. Z Non-Clustered Index (Name) ?
  12. 12. ASYNC_NETWORK_IO Wait 0 SchedulersRunnable Queue 1 2 3 1 Suspended Queue 1 SELECT * FROM Users1 1 ASYNC_NETWORK_IO ASYNC_NETWORK_IO 1 Client Id Name 1 John Snow 2 Darth Vader 3 Peter Parker 4 Andriy Yarmolenko Users var command = new SqlCommand("SELECT * FROM Users", connection); connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { // Do some logic (e.g. Thread.Sleep(1000); ) }
  13. 13. CX_PACKET Thread 1 Thread 2 Thread 3 Thread 4 1s2s Thread 0CXPACKET WaitCXPACKET Wait CXPACKET Wait CXPACKET Wait CXPACKET Wait
  14. 14. THREADPOOL Wait Runnable Queue Suspended Queue Thread Pool Connection
  15. 15. Тема доклада Тема доклада Тема доклада KYIV 2018 Low CPU – High Duration .NET CONFERENCE #1 IN UKRAINE Demo
  16. 16. Тема доклада Тема доклада Тема доклада KYIV 2018 High CPU – Low Duration .NET CONFERENCE #1 IN UKRAINE Demo
  17. 17. Тема доклада Тема доклада Тема доклада KYIV 2018 High CPU – High Duration .NET CONFERENCE #1 IN UKRAINE Demo
  18. 18. t .NET LEVEL UP KYIV 2018 Summary • Query Execution Time • Slow Queries • Optimization Algorithm • First-Level Root Cause(s) • Second-Level Root Cause(s) • Query/Server/Database/Application Optimization
  19. 19. Тема доклада Тема доклада Тема доклада KYIV 2018 .NET LEVEL UP .NET CONFERENCE #1 IN UKRAINE Denis Reznik Twitter: @denisreznik Email: denisreznik@gmail.com Blog: http://reznik.uneta.com.ua Facebook: https://www.facebook.com/denis.reznik.5 LinkedIn: http://ua.linkedin.com/pub/denis-reznik/3/502/234 Thank You!

×