SlideShare uma empresa Scribd logo
1 de 40
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 Berry’s Diagnostic Information Queries
http://sqlserverperformance.wordpress.com/
• Brent Ozar’s sp_Blitz
http://www.brentozar.com/blitz/
• Davide Mauri’s 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 l’attività dell’istanza
• SQLDiag / PSSDiag
– Raccoglie counters, DMV, Trace, logs…
Strumenti per la raccolta informazioni
Analisi
• Management Datawarehouse
– Contiene informazioni sugli indicatori di performance e l’attività
• 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 l’analisi
Strumenti per l’analisi 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 dell’utilizzo 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
L’analisi 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 all’altra!
• 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 un’istanza 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
• L’ambiente 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
• L’ambiente di test deve essere isolato dalla produzione!
Preparazione dell’ambiente 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

Mais conteúdo relacionado

Destaque

Agile@scale: Portfolio level
Agile@scale: Portfolio levelAgile@scale: Portfolio level
Agile@scale: Portfolio levelFelice 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 preoccuparveneOlegs Belousovs
 
Presentation chingay
Presentation chingayPresentation chingay
Presentation chingayToh Zhi Yang
 
Aarad Homer's Visual Resume
Aarad Homer's Visual ResumeAarad Homer's Visual Resume
Aarad Homer's Visual ResumeAarad 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 -JenJen Vuhuong
 
All Aboard LILAC 2016 4 290216
All Aboard LILAC 2016 4 290216All Aboard LILAC 2016 4 290216
All Aboard LILAC 2016 4 290216Liz Dore
 
How to have the best Christmas
How to have the best ChristmasHow to have the best Christmas
How to have the best ChristmasJen Vuhuong
 
Mae Jamison by Aspen
Mae Jamison by AspenMae Jamison by Aspen
Mae Jamison by AspenJolinspeeps
 
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 calvesmclsto
 
Codflorestal port digital
Codflorestal port digitalCodflorestal port digital
Codflorestal port digitalLiliane 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 enginesEduonix 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 processEduonix Learning Solutions
 

Destaque (18)

Agile@scale: Portfolio level
Agile@scale: Portfolio levelAgile@scale: Portfolio level
Agile@scale: Portfolio level
 
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 ...
 
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...
 
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
 
Presentation chingay
Presentation chingayPresentation chingay
Presentation chingay
 
sample
samplesample
sample
 
Aarad Homer's Visual Resume
Aarad Homer's Visual ResumeAarad Homer's Visual Resume
Aarad Homer's Visual Resume
 
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
 
All Aboard LILAC 2016 4 290216
All Aboard LILAC 2016 4 290216All Aboard LILAC 2016 4 290216
All Aboard LILAC 2016 4 290216
 
How to have the best Christmas
How to have the best ChristmasHow to have the best Christmas
How to have the best Christmas
 
Mae Jamison by Aspen
Mae Jamison by AspenMae Jamison by Aspen
Mae Jamison by Aspen
 
Expand Your Loft Space
Expand Your Loft Space Expand Your Loft Space
Expand Your Loft Space
 
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
 
นักพัฒ
นักพัฒนักพัฒ
นักพัฒ
 
Codflorestal port digital
Codflorestal port digitalCodflorestal port digital
Codflorestal port digital
 
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
 
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
 
Flightof geese
Flightof geeseFlightof geese
Flightof geese
 

Semelhante a A performance tuning methodology

SQL Server Workload Profiling
SQL Server Workload ProfilingSQL Server Workload Profiling
SQL Server Workload ProfilingGianluca Hotz
 
SQL Server Modern Query Processing
SQL Server Modern Query ProcessingSQL Server Modern Query Processing
SQL Server Modern Query ProcessingGianluca 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 DatabaseEmanuele 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 DatabaseEmanuele Zanchettin
 
Servizi DBA da remoto
Servizi DBA da remotoServizi DBA da remoto
Servizi DBA da remotoAt 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 webinarDatamaze
 
IMPROVE 4.0
IMPROVE 4.0IMPROVE 4.0
IMPROVE 4.0nextsrl
 
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.2Emanuele 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 proposalGiuliano Latini
 
Dab:exporter - Presentazione
Dab:exporter - PresentazioneDab:exporter - Presentazione
Dab:exporter - PresentazioneMantala
 
Query Processor & Statistics: A Performance Primer
Query Processor & Statistics: A Performance PrimerQuery Processor & Statistics: A Performance Primer
Query Processor & Statistics: A Performance PrimerDavide 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 ServerAlessandro Alpi
 
Visual Studio Performance Tools
Visual Studio Performance ToolsVisual Studio Performance Tools
Visual Studio Performance ToolsAndrea 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 controlAlessandro 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 controlRoberto Albano
 
Best Practices on SQL Server
Best Practices on SQL ServerBest Practices on SQL Server
Best Practices on SQL ServerGianluca 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 SynapseMarco 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 2012Sebastiano 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 preventivatoreBPR Group
 

Semelhante a A performance tuning methodology (20)

SQL Server Workload Profiling
SQL Server Workload ProfilingSQL Server Workload Profiling
SQL Server Workload Profiling
 
SQL Server Modern Query Processing
SQL Server Modern Query ProcessingSQL Server Modern Query Processing
SQL Server Modern Query Processing
 
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
 
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...
 
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
 
Servizi DBA da remoto
Servizi DBA da remotoServizi DBA da remoto
Servizi DBA da remoto
 
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
 
IMPROVE 4.0
IMPROVE 4.0IMPROVE 4.0
IMPROVE 4.0
 
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
 
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
 
Dab:exporter - Presentazione
Dab:exporter - PresentazioneDab:exporter - Presentazione
Dab:exporter - Presentazione
 
Query Processor & Statistics: A Performance Primer
Query Processor & Statistics: A Performance PrimerQuery Processor & Statistics: A Performance Primer
Query Processor & Statistics: A Performance Primer
 
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
 
Visual Studio Performance Tools
Visual Studio Performance ToolsVisual Studio Performance Tools
Visual Studio Performance Tools
 
[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
 
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
 
Best Practices on SQL Server
Best Practices on SQL ServerBest Practices on SQL Server
Best Practices on SQL Server
 
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
 
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
 
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
 

Mais de Gianluca Sartori

SQL Server 2016 New Security Features
SQL Server 2016 New Security FeaturesSQL Server 2016 New Security Features
SQL Server 2016 New Security FeaturesGianluca 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 timeGianluca 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 worldGianluca Sartori
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - ENGianluca Sartori
 
TSQL Advanced Query Techniques
TSQL Advanced Query TechniquesTSQL Advanced Query Techniques
TSQL Advanced Query TechniquesGianluca 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
 

Mais de Gianluca Sartori (8)

Benchmarking like a pro
Benchmarking like a proBenchmarking like a pro
Benchmarking like a pro
 
Sql server infernals
Sql server infernalsSql server infernals
Sql server infernals
 
SQL Server 2016 New Security Features
SQL Server 2016 New Security FeaturesSQL Server 2016 New Security Features
SQL Server 2016 New Security Features
 
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
 
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
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - EN
 
TSQL Advanced Query Techniques
TSQL Advanced Query TechniquesTSQL Advanced Query Techniques
TSQL Advanced Query Techniques
 
My Query is slow, now what?
My Query is slow, now what?My Query is slow, now what?
My Query is slow, now what?
 

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 Berry’s Diagnostic Information Queries http://sqlserverperformance.wordpress.com/ • Brent Ozar’s sp_Blitz http://www.brentozar.com/blitz/ • Davide Mauri’s 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 l’attività dell’istanza • SQLDiag / PSSDiag – Raccoglie counters, DMV, Trace, logs… Strumenti per la raccolta informazioni
  • 18. Analisi • Management Datawarehouse – Contiene informazioni sugli indicatori di performance e l’attività • 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 l’analisi Strumenti per l’analisi 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 dell’utilizzo 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 L’analisi 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 all’altra! • 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 un’istanza 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 • L’ambiente 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 • L’ambiente di test deve essere isolato dalla produzione! Preparazione dell’ambiente 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