• Save
SQL Server Performance Analysis
Upcoming SlideShare
Loading in...5
×
 

SQL Server Performance Analysis

on

  • 4,980 views

Les comparto la presentación utilizada en la charla sobre optimización de desempeño de SQL Server....

Les comparto la presentación utilizada en la charla sobre optimización de desempeño de SQL Server.

Saludos,

Eduardo Castro Martinez
http://ecastrom.blogspot.com
http://comunidadwindows.org

Statistics

Views

Total Views
4,980
Views on SlideShare
4,980
Embed Views
0

Actions

Likes
3
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

SQL Server Performance Analysis SQL Server Performance Analysis Presentation Transcript

  • Ing. Eduardo Castro, PhDecastro@grupoasesor.nethttp://ComunidadWindows.org
  • 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
  • Target the most challenging and innovativeSQL Server applications10+ TB DW, 3k/tran/s OLTP, Large 500GB+ Cubes, Competitive migrations,Complex deployments, Server Consolidation (1000+)Invest in large scale, referenceable SQL Server projectsacross 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
  • Performance Tuning ToolsI/O BottleneckCPU BottleneckMemory Bottleneck
  • System Performance Monitor (Perfmon)SQL Profiler TraceDynamic Management Views/FunctionsDBCC commandsSQLDiag (Shipped with SQL 2005/2008)SQLIO, SQLIOSimKernRateDebugging tools (Windbg, DebugDiag,…)More…
  • Data Collector & Management DataWarehouse (MDW)Extended EventsActivity MonitorNew DMVs/DMFs
  • MDW Host MDW Client Workstation Target Server Snapshot Data dcexec.exe Management Studio SSIS Pkgs CacheCollection Set MDW Metadata Files ReportsJob Metadata SQL Agent msdb
  • Time lineNavigation controlResource usage
  • Highly scalable with low overheadFuture of SQL tracing
  • Built-in system_health sessionselect event_session_id, name, startup_state fromsys.server_event_sessionsSession definition examplecreate 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)goalter event session session_error on server state = start;go
  • Memory allocation tracking sys.dm_os_memory_brokers sys.dm_os_memory_nodesReqource Governor sys.dm_resource_governor_configuration sys.dm_resource_governor_resource_pools sys.dm_resource_governor_workload_groupsQuery 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_statsMore…
  • Bottleneck – A point or component of aprocess where throughput is the slowest.Understanding where time is spentElapsed Time = Running + WaitingKey is the waiting - what type of wait(s)?
  • Monitor and identify I/O bottleneck Resource Monitor & Performance Monitor MDW DMV & Extended EventsWhat is driving high I/O load? Inefficient query plan Too much data to read/write Slow I/O subsystem
  • File level I/O throughput and diskresponse time
  • RuntimePerformance monitoring System ReportsWhat counters to look at?
  • 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/SecSQL Server Buffer Manager Object: (memorypressure could cause I/O pressure) Buffer Cache hit ratio Page Life Expectancy Checkpoint pages/sec Lazywrites/sec
  • Page I/O waitsin Buffer poolWriteLog and LogBuffer waits
  • High I/O Latch sys.dm_os_wait_stats Wait Time sys.dm_exec_requestspending/stalled sys.dm_io_pending_io_requests I/O sys.dm_io_virtual_file_stats ERRORLOG This is 15 second delay in IOwarnings of I/O completion way too delays slow
  • sqlos package sqlserver package• async_io_requested • physical_page_read• async_io_completed • physical_page_write• wait_info • file_read• wait_info_external • 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:tempdbtemplog.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
  • Look if there is memory pressureFurther narrow down to what queries aregenerating the I/O workload. Tune thesequeries.Explore data compression to reduce I/OloadUpgrade storage hardware
  • Compress tables/indexes to reducedatabase sizeCompression 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
  • Sustained %Processor Time > 80% Performance Monitor/Task Manager MDW Server Activity Report DMV & Extended EventsWhat is driving high CPU? Recompilations Cursors Inefficient query plans More…
  • Resource • Monitor it LiveMonitor/Task ManagerPerformance Monitor • Watch Live or Log Counters counters you likeSystem Data Collector • Formatted Perfmon Reports counter based reportWindows Performance • Dig deeper using ETW Toolkit (XPerf)
  • Processor object: %Privileged Time %Processor Time New in SQL Server 2008 for Resource %User Time Governor featureProcess object (SQL Server): %Privileged Time %Processor Time %User TimeSQL Server:Workload Group Stats CPU usage % Max request cpu timeSQL Server:Resource Pool Stats CPU usage % CPU usage target %
  • SQL Server:SQL Statistics Batch requests/sec SQL Compilations/sec SQL Re-Compilations/secSQL Server:Cursor Manager by TypeSQL Server:Cursor Manager Total Concurrent processing of multiple cursors could be cpu intensive
  • Total CPU waitsCPU cyclesthat did the real work Wait in runnable queue Threadvoluntarily yields
  • sys.dm_exec_query_statsSys.dm_exec_sessions sys.dm_exec_requests sys.dm_exec_procedure_stats Sys.sysprocesses sys.dm_exec_trigger_stats cpu_time cpu_time total_worker_time cpu total_scheduled_tim e total_elapsed_time total_elapsed_time Backward compatibility view Sql_handle/query_h total_elapsed_time query_hash ash
  • sqlos package sqlserver package•scheduler_monitor_non_yielding_ring_buffer_recorded •sql_statement_completed•spinlock_backoff •sp_statement_completed•Wait_info •cursor_manager_cursor_end•wait_info_external •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
  • High cpu doesn’t necessarily mean it’s aproblem.Drill down to specific workload and queriesthat drive cpu usage. Tune them.Use Resource Governor to protect highpriority workloadsUpgrade hardware
  • Resource Governor allocate cpu/memory to prioritized workloads based on connection string parameters Mixed workloads: OLTP, Reporting, MaintenanceSoft Numa Node configuration (soft numa node and cpu affinity) Network Configuration (soft numa node and tcp port)
  • Monitor and identify memory pressure Performance Monitor/Task Manager MDW Server Activity Report DMV & Extended EventsWhat is eating up my memory? External or internal memory pressure Inefficient query plan (hashing, sorting,…)
  • AWE 32-bit uses AWE to cache data/index pages 64-bit uses AWE to implement “Locked pages in memory” Environment Virtual Address Max physical Space 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
  • Perfmon is golden tool to identify memorypressureMemory object: Available K/M bytes Commit Limit Paging File %Usage (Peak) Page reads/secProcess object: Private bytes Virtual bytes Working set
  • SQL Server Memory Manager object: Connection Memory Lock Memory Somebody is waiting on Optimizer Memory 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 How long will the page Stolen pages live? Target pages Total pagesSQL Server Plan Cache objectSQL Server Resource Pool Stats object
  • Query execution waits on memory for sorting, hashing,…
  • DBCC MEMORYSTATUSsys.dm_os_sys_memory system_memory_state_desc a good indicator of available physical memorysys.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
  • sys.dm_os_ring_buffers RING_BUFFER_SCHEDULER_MONITOR RING_BUFFER_RESOURCE_MONITOR RING_BUFFER_OOM RING_BUFFER_MEMORY_BROKER RING_BUFFER_BUFFER_POOL
  • sqlos package sqlserver package• page_heap_memory_allocated • sort_memory_grant_adjustment• page_heap_memory_freed • plan_cache_cache_hit• memory_node_oom_ring_buffer_recorded • plan_cache_cache_attempt • cursor_manager_cursor_memory_usage 2009-04-14 09:27:15.43 spid62 Failed allocate pages: FAIL_PAGE_ALLOCATION 1
  • Check memory configuration – sp_configureExternal memory pressure – Identify whatother processes are competingInternal memory pressure – Identify whichSQL component is main consumerWorkload/query tuning (sorting, hash join…)Resource GovernorHardware upgrade
  • Focus on methodology – no guessCorrelate data points from multiple toolsPerformance tuning is iterative process –bottleneck could moveResource contention impacts each other Lack of memory -> high cpu & I/O Slow I/O -> tempdb contention …
  • Ing. Eduardo Castro, PhDecastro@grupoasesor.net
  • “Troubleshooting Performance Problems in SQL Server2008” http://msdn.microsoft.com/en-us/library/dd672789.aspx