Ajuste (tuning) del rendimiento de SQL Server 2008
-
Upload
eduardo-castro -
Category
Technology
-
view
8.527 -
download
4
description
Transcript of Ajuste (tuning) del rendimiento de SQL Server 2008
![Page 1: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/1.jpg)
Ing. Eduardo Castro, PhD [email protected] http://ComunidadWindows.org
![Page 2: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/2.jpg)
Session Objectives:
Get familiar with database performance tuning tools, especially what SQL Server 2008 offers
Understand methodology of database performance bottleneck analysis
Learn features/improvements of SQL Server 2008 that help improve performance
![Page 3: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/3.jpg)
Target the most challenging and innovative SQL Server applications
10+ TB DW, 3k/tran/s OLTP, Large 500GB+ Cubes, Competitive migrations, Complex deployments, Server Consolidation (1000+)
Invest in large scale, referenceable SQL Server projects across the world
Provide SQLCAT technical & project experience
Conduct architecture and design reviews covering performance, operation, scalability and availability
Offer use of HW lab in Redmond with direct access to SQL Server development team
![Page 4: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/4.jpg)
Performance Tuning Tools
I/O Bottleneck
CPU Bottleneck
Memory Bottleneck
![Page 5: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/5.jpg)
System Performance Monitor (Perfmon)
SQL Profiler Trace
Dynamic Management Views/Functions
DBCC commands
SQLDiag (Shipped with SQL 2005/2008)
SQLIO, SQLIOSim
KernRate
Debugging tools (Windbg, DebugDiag,…)
More…
![Page 6: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/6.jpg)
Data Collector & Management Data Warehouse (MDW)
Extended Events
Activity Monitor
New DMVs/DMFs
![Page 7: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/7.jpg)
SQL Agent
dcexec.exe
Cache Files
SSIS Pkgs
Job Metadata
Collection Set Metadata
MDW
Snapshot Data
Management Studio
MDW
Reports
msdb
MDW Host
Target Server Client Workstation
![Page 8: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/8.jpg)
Time line
Navigation control
Resource usage
![Page 9: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/9.jpg)
Highly scalable with low overhead
Future of SQL tracing
![Page 10: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/10.jpg)
Built-in system_health session select event_session_id, name, startup_state from
sys.server_event_sessions
Session definition example create event session session_error on server ADD EVENT sqlserver.error_reported (action (sqlserver.sql_text, sqlserver.tsql_stack,
sqlserver.client_app_name) where error = 50001) ADD target package0.ring_buffer with (max_dispatch_latency = 1 seconds) go alter event session session_error on server state = start; go
![Page 11: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/11.jpg)
![Page 12: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/12.jpg)
Memory allocation tracking sys.dm_os_memory_brokers sys.dm_os_memory_nodes
Reqource Governor sys.dm_resource_governor_configuration sys.dm_resource_governor_resource_pools sys.dm_resource_governor_workload_groups
Query performance (hash value for query and plan) sys.dm_exec_query_stats
Sys.dm_exec_requests sys.dm_exec_procedure_stats sys.dm_exec_trigger_stats
More…
![Page 13: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/13.jpg)
Bottleneck – A point or component of a process where throughput is the slowest.
Understanding where time is spent
Elapsed Time = Running + Waiting
Key is the waiting - what type of wait(s)?
![Page 14: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/14.jpg)
Monitor and identify I/O bottleneck
Resource Monitor & Performance Monitor
MDW
DMV & Extended Events
What is driving high I/O load?
Inefficient query plan
Too much data to read/write
Slow I/O subsystem
![Page 15: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/15.jpg)
File level I/O throughput
and disk response time
![Page 16: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/16.jpg)
Runtime Performance monitoring
System Reports
What counters to look at?
![Page 17: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/17.jpg)
Physical Disk Object: Avg. Disk Queue Length Avg. Disk Sec/Read Avg. Disk Sec/Write %Disk Time Disk Transfers/Sec Avg. Disk Bytes/Read Avg. Disk Bytes/Write Disk Read Bytes/Sec Disk Write Bytes/Sec
SQL Server Buffer Manager Object: (memory pressure could cause I/O pressure)
Buffer Cache hit ratio Page Life Expectancy Checkpoint pages/sec Lazywrites/sec
![Page 18: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/18.jpg)
WriteLog and LogBuffer
waits
Page I/O waits in Buffer pool
![Page 19: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/19.jpg)
High I/O Latch Wait Time
pending/stalled I/O
ERRORLOG warnings of I/O
delays
sys.dm_os_wait_stats
sys.dm_exec_requests
sys.dm_io_pending_io_requests
sys.dm_io_virtual_file_stats
15 second delay in IO
completion
This is
way too
slow
![Page 20: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/20.jpg)
sqlos package
• async_io_requested
• async_io_completed
• wait_info
• wait_info_external
sqlserver package
• physical_page_read
• physical_page_write
• file_read
• file_write
• long_io_detected
2009-04-13 18:30:10.170 spid5s SQL Server has encountered 1
occurrence(s) of I/O requests taking longer than 15 seconds to complete on file
[T:\tempdb\templog.ldf] in database [tempdb] (2). The OS file handle is
0x0000000000000670. The offset of the latest long I/O is: 0x000007eecac000
king longer than 15 seconds to complete on file [e:\myslowdb.mdf] in database
[myslowdb] (1). The OS file handle is
0x00000438. The offset of the latest long IO is: 0x000000513ce000
![Page 21: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/21.jpg)
Look if there is memory pressure
Further narrow down to what queries are generating the I/O workload. Tune these queries.
Explore data compression to reduce I/O load
Upgrade storage hardware
![Page 22: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/22.jpg)
Compress tables/indexes to reduce database size
Compression ratio depends on schema & data distribution (avg 50-60%)
Reduce query runtime I/O (increase cpu)
Identify compression candidates
sp_estimate_data_compression_savings
sys.dm_db_index_operational_stats
![Page 23: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/23.jpg)
![Page 24: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/24.jpg)
Sustained %Processor Time > 80%
Performance Monitor/Task Manager
MDW Server Activity Report
DMV & Extended Events
What is driving high CPU?
Recompilations
Cursors
Inefficient query plans
More…
![Page 25: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/25.jpg)
• Monitor it Live Resource Monitor/Task Manager
• Watch Live or Log counters you like
Performance Monitor Counters
• Formatted Perfmon counter based report
System Data Collector Reports
• Dig deeper using ETW Windows Performance Toolkit (XPerf)
![Page 26: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/26.jpg)
Processor object: %Privileged Time %Processor Time %User Time
Process object (SQL Server): %Privileged Time %Processor Time %User Time
SQL Server:Workload Group Stats CPU usage % Max request cpu time
SQL Server:Resource Pool Stats CPU usage % CPU usage target %
New in SQL Server 2008 for Resource Governor feature
![Page 27: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/27.jpg)
SQL Server:SQL Statistics
Batch requests/sec
SQL Compilations/sec
SQL Re-Compilations/sec
SQL Server:Cursor Manager by Type
SQL Server:Cursor Manager Total
Concurrent processing of multiple cursors could be cpu
intensive
![Page 28: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/28.jpg)
Wait in runnable
queue
Total CPU waits
Thread voluntarily
yields
CPU cycles that did the real work
![Page 29: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/29.jpg)
Sys.dm_exec_sessions
cpu_time
total_scheduled_time
total_elapsed_time
sys.dm_exec_requests
cpu_time
total_elapsed_time
query_hash
sys.dm_exec_query_stats
sys.dm_exec_procedure_stats
sys.dm_exec_trigger_stats
total_worker_time
total_elapsed_time
Sql_handle/query_hash
Sys.sysprocesses
cpu
Backward compatibility view
![Page 30: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/30.jpg)
sqlos package
•scheduler_monitor_non_yielding_ring_buffer_recorded
•spinlock_backoff
•Wait_info
•wait_info_external
sqlserver package
•sql_statement_completed
•sp_statement_completed
•cursor_manager_cursor_end
•checkpoint_end
Extended Event can track individual statement level events like Profiler does
with minimal impact -
ADD EVENT sqlserver.sql_statement_completed
(action (sqlserver.sql_text)
WHERE duration > 0),
ADD EVENT sqlserver.sp_statement_completed
(action (sqlserver.sql_text)
WHERE duration > 0)
select top 10
CONVERT(xml, event_data).value('(/event/data/value)[4]','int') as 'cpu'
![Page 31: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/31.jpg)
High cpu doesn’t necessarily mean it’s a problem.
Drill down to specific workload and queries that drive cpu usage. Tune them.
Use Resource Governor to protect high priority workloads
Upgrade hardware
![Page 32: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/32.jpg)
Resource Governor
allocate cpu/memory to prioritized workloads based on connection string parameters
Mixed workloads: OLTP, Reporting, Maintenance
Soft Numa
Node configuration (soft numa node and cpu affinity)
Network Configuration (soft numa node and tcp port)
![Page 33: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/33.jpg)
![Page 34: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/34.jpg)
Monitor and identify memory pressure
Performance Monitor/Task Manager
MDW Server Activity Report
DMV & Extended Events
What is eating up my memory?
External or internal memory pressure
Inefficient query plan (hashing, sorting,…)
![Page 35: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/35.jpg)
AWE
32-bit uses AWE to cache data/index pages
64-bit uses AWE to implement “Locked pages in memory”
Environment Virtual Address
Space
Max physical
memory
32-bit on 32-bit OS 2 GB 64 GB
32-bit on 64-bit OS (Wow) 4 GB 64 GB
64-bit on 64-bit OS 8 TB 2 TB
![Page 36: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/36.jpg)
Perfmon is golden tool to identify memory pressure
Memory object: Available K/M bytes
Commit Limit
Paging File %Usage (Peak)
Page reads/sec
Process object: Private bytes
Virtual bytes
Working set
![Page 37: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/37.jpg)
SQL Server Memory Manager object: Connection Memory Lock Memory Optimizer Memory Memory Grants Pending …
SQL Server Buffer Manager object: Buffer cache hit ratio Checkpoint pages/sec Free list stalls/sec Free pages Lazy writes/sec Page life expectancy Stolen pages Target pages Total pages
SQL Server Plan Cache object SQL Server Resource Pool Stats object
Somebody is waiting on memory
How long will the page live?
![Page 38: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/38.jpg)
Query execution waits on memory for sorting,
hashing,…
![Page 39: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/39.jpg)
DBCC MEMORYSTATUS
sys.dm_os_sys_memory
system_memory_state_desc a good indicator of available physical memory
sys.dm_os_process_memory
process_physical_memory_low = 1 indicates low physical memory.
memory_utilization_percentage value below 100% indicates external memory pressure.
sys.dm_os_memory_clerks
![Page 40: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/40.jpg)
sys.dm_os_ring_buffers
RING_BUFFER_SCHEDULER_MONITOR
RING_BUFFER_RESOURCE_MONITOR
RING_BUFFER_OOM
RING_BUFFER_MEMORY_BROKER
RING_BUFFER_BUFFER_POOL
![Page 41: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/41.jpg)
sqlos package
• page_heap_memory_allocated
• page_heap_memory_freed
• memory_node_oom_ring_buffer_recorded
sqlserver package
• sort_memory_grant_adjustment
• plan_cache_cache_hit
• plan_cache_cache_attempt
• cursor_manager_cursor_memory_usage
2009-04-14 09:27:15.43 spid62 Failed allocate
pages: FAIL_PAGE_ALLOCATION 1
![Page 42: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/42.jpg)
Check memory configuration – sp_configure
External memory pressure – Identify what other processes are competing
Internal memory pressure – Identify which SQL component is main consumer
Workload/query tuning (sorting, hash join…)
Resource Governor
Hardware upgrade
![Page 43: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/43.jpg)
![Page 44: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/44.jpg)
Focus on methodology – no guess
Correlate data points from multiple tools
Performance tuning is iterative process – bottleneck could move
Resource contention impacts each other
Lack of memory -> high cpu & I/O
Slow I/O -> tempdb contention
…
![Page 45: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/45.jpg)
Ing. Eduardo Castro, PhD [email protected]
![Page 46: Ajuste (tuning) del rendimiento de SQL Server 2008](https://reader035.fdocuments.net/reader035/viewer/2022081511/555c44b1d8b42a2c068b4ff0/html5/thumbnails/46.jpg)
“Troubleshooting Performance Problems in SQL Server 2008” http://msdn.microsoft.com/en-us/library/dd672789.aspx