Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Extensible Storage Engine wikipedia , lookup
Microsoft Access wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Database model wikipedia , lookup
Tandem Computers wikipedia , lookup
Relational model wikipedia , lookup
Clusterpoint wikipedia , lookup
Team Foundation Server wikipedia , lookup
Managing SQL Server Performance AtlantaMDF August 11, 2003 By Larry Ansley 2 Performance Maximization Plan In Only 4 Easy Steps • • • • Denormalize Index Everything Use Full-Text Searches Liberally Get a Bigger, More Powerful System 3 Performance Areas Hardware • • • • Memory CPU Storage Network 4 Performance Areas Operating System • Configuration • Version Upgrades 5 Performance Areas Operating System • Configuration • File Management • Version Upgrades 6 Performance Areas SQL Server • Configuration & Options • File Management • Version Upgrades 7 Performance Areas Databases • • • • Configuration & Options Tables Indexes File Management 8 Performance Areas Stored Procedures • Logic • Best Practices 9 Performance Killers 1. 2. 3. 4. 5. 6. 7. Poor indexing Inaccurate statistics Excessive fragmentation Non-reusable execution plans Frequent recompilation Excessive blocking and deadlocks Poor query design 10 Performance Killers 8. Poor database design 9. Improper cursor use 10. Ineffective connection pooling 11. Improper database log configuration 11 Taming The Performance Killers • Planning – – – – ER Diagrams Data Modeling Capacity Requirements Procedure Case Analysis • Follow Best Practices in Development 12 Taming The Performance Killers • Good Record Keeping – Logs – Baselines – Audits 13 Performance Baselines Benefits • Allows us to analyze resource bottlenecks • Allows us to troubleshoot by comparing system utilization patterns with preestablished baselines • Allows us to make accurate estimates in capacity planning and scheduling hardware upgrades 14 Performance Baselines Benefits • Aids us in identifying low utilization periods, when we can execute administrative activities • Helps us distinguish between performance perception and reality 15 Performance Baselines Baseline Tools • System Monitor (Key Resource Counters) – – – – – CPU – % Processor Time (85%) CPU – Processor Queue Length (2) Memory – Available Bytes (4 MB) Memory – Pages / Sec (20) Memory – Buffer Cache Hit Ratio ( 90%) 16 Performance Baselines Baseline Tools • System Monitor (Key Resource Counters) – Disk – % Disk Time (90%) – Disk – Avg. Disk Queue Length (number of spindles + 2) – Network – % Net Utilization (30% for Ethernet) – SQL Server – User Connections 17 Performance Baselines Baseline Tools • SQL Profiler – Record Traces for Major Processes – Duration, CPU, Reads, Writes 18 Performance Audit • • • • • • • System Monitor Hardware Operating System SQL Server Configuration Database Settings Indexes Application and Transact-SQL 19 Performance Audit System Monitor • Processor: % Processor Time – Recurring period exceeding 80% indicate CPU bottlenecks • System: Processor Queue Length – Recurring periods exceeding 2 per CPU indicate CPU bottlenecks – Consider Maximum Worker Threads setting 20 Performance Audit System Monitor • Memory: Pages / Sec – Average around 0 over 24 hours – Average over 20 indicates memory bottleneck • Memory: Available Bytes – Should be greater than 5 MB – Dedicated SQL Servers attempt to maintain 410 MB free – Less than 5 MB indicates a memory bottleneck 21 Performance Audit System Monitor • SQL Server Buffer: Buffer Cache Hit Ratio – For OLTP application, should exceed 90%, ideally around 99% – OLAP (Analysis Services) application work well with lower ratios • SQL Server General: User Connections – If this exceeds 255, Maximum Worker Threads setting should be increased to remain greater than user connections, thus avoiding thread sharing. 22 Performance Audit System Monitor • Physical Disk: % Disk Time – Should run less than 55% – Recurring periods (10 minutes or more) exceeding 55% indicate I/O bottlenecks • Physical Disk: Avg. Disk Queue Length – Should run less than 2 per spindle – Recurring periods exceeding 2 indicate I/O bottlenecks 23 Performance Audit Hardware • • • • • Number of CPUs CPU MHz CPU L2 Cache Size Physical Ram Amount Total Amount of Available Drive Space on Server • Total Number of Physical Drives in Each Array 24 Performance Audit Hardware • • • • • • • Hardware vs. Software Raid RAID Level of Each Array Used Disk Fragmentation Level Location of Operating System Location of SQL Server Executables Location of Swap File Location of tempdb Database 25 Performance Audit Hardware • • • • • • • Location of System Databases Location of User Databases Location of Log Files Number of Disk Controllers in Server Type of Disk Controllers in Server Size of Cache in Disk Controllers In Server Is Write Cache in Disk Controller On or Off 26 Performance Audit Hardware • Speed of Disk Drives • How Many Network Cards Are in Server • Are the Network Cards Hard-Coded for Speed/Duplex • Are the Network Cards Attached to a Switch • Are All the Hardware Drivers Up-to-Date • Is This Physical Server Dedicated to SQL Server 27 Performance Audit Operating System • Are the Disk Partitions NTFS 5.0 • Is “NTFS Data File Encryption and Compression” Turned Off • Is the Server Updated With the Latest Service Pack • Does the Server Have the Most Current, Microsoft-Certified Hardware Drivers 28 Performance Audit Operating System • Is the Windows 2000 Server Configured as a Stand-Alone Server • Are the Physical Files on the Server Overly Fragmented • Is the “Application Response” Setting Set to “Optimize Performance” for “Background Services” • Has Security Auditing Been Turned On 29 Performance Audit Operating System • How Large Is the Server’s PAGEFILE.SYS swap file • Have Unnecessary Services Been Turned Off • Have All Unnecessary Network Protocols Been Turned Off 30 Performance Audit SQL Server Configuration Settings Advanced Restart Default Current Affinity mask Yes Yes 0 Awe enabled Yes Yes 0 Cost threshold for parallelism Yes No 5 Cursor threshold Yes No -1 Fill factor (%) Yes Yes 0 31 Performance Audit SQL Server Configuration Settings Index create memory (KB) Lightweight pooling Locks Max degree of parallelism Advanced Restart Default Current Yes No 0 Yes Yes 0 Yes Yes Yes No 0 0 32 Performance Audit SQL Server Configuration Settings Max server memory (MB) Max text repl size (B) Max worker threads Min memory per query (KB) Advanced Restart Default Current Yes No No No 2,147,4 83,647 65536 Yes Yes 255 Yes No 1024 33 Performance Audit SQL Server Configuration Settings Advanced Restart Default Current Min server memory (MB) Nested triggers Yes No 0 No No 1 Network packet size (B) Open objects Yes No 4096 Yes Yes 0 34 Performance Audit SQL Server Configuration Settings Advanced Restart Default Current Priority boost Yes Yes 0 Query governor cost limit Query wait (s) Recovery interval (min) Yes No 0 Yes Yes No No -1 0 35 Performance Audit SQL Server Configuration Settings Scan for startup procs Set working set size User connections Advanced Restart Default Current Yes No 0 Yes Yes 0 Yes No 0 36 Performance Audit Database Configuration Settings Database Setting Auto_close Auto_create_statistics Auto_update_statistics Auto_shrink Read_only Torn_page_detection Default Off On On Off Off On in 2000 Off in 7.0 Current 37 Performance Audit Database Configuration Settings Database Setting Compatibility level Database auto grow Transaction log auto grow Default 80 for 2000 70 for 7.0 On On Current 38 Performance Audit Indexes • Have you run the Index Tuning Wizard recently • Does every table in each database have a clustered index • Are any of the columns in any table indexed more than once • Are there any indexes that are not being used in queries 39 Performance Audit Indexes • Are the indexes too wide • Do the tables that are joined have the appropriate indexes on the joined columns • Are the indexes unique enough to be useful • Are you taking advantage of covering indexes • How often are indexes rebuilt • What is your index fillfactor 40 Performance Audit Transact-SQL • Does the Transaction-SQL code return more data than needed • Are cursors being used when they don’t need to be • Are Union and Union Select properly used • Is Select Distinct being used properly • Is the Where clause Sargable • Are temp tables used when they aren’t needed 41 Performance Audit Transact-SQL • Are hints being properly used in queries • Are view unnecessarily being used • Are stored procedures being used whenever possible • Inside stored procedures, is Set NoCount On being used • Do any of your stored procedures start with sp_ 42 Performance Audit Transact-SQL • Are all stored procedures owned by DBO and referred to in the form of databaseowner.objectname • Are you using constraints or triggers for referential integrity • Are transactions being kept as short as possible 43 Performance Audit Applications • Is the application using stored procedures, strings of T-SQL code, or using an object model, like ADO, to communicate with SQL Server • What method is the application using to communicate with SQL Server: DB-Lib, DAO, RDO, ADO, .Net • Is the application using ODBC or OLE DB to communicate with SQL Server 44 Performance Audit Applications • Is the application taking advantage of connection pooling • Is the application properly opening, reusing, and closing connections • Is the T-SQL code being sent to SQL Server optimized for SQL Server, or is it generic SQL • Does the application return unnecessary data 45 Performance Audit Applications • Is the application taking advantage of connection pooling • Is the application properly opening, reusing, and closing connections • Is the T-SQL code being sent to SQL Server optimized for SQL Server, or is it generic SQL • Does the application return unnecessary data 46 Performance Audit Applications • Does the application keep transaction open when the user is modifying data 47 Monitoring & Measuring Tools • • • • • Enterprise Manager Query Analyzer System Monitor SQL Profiler 3rd Party 48 Monitoring & Measuring Tools Enterprise Manager • Management / Current Activity – Process Info (sp_who2) – Locks / Process ID (sp_lock) – Locks / Object (sp_lock) • Management / SQL Server Logs 49 Monitoring & Measuring Tools Query Analyzer • • • • • • • • • sp_who / sp_who2 sp_lock sp_spaceused sp_monitor Showplan_Text Showplan_All Set Statistics IO Set Statistics Time Set Statistics Profile 50 Monitoring & Measuring Tools Query Analyzer • DBCC Commands – – – – – – DBCC UserOptions DBCC Show_Statistics DBCC ShowContig DBCC IndexDefrag DBCC PerfMon DBCC TraceOn / DBCC TraceOff 51 Monitoring & Measuring Tools Query Analyzer • Built-in Functions – – – – – – – – @@CPU_Busy @@IO_Busy @@Packet_Errors @@Connections @@Total_Read @@Total_Write @@Total_Errors @@TranCount 52 Monitoring & Measuring Tools Query Analyzer • System Tables – – – – – – Master.dbo.sysprocesses Master.dbo.syslockinfo Master.dbo.sysperfinfo Master.dbo.syscacheobjects dbo.sysobjects dbo.sysindexes • _WA_Sys_AcctNo_2216C367, hind_1400444113_1A_6A_7A – dbo.sysindexkeys – dbo.syscolumns – dbo.sysdepends 53 SQL Profiler & Query Analyzer Highest Execution Count 54 SQL Profiler & Query Analyzer Longest Single Duration 55 SQL Profiler & Query Analyzer Longest Aggregate Duration 56 SQL Profiler & Query Analyzer Recompiles 57 Suggested Reading Printed Books • Inside SQL Server 2000 – Kalen Delaney (Microsoft Press, 2001) • SQL Server Query Performance Tuning Distilled – Sajal Dam (Curlingstone, 2003) • SQL Server 2000 for Experienced DBAs – Brian Knight (Osborne, 2003) 58 Suggested Reading E-Books • Microsoft SQL Server Books On Line • Start to Finish Guide to SQL Server Performance Monitoring – Brian Kelly (NetImpress, 2002) • Hands-On SQL Server 2000 Troubleshooting: Locking and Blocking – Kalen Delaney (NetImpress, 2003) 59 Suggested Reading Periodicals • SQL Server Magazine (Penton Media) 60 Suggested Reading Web Sites & Web Articles • http://www.sql-server-performance.com – Brad McGehee – How to Perform a SQL Server Performance Audit; and many others – Randy Dyess – An Introduction to SQL Server Query Tuning; and many others – Joe Chang – SQL Server Quantitative Performance Analysis • http://www.sqlservercentral.com – Brian Knight 61 Suggested Reading Web Sites & Web Articles • http://www.sqlmag.com – Kalen Delaney – Recompiling Riddles; and many more – Neil Pike – What is the precedence of the SET commands, database options, session options, etc. • http://www.sqlteam.com • http://www.algonet.se/~sommar/index.html – Erland Sommarskog MBP – aba_lockinfo 62 Suggested Reading Web Sites & Web Articles • http://www.msdn.microsoft.com • http://support.microsoft.com/default.aspx?s cid=fh;EN-US;KBHOWTO • http://www.msdn.microsoft.com/library/def ault.asp?url=/nhp/Default.asp?contentid=28 000409 • http://www.microsoft.com/sql/ 63