際際滷

際際滷Share a Scribd company logo
DPC3010 - SQL Server 2012:
Performance Tuning
Methodology
Gianluca
Sartori
MCITP MCTS MCT
Performance Tuning Methodology
 Perch辿 una metodologia?
 Come condurre un Health Check
 Raccolta
 Analisi
 Intervento
 The Performance Cycle
 Replay
 Capture
 Analyze
 Adjust
 SQL Server 竪 un prodotto complesso
 Molte leve su cui agire
 Non c竪 il pulsante 束turbo損 degli anni 90 
 Si rischia di perdersi
 Serve un metodo riproducibile
 Linee guida, ognuno trover il metodo che preferisce
Perch辿 una metodologia?
Health Check
Raccolta Informazioni
 Windows
 Versione
 Dotazione HW
 CPU
 RAM
 Disco
 SQL Server
 Versione
 Parametri di configurazione
 Numero e dimensione dei database
 Distribuzione di data/log files sullo storage
Dati anagrafici del 束paziente損
Raccolta Informazioni
 Wait stats
 Performance counters
 Dynamic Management Views
 Query stats
Quali dati raccogliere?
Raccolta Informazioni
 DMV  sys.dm_os_wait_stats
 Traccia il tempo speso dai processi in attesa di risorse
 Tempi di attesa cumulativi (ultimo riavvio istanza)
 Ottimo punto di partenza per il troubleshooting
 Consente di identificare i problemi dai sintomi
 Mostra quali aree richiedono attenzione
 Non tutte le classi di wait sono significative
Wait Statistics
Raccolta Informazioni
Comuni classi di wait
Risorsa Classe Esempio
Locking LCK_*
LCK_M_S
LCK_M_X
Latching
LATCH_*
PAGELATCH_*
LATCH_EX
PAGELATCH_UP
I/O
PAGEIOLATCH_*
*_COMPLETION
WRITELOG
PAGEIOLATCH_SH
IO_COMPLETION
ASYNC_IO_COMPLETION
CPU
THREADPOOL
SOS_SCHEDULER_YIELD
Network ASYNC_NETWORK_IO
Parallelismo CXPACKET
Raccolta Informazioni
DEMO
Wait Stats
Raccolta Informazioni
 CPU
 Memoria
 Disco
 SQL  specific
 
 Quali contatori?
 In SQL Server 2012 sono 355!
Performance Counters
Raccolta Informazioni
DEMO
Performance Counters
Raccolta Informazioni
 sys.dm_os_... OS information, memory, performance
 sys.dm_io_... Disk performance
 sys.dm_exec_... Sessions, requests, connections
 sys.dm_db Database info
 sys.dm_tran Transactions, locks
 sys.dm_... Audits, broker, CDC, CLR, FileStream,
FTS, HADR, Repl, Resource Governor,
Extended Events
 Non tutte le DMV riguardano le performance
DMVs
Raccolta Informazioni
Quali DMV?
In SQL 2012 sono 141!
SELECT name
,type_desc
FROM sys.all_objects
WHERE name LIKE 'dm[_]%'
ORDER BY name
Raccolta Informazioni
 Glenn Berrys Diagnostic Information Queries
http://sqlserverperformance.wordpress.com/
 Brent Ozars sp_Blitz
http://www.brentozar.com/blitz/
 Davide Mauris SYS2 DMVs
http://sys2dmvs.codeplex.com/
Come orientarsi tra 355 performance counters e 141 DMV?
Raccolta Informazioni
 DMV  sys.dm_exec_query_stats
 Informazioni su tutte le query presenti in plan cache
 Possibile ottenere le query pi湛 costose in termini di:
 IO
 Reads
 Writes
 CPU
 Execution count
 Correlare le wait stats con le query stats
Query Statistics
Raccolta Informazioni
DEMO
Query Stats
Raccolta Informazioni
 Performance Data Collector
 Popola il Management Datawarehouse
 PAL
 Analizza Performance Counters
 Fornisce un template performance monitor
 SQL Trace / Profiler
 Cattura lattivit dellistanza
 SQLDiag / PSSDiag
 Raccoglie counters, DMV, Trace, logs
Strumenti per la raccolta informazioni
Analisi
 Management Datawarehouse
 Contiene informazioni sugli indicatori di performance e lattivit
 PAL
 Produce un report con analisi soglie
 RML Utilities
 ReadTrace produce un database di analisi
 Reporter visualizza e confronta i dati
 SQLNexus
 Analizza i dati raccolti da SQLDiag
 Offre reportistica per lanalisi
Strumenti per lanalisi dei dati raccolti
Analisi
 Best Practices Analyzer
 Controlla la conformit delle Best Practices
 ClearTrace
 束Normalizza損 una traccia
 Analizza il consumo di risorse per query
 CPU
 Reads
 Writes
Altri strumenti di analisi
Analisi
 Riduzione dellutilizzo delle risorse
 Riduzione delle attese
Su quali punti intervenire?
Piano di Intervento
 Elenco dettagliato degli interventi
 Suddividere per area
 Configuration
 Recovery
 Performance
 Concurrency
 Security
 Management
 HA and Replication
 Dare una priorit
 Stimare i tempi di intervento
Lanalisi produce un 束Action Plan損
Piano di Intervento
 Gli interventi devono produrre dei miglioramenti
 Rispetto a cosa?
 Il miglioramento deve essere misurabile
 Rispetto a cosa?
 Non devo introdurre peggioramenti
 Rispetto a cosa?
Il piano deve avere un obiettivo
BASELINE
Baselining
 Non esiste una baseline uguale allaltra!
 Descrive le prestazioni del sistema in condizioni 束normali損
 Servir come termine di confronto
 Monitoring
 Troubleshooting
 Fotografia statica degli indicatori di performance
 Performance Counters
 DMVs
 WAIT_STATS
Che cos竪 una Baseline?
Baselining
 Breve termine
 Servono i dati di dettaglio per il troubleshooting
 ES: valore dei contatori raccolto ogni minuto
retention = 1 mese
 Lungo termine
 Dati aggregati per andamento storico
 ES: valori aggregati (MIN-MAX-AVG) per ogni ora
retention = 
 Organizzare in un DWH
 Posizionare in unistanza non di produzione!
Monitoring Baseline
Baselining
E sufficiente una sola Baseline?
Performance Cycle
Performance Cycle
 Quale strumento?
 SQL Trace vs. Profiler
 Utilizziamo una SQL Trace
 Quali eventi catturare?
 Quali colonne catturare?
 RML Utilities
 Trace definition script
 Backup database
 Prima effettuare il backup, poi avviare la traccia
 Prima avviare la traccia, poi effettuare il backup
 Filtrare la traccia
Capture in produzione
Performance Cycle
 Lambiente di test deve essere un clone completo
 Restore User Databases
 Attenzione agli object_id!
 Logins
 Attenzione agli utenti orfani!
 Job
 Package SSIS / DTS
 Database Mail
 Lambiente di test deve essere isolato dalla produzione!
Preparazione dellambiente di test
Testare le modifiche
 Profiler
 RML Utilities - Ostress
 Distributed Replay
 Novit di SQL Server 2012
 Pu嘆 eseguire un workload da pi湛 client
 Stesso query rate della traccia originale
Workload Replay - quale strumento?
Testare le modifiche
 E composto da tre elementi:
 Administration tool
 Distributed Replay Controller
 Distributed Replay Client
Distributed Replay
Testare le modifiche
Workload Replay - quale strumento?
Profiler Ostress Distributed Replay
Multithreading SI SI SI
Debugging SI NO NO
Synchronization mode NO SI SI
Stress mode SI SI SI
Distributed mode NO NO SI
Input format Trace
Trace
RML
SQL
Trace
Testare le modifiche
 Resettare i performance counters
 DBCC SQLPERF("sys.dm_os_wait_stats",CLEAR);
 DBCC FREEPROCCACHE();
 DBCC FREESYSTEMCACHE('ALL');
 DBCC DROPCLEANBUFFERS();
 Effettuare uno snapshot di ogni database
 Avviare gli strumenti di raccolta prestazioni
 Performance Monitor Collection Set
 SQLTrace  RML Template
Raccolta della Baseline
Testare le modifiche
 Revert snapshot
 Applicare le modifiche
 Avviare gli strumenti di raccolta
 Avviare il replay
 Analizzare i dati raccolti (ReadTrace, PAL)
 Confrontare i dati raccolti con la Baseline
Ripetere per ogni modifica significativa
Raccolta del benchmark
Testare le modifiche
DEMO
Distributed Replay
Deploy in produzione
 Mantenere le modifiche sotto source control
 SQL Server Data Tools (SSDT)
 Database Projects
 Modello dichiarativo del database
 Database compare
 Change script
 Tenere anche i change script sotto source control
 Monitorare le prestazioni in produzione
 Monitoring Baseline
Deploy
Risorse
 PAL
http://pal.codeplex.com/
 RML Utilities
http://support.microsoft.com/kb/944837/en-us
 ClearTrace
http://www.scalesql.com/cleartrace/default.aspx
 SQLNexus
http://sqlnexus.codeplex.com/
Strumenti
Risorse
 Troubleshooting SQL Server
Jonathan Kehayias
Ted Krueger
http://www.simple-talk.com/books/sql-books/troubleshooting-
sql-server-a-guide-for-the-accidental-dba/
Free Ebook
Q&A
Thank you
Con il contributo di
Con il patrocinio di

More Related Content

Viewers also liked (18)

Agile@scale: Portfolio level
Agile@scale: Portfolio levelAgile@scale: Portfolio level
Agile@scale: Portfolio level
Felice Pescatore
Gestione della capacit e forecasting Gandolfo Dominici CDL magistrale scm e ...
Gestione della capacit e forecasting Gandolfo Dominici CDL magistrale scm e ...Gestione della capacit e forecasting Gandolfo Dominici CDL magistrale scm e ...
Gestione della capacit e forecasting Gandolfo Dominici CDL magistrale scm e ...
Gandolfo Dominici
Smau Firenze 2014 - Business Intelligence, Analytics e Big Data: una guida pe...
Smau Firenze 2014 - Business Intelligence, Analytics e Big Data: una guida pe...Smau Firenze 2014 - Business Intelligence, Analytics e Big Data: una guida pe...
Smau Firenze 2014 - Business Intelligence, Analytics e Big Data: una guida pe...
SMAU
Cosa sono le Web Performance e perch辿 dovete preoccuparvene
Cosa sono le Web Performance e perch辿 dovete preoccuparveneCosa sono le Web Performance e perch辿 dovete preoccuparvene
Cosa sono le Web Performance e perch辿 dovete preoccuparvene
Olegs Belousovs
Presentation chingay
Presentation chingayPresentation chingay
Presentation chingay
Toh Zhi Yang
Aarad Homer's Visual Resume
Aarad Homer's Visual ResumeAarad Homer's Visual Resume
Aarad Homer's Visual Resume
Aarad Homer
Travelling and working abroad - Ielts topic -Jen
Travelling and working abroad - Ielts topic -JenTravelling and working abroad - Ielts topic -Jen
Travelling and working abroad - Ielts topic -Jen
Jen Vuhuong
All Aboard LILAC 2016 4 290216
All Aboard LILAC 2016 4 290216All Aboard LILAC 2016 4 290216
All Aboard LILAC 2016 4 290216
Liz Dore
How to have the best Christmas
How to have the best ChristmasHow to have the best Christmas
How to have the best Christmas
Jen Vuhuong
Mae Jamison by Aspen
Mae Jamison by AspenMae Jamison by Aspen
Mae Jamison by Aspen
Jolinspeeps
Expand Your Loft Space
Expand Your Loft Space Expand Your Loft Space
Expand Your Loft Space
Melton Design Build
Exercises to improve your form and protect your calves
Exercises to improve your form and protect your calvesExercises to improve your form and protect your calves
Exercises to improve your form and protect your calves
mclsto
Codflorestal port digitalCodflorestal port digital
Codflorestal port digital
Liliane Almeida
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
Learn Database Design with MySQL - Chapter 3 - My sql storage enginesLearn Database Design with MySQL - Chapter 3 - My sql storage engines
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
Eduonix Learning Solutions
Learn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design processLearn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design process
Eduonix Learning Solutions
Flightof geese
Flightof geeseFlightof geese
Flightof geese
vikas thakur
Agile@scale: Portfolio level
Agile@scale: Portfolio levelAgile@scale: Portfolio level
Agile@scale: Portfolio level
Felice Pescatore
Gestione della capacit e forecasting Gandolfo Dominici CDL magistrale scm e ...
Gestione della capacit e forecasting Gandolfo Dominici CDL magistrale scm e ...Gestione della capacit e forecasting Gandolfo Dominici CDL magistrale scm e ...
Gestione della capacit e forecasting Gandolfo Dominici CDL magistrale scm e ...
Gandolfo Dominici
Smau Firenze 2014 - Business Intelligence, Analytics e Big Data: una guida pe...
Smau Firenze 2014 - Business Intelligence, Analytics e Big Data: una guida pe...Smau Firenze 2014 - Business Intelligence, Analytics e Big Data: una guida pe...
Smau Firenze 2014 - Business Intelligence, Analytics e Big Data: una guida pe...
SMAU
Cosa sono le Web Performance e perch辿 dovete preoccuparvene
Cosa sono le Web Performance e perch辿 dovete preoccuparveneCosa sono le Web Performance e perch辿 dovete preoccuparvene
Cosa sono le Web Performance e perch辿 dovete preoccuparvene
Olegs Belousovs
Presentation chingay
Presentation chingayPresentation chingay
Presentation chingay
Toh Zhi Yang
Aarad Homer's Visual Resume
Aarad Homer's Visual ResumeAarad Homer's Visual Resume
Aarad Homer's Visual Resume
Aarad Homer
Travelling and working abroad - Ielts topic -Jen
Travelling and working abroad - Ielts topic -JenTravelling and working abroad - Ielts topic -Jen
Travelling and working abroad - Ielts topic -Jen
Jen Vuhuong
All Aboard LILAC 2016 4 290216
All Aboard LILAC 2016 4 290216All Aboard LILAC 2016 4 290216
All Aboard LILAC 2016 4 290216
Liz Dore
How to have the best Christmas
How to have the best ChristmasHow to have the best Christmas
How to have the best Christmas
Jen Vuhuong
Mae Jamison by Aspen
Mae Jamison by AspenMae Jamison by Aspen
Mae Jamison by Aspen
Jolinspeeps
Exercises to improve your form and protect your calves
Exercises to improve your form and protect your calvesExercises to improve your form and protect your calves
Exercises to improve your form and protect your calves
mclsto
Codflorestal port digitalCodflorestal port digital
Codflorestal port digital
Liliane Almeida
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
Learn Database Design with MySQL - Chapter 3 - My sql storage enginesLearn Database Design with MySQL - Chapter 3 - My sql storage engines
Learn Database Design with MySQL - Chapter 3 - My sql storage engines
Eduonix Learning Solutions
Learn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design processLearn Database Design with MySQL - Chapter 6 - Database design process
Learn Database Design with MySQL - Chapter 6 - Database design process
Eduonix Learning Solutions

Similar to A performance tuning methodology (20)

SQL Server Workload Profiling
SQL Server Workload ProfilingSQL Server Workload Profiling
SQL Server Workload Profiling
Gianluca Hotz
SQL Server Modern Query Processing
SQL Server Modern Query ProcessingSQL Server Modern Query Processing
SQL Server Modern Query Processing
Gianluca Hotz
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
2014.11.14 Implementare e mantenere un progetto Azure SQL Database2014.11.14 Implementare e mantenere un progetto Azure SQL Database
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
Emanuele Zanchettin
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Meet Magento Italy
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
2014.11.14 Implementare e mantenere un progetto Azure SQL Database2014.11.14 Implementare e mantenere un progetto Azure SQL Database
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
Emanuele Zanchettin
Servizi DBA da remoto
Servizi DBA da remotoServizi DBA da remoto
Servizi DBA da remoto
At Work
SQL Server Health Check: le slide del webinar
SQL Server Health Check: le slide del webinarSQL Server Health Check: le slide del webinar
SQL Server Health Check: le slide del webinar
Datamaze
IMPROVE 4.0
IMPROVE 4.0IMPROVE 4.0
IMPROVE 4.0
nextsrl
Implementare e mantenere un progetto azure sql database v.2
Implementare e mantenere un progetto azure sql database v.2Implementare e mantenere un progetto azure sql database v.2
Implementare e mantenere un progetto azure sql database v.2
Emanuele Zanchettin
Kubernetes as HA time series server, a proposal
Kubernetes as HA time series server, a proposalKubernetes as HA time series server, a proposal
Kubernetes as HA time series server, a proposal
Giuliano Latini
Dab:exporter - Presentazione
Dab:exporter - PresentazioneDab:exporter - Presentazione
Dab:exporter - Presentazione
Mantala
Query Processor & Statistics: A Performance Primer
Query Processor & Statistics: A Performance PrimerQuery Processor & Statistics: A Performance Primer
Query Processor & Statistics: A Performance Primer
Davide Mauri
PASS Virtual Chapter - Unit Testing su SQL Server
PASS Virtual Chapter - Unit Testing su SQL ServerPASS Virtual Chapter - Unit Testing su SQL Server
PASS Virtual Chapter - Unit Testing su SQL Server
Alessandro Alpi
Visual Studio Performance Tools
Visual Studio Performance ToolsVisual Studio Performance Tools
Visual Studio Performance Tools
Andrea Tosato
[ITA] Sql Saturday 355 in Parma - New SQL Server databases under source control
[ITA] Sql Saturday 355 in Parma - New SQL Server databases under source control[ITA] Sql Saturday 355 in Parma - New SQL Server databases under source control
[ITA] Sql Saturday 355 in Parma - New SQL Server databases under source control
Alessandro Alpi
Application insights - Power is nothing without control
Application insights - Power is nothing without controlApplication insights - Power is nothing without control
Application insights - Power is nothing without control
Roberto Albano
Best Practices on SQL Server
Best Practices on SQL ServerBest Practices on SQL Server
Best Practices on SQL Server
Gianluca Hotz
Quanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless SynapseQuanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless Synapse
Marco Pozzan
Guida esame 70 462 administering sql server 2012
Guida esame 70 462 administering sql server 2012Guida esame 70 462 administering sql server 2012
Guida esame 70 462 administering sql server 2012
Sebastiano Della Puppa
Bpr group - Case history: database tempi standard e preventivatore
Bpr group - Case history: database tempi standard e preventivatoreBpr group - Case history: database tempi standard e preventivatore
Bpr group - Case history: database tempi standard e preventivatore
BPR Group
SQL Server Workload Profiling
SQL Server Workload ProfilingSQL Server Workload Profiling
SQL Server Workload Profiling
Gianluca Hotz
SQL Server Modern Query Processing
SQL Server Modern Query ProcessingSQL Server Modern Query Processing
SQL Server Modern Query Processing
Gianluca Hotz
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
2014.11.14 Implementare e mantenere un progetto Azure SQL Database2014.11.14 Implementare e mantenere un progetto Azure SQL Database
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
Emanuele Zanchettin
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Marco Zani: Come dimensionare Magento per raggiungere i Key Performance Indic...
Meet Magento Italy
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
2014.11.14 Implementare e mantenere un progetto Azure SQL Database2014.11.14 Implementare e mantenere un progetto Azure SQL Database
2014.11.14 Implementare e mantenere un progetto Azure SQL Database
Emanuele Zanchettin
Servizi DBA da remoto
Servizi DBA da remotoServizi DBA da remoto
Servizi DBA da remoto
At Work
SQL Server Health Check: le slide del webinar
SQL Server Health Check: le slide del webinarSQL Server Health Check: le slide del webinar
SQL Server Health Check: le slide del webinar
Datamaze
IMPROVE 4.0
IMPROVE 4.0IMPROVE 4.0
IMPROVE 4.0
nextsrl
Implementare e mantenere un progetto azure sql database v.2
Implementare e mantenere un progetto azure sql database v.2Implementare e mantenere un progetto azure sql database v.2
Implementare e mantenere un progetto azure sql database v.2
Emanuele Zanchettin
Kubernetes as HA time series server, a proposal
Kubernetes as HA time series server, a proposalKubernetes as HA time series server, a proposal
Kubernetes as HA time series server, a proposal
Giuliano Latini
Dab:exporter - Presentazione
Dab:exporter - PresentazioneDab:exporter - Presentazione
Dab:exporter - Presentazione
Mantala
Query Processor & Statistics: A Performance Primer
Query Processor & Statistics: A Performance PrimerQuery Processor & Statistics: A Performance Primer
Query Processor & Statistics: A Performance Primer
Davide Mauri
PASS Virtual Chapter - Unit Testing su SQL Server
PASS Virtual Chapter - Unit Testing su SQL ServerPASS Virtual Chapter - Unit Testing su SQL Server
PASS Virtual Chapter - Unit Testing su SQL Server
Alessandro Alpi
Visual Studio Performance Tools
Visual Studio Performance ToolsVisual Studio Performance Tools
Visual Studio Performance Tools
Andrea Tosato
[ITA] Sql Saturday 355 in Parma - New SQL Server databases under source control
[ITA] Sql Saturday 355 in Parma - New SQL Server databases under source control[ITA] Sql Saturday 355 in Parma - New SQL Server databases under source control
[ITA] Sql Saturday 355 in Parma - New SQL Server databases under source control
Alessandro Alpi
Application insights - Power is nothing without control
Application insights - Power is nothing without controlApplication insights - Power is nothing without control
Application insights - Power is nothing without control
Roberto Albano
Best Practices on SQL Server
Best Practices on SQL ServerBest Practices on SQL Server
Best Practices on SQL Server
Gianluca Hotz
Quanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless SynapseQuanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless Synapse
Marco Pozzan
Guida esame 70 462 administering sql server 2012
Guida esame 70 462 administering sql server 2012Guida esame 70 462 administering sql server 2012
Guida esame 70 462 administering sql server 2012
Sebastiano Della Puppa
Bpr group - Case history: database tempi standard e preventivatore
Bpr group - Case history: database tempi standard e preventivatoreBpr group - Case history: database tempi standard e preventivatore
Bpr group - Case history: database tempi standard e preventivatore
BPR Group

More from Gianluca Sartori (8)

Benchmarking like a pro
Benchmarking like a proBenchmarking like a pro
Benchmarking like a pro
Gianluca Sartori
Sql server infernals
Sql server infernalsSql server infernals
Sql server infernals
Gianluca Sartori
SQL Server 2016 New Security Features
SQL Server 2016 New Security FeaturesSQL Server 2016 New Security Features
SQL Server 2016 New Security Features
Gianluca Sartori
Responding to extended events in near real time
Responding to extended events in near real timeResponding to extended events in near real time
Responding to extended events in near real time
Gianluca Sartori
Sql server security in an insecure world
Sql server security in an insecure worldSql server security in an insecure world
Sql server security in an insecure world
Gianluca Sartori
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - EN
Gianluca Sartori
TSQL Advanced Query Techniques
TSQL Advanced Query TechniquesTSQL Advanced Query Techniques
TSQL Advanced Query Techniques
Gianluca Sartori
My Query is slow, now what?
My Query is slow, now what?My Query is slow, now what?
My Query is slow, now what?
Gianluca Sartori
Benchmarking like a pro
Benchmarking like a proBenchmarking like a pro
Benchmarking like a pro
Gianluca Sartori
SQL Server 2016 New Security Features
SQL Server 2016 New Security FeaturesSQL Server 2016 New Security Features
SQL Server 2016 New Security Features
Gianluca Sartori
Responding to extended events in near real time
Responding to extended events in near real timeResponding to extended events in near real time
Responding to extended events in near real time
Gianluca Sartori
Sql server security in an insecure world
Sql server security in an insecure worldSql server security in an insecure world
Sql server security in an insecure world
Gianluca Sartori
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - EN
Gianluca Sartori
TSQL Advanced Query Techniques
TSQL Advanced Query TechniquesTSQL Advanced Query Techniques
TSQL Advanced Query Techniques
Gianluca Sartori
My Query is slow, now what?
My Query is slow, now what?My Query is slow, now what?
My Query is slow, now what?
Gianluca Sartori

A performance tuning methodology

  • 1. DPC3010 - SQL Server 2012: Performance Tuning Methodology Gianluca Sartori MCITP MCTS MCT
  • 2. Performance Tuning Methodology Perch辿 una metodologia? Come condurre un Health Check Raccolta Analisi Intervento The Performance Cycle Replay Capture Analyze Adjust
  • 3. SQL Server 竪 un prodotto complesso Molte leve su cui agire Non c竪 il pulsante 束turbo損 degli anni 90 Si rischia di perdersi Serve un metodo riproducibile Linee guida, ognuno trover il metodo che preferisce Perch辿 una metodologia?
  • 5. Raccolta Informazioni Windows Versione Dotazione HW CPU RAM Disco SQL Server Versione Parametri di configurazione Numero e dimensione dei database Distribuzione di data/log files sullo storage Dati anagrafici del 束paziente損
  • 6. Raccolta Informazioni Wait stats Performance counters Dynamic Management Views Query stats Quali dati raccogliere?
  • 7. Raccolta Informazioni DMV sys.dm_os_wait_stats Traccia il tempo speso dai processi in attesa di risorse Tempi di attesa cumulativi (ultimo riavvio istanza) Ottimo punto di partenza per il troubleshooting Consente di identificare i problemi dai sintomi Mostra quali aree richiedono attenzione Non tutte le classi di wait sono significative Wait Statistics
  • 8. Raccolta Informazioni Comuni classi di wait Risorsa Classe Esempio Locking LCK_* LCK_M_S LCK_M_X Latching LATCH_* PAGELATCH_* LATCH_EX PAGELATCH_UP I/O PAGEIOLATCH_* *_COMPLETION WRITELOG PAGEIOLATCH_SH IO_COMPLETION ASYNC_IO_COMPLETION CPU THREADPOOL SOS_SCHEDULER_YIELD Network ASYNC_NETWORK_IO Parallelismo CXPACKET
  • 10. Raccolta Informazioni CPU Memoria Disco SQL specific Quali contatori? In SQL Server 2012 sono 355! Performance Counters
  • 12. Raccolta Informazioni sys.dm_os_... OS information, memory, performance sys.dm_io_... Disk performance sys.dm_exec_... Sessions, requests, connections sys.dm_db Database info sys.dm_tran Transactions, locks sys.dm_... Audits, broker, CDC, CLR, FileStream, FTS, HADR, Repl, Resource Governor, Extended Events Non tutte le DMV riguardano le performance DMVs
  • 13. Raccolta Informazioni Quali DMV? In SQL 2012 sono 141! SELECT name ,type_desc FROM sys.all_objects WHERE name LIKE 'dm[_]%' ORDER BY name
  • 14. Raccolta Informazioni Glenn Berrys Diagnostic Information Queries http://sqlserverperformance.wordpress.com/ Brent Ozars sp_Blitz http://www.brentozar.com/blitz/ Davide Mauris SYS2 DMVs http://sys2dmvs.codeplex.com/ Come orientarsi tra 355 performance counters e 141 DMV?
  • 15. Raccolta Informazioni DMV sys.dm_exec_query_stats Informazioni su tutte le query presenti in plan cache Possibile ottenere le query pi湛 costose in termini di: IO Reads Writes CPU Execution count Correlare le wait stats con le query stats Query Statistics
  • 17. Raccolta Informazioni Performance Data Collector Popola il Management Datawarehouse PAL Analizza Performance Counters Fornisce un template performance monitor SQL Trace / Profiler Cattura lattivit dellistanza SQLDiag / PSSDiag Raccoglie counters, DMV, Trace, logs Strumenti per la raccolta informazioni
  • 18. Analisi Management Datawarehouse Contiene informazioni sugli indicatori di performance e lattivit PAL Produce un report con analisi soglie RML Utilities ReadTrace produce un database di analisi Reporter visualizza e confronta i dati SQLNexus Analizza i dati raccolti da SQLDiag Offre reportistica per lanalisi Strumenti per lanalisi dei dati raccolti
  • 19. Analisi Best Practices Analyzer Controlla la conformit delle Best Practices ClearTrace 束Normalizza損 una traccia Analizza il consumo di risorse per query CPU Reads Writes Altri strumenti di analisi
  • 20. Analisi Riduzione dellutilizzo delle risorse Riduzione delle attese Su quali punti intervenire?
  • 21. Piano di Intervento Elenco dettagliato degli interventi Suddividere per area Configuration Recovery Performance Concurrency Security Management HA and Replication Dare una priorit Stimare i tempi di intervento Lanalisi produce un 束Action Plan損
  • 22. Piano di Intervento Gli interventi devono produrre dei miglioramenti Rispetto a cosa? Il miglioramento deve essere misurabile Rispetto a cosa? Non devo introdurre peggioramenti Rispetto a cosa? Il piano deve avere un obiettivo BASELINE
  • 23. Baselining Non esiste una baseline uguale allaltra! Descrive le prestazioni del sistema in condizioni 束normali損 Servir come termine di confronto Monitoring Troubleshooting Fotografia statica degli indicatori di performance Performance Counters DMVs WAIT_STATS Che cos竪 una Baseline?
  • 24. Baselining Breve termine Servono i dati di dettaglio per il troubleshooting ES: valore dei contatori raccolto ogni minuto retention = 1 mese Lungo termine Dati aggregati per andamento storico ES: valori aggregati (MIN-MAX-AVG) per ogni ora retention = Organizzare in un DWH Posizionare in unistanza non di produzione! Monitoring Baseline
  • 27. Performance Cycle Quale strumento? SQL Trace vs. Profiler Utilizziamo una SQL Trace Quali eventi catturare? Quali colonne catturare? RML Utilities Trace definition script Backup database Prima effettuare il backup, poi avviare la traccia Prima avviare la traccia, poi effettuare il backup Filtrare la traccia Capture in produzione
  • 28. Performance Cycle Lambiente di test deve essere un clone completo Restore User Databases Attenzione agli object_id! Logins Attenzione agli utenti orfani! Job Package SSIS / DTS Database Mail Lambiente di test deve essere isolato dalla produzione! Preparazione dellambiente di test
  • 29. Testare le modifiche Profiler RML Utilities - Ostress Distributed Replay Novit di SQL Server 2012 Pu嘆 eseguire un workload da pi湛 client Stesso query rate della traccia originale Workload Replay - quale strumento?
  • 30. Testare le modifiche E composto da tre elementi: Administration tool Distributed Replay Controller Distributed Replay Client Distributed Replay
  • 31. Testare le modifiche Workload Replay - quale strumento? Profiler Ostress Distributed Replay Multithreading SI SI SI Debugging SI NO NO Synchronization mode NO SI SI Stress mode SI SI SI Distributed mode NO NO SI Input format Trace Trace RML SQL Trace
  • 32. Testare le modifiche Resettare i performance counters DBCC SQLPERF("sys.dm_os_wait_stats",CLEAR); DBCC FREEPROCCACHE(); DBCC FREESYSTEMCACHE('ALL'); DBCC DROPCLEANBUFFERS(); Effettuare uno snapshot di ogni database Avviare gli strumenti di raccolta prestazioni Performance Monitor Collection Set SQLTrace RML Template Raccolta della Baseline
  • 33. Testare le modifiche Revert snapshot Applicare le modifiche Avviare gli strumenti di raccolta Avviare il replay Analizzare i dati raccolti (ReadTrace, PAL) Confrontare i dati raccolti con la Baseline Ripetere per ogni modifica significativa Raccolta del benchmark
  • 35. Deploy in produzione Mantenere le modifiche sotto source control SQL Server Data Tools (SSDT) Database Projects Modello dichiarativo del database Database compare Change script Tenere anche i change script sotto source control Monitorare le prestazioni in produzione Monitoring Baseline Deploy
  • 36. Risorse PAL http://pal.codeplex.com/ RML Utilities http://support.microsoft.com/kb/944837/en-us ClearTrace http://www.scalesql.com/cleartrace/default.aspx SQLNexus http://sqlnexus.codeplex.com/ Strumenti
  • 37. Risorse Troubleshooting SQL Server Jonathan Kehayias Ted Krueger http://www.simple-talk.com/books/sql-books/troubleshooting- sql-server-a-guide-for-the-accidental-dba/ Free Ebook
  • 38. Q&A
  • 40. Con il contributo di Con il patrocinio di