tarek bohsali
play

Tarek Bohsali Microsoft SESSION SUMMARY [PRES ESEN ENTATI TION - PowerPoint PPT Presentation

[TITLE LE] Scaling SQL Server Applications: Application Design and Hardware Considerations Tarek Bohsali Microsoft SESSION SUMMARY [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] SQL Server is a proven


  1. [TITLE LE] Scaling SQL Server Applications: Application Design and Hardware Considerations Tarek Bohsali Microsoft

  2. SESSION SUMMARY [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] • SQL Server is a proven platform for OLTP workloads SQL Server 2008 R2 offers features to assist with OLTP scalability • • How to design hardware and software for scalability

  3. AGENDA [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] • OLTP workload characteristics OLTP application design principles • • Scalability determinants and bottlenecks SQL Server 2008 R2 Performance and Scale features • • Demo Scaling Up – Hardware to the rescue • • Summary

  4. OLTP WORKLOAD CHARACTERISTICS [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] • Typically used by line-of-business (LOB) applications • Has both read-write • Fine-grained inserts and updates • High transaction throughput e.g., 10s K/sec • Usually very short transactions e.g., 1 – 3 tables • Sometimes multi-step e.g., financial • Relatively small data sizes

  5. APPLICATION DESIGN PRINCIPLES

  6. ENTITY FRAMEWORK 4.0 [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] • Development Approaches Model First development – Start from a Model and then have T-SQL and customized • code generated. Testing – New interface and guidance for building test suites faster. • Architectural Advantages • • Persistence Ignorance – Use your own classes without needing to introduce interfaces or other elements • Applications Patterns – Discussing patterns like the Repository and UnitOfWork patterns with guidance on how to use them with the Entity Framework • Building N-Tier applications – Adding API’s and templates that make building N -Tier applications much easier

  7. EXPLORING THE MODEL [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] • The Three Parts of the Model: The image is taken from Julia Lerman’s book Programming Entity Framework, 1st Edition

  8. REVERSE ENGINEER DATABASE [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE]

  9. [PRES ESEN ENTATI TION N TITLE LE] APPLICATION DESIGN BEST PRACTICES [PRES ESEN ENTATI TION N TITLE LE] • Ensure good logical (E-R Model) and physical (indexes) DB design • Leverage set-oriented processing power of SQL Server • Update Statistics – ensure it is up to date! • Use DTA to assist with physical design • Avoid too many joins • Now let’s talk Physical Design

  10. PHYSICAL DESIGN BEST PRACTICES [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] • Reasons for Physical Design changes Performance • • Availability Security • • Auditing Separate logs and data if possible • • Spend time doing index analysis Tune OLTP systems for high I/O per second • • Tune data warehouse for high throughput per second

  11. CLUSTERED INDEX GUIDELINES • Good when queries select large number of • Remember cost of maintenance: adjacent rows (range queries) Updates reorganize the table • Create on the frequently used columns • • Performance impact (in JOINs and WHERE with “=“, “<“, “>“, “BETWEEN”) • Causes index fragmentation over time • If number of returned rows is small – non-clustered index may be as efficient Preferred on narrow and highly • selective columns

  12. NON-CLUSTERED INDEX GUIDELINES • Create for frequent search columns • The drawback: maintenance cost Use on narrow and highly selective Frequent updates will ruin perf where • • columns there are too many indexes Place on foreign key constraints (for join Evaluate benefits of [not] indexing small • • queries) tables • Check the workload for “covering” queries Consider adding included columns •

  13. OLTP SCALABILITY DIMENSIONS & DETERMINANTS Dimensions Bottleneck Resources Transaction throughput CPU • • • No. of concurrent users • Memory Transaction Poor takes Data size and growth rate IO • scaling • longer • Network Transaction holds resources Key Design Pattern for Scalability: Divide and Conquer

  14. TYPICAL CPU SCALING ISSUES Symptoms Causes Plan compilation and recompilations • • Queries not parameterized • Plan reuse < 90% is bad • Inefficient Query plan • Parallel queries Not enough stored procedures • Parallel wait type cxpacket > 10% of • MAXDOP is not set to 1 • total waits Statistics not updated • High runnable tasks or • • Table scan, range scan sos_scheduler_yield waits • SET option changes within SP

  15. TYPICAL IO SCALING ISSUES Causes Symptoms High average disk seconds per read (> 10 Aggravated by Big IOs such as table • • msec) and write (> 2 msec) for spindle scans (bad query plans) based devices • Non covering indexes Top 2 values for wait stats are one of - • Sharing of storage backend – combine • ASYNCH_IO_COMPLETION, OLTP and DW workloads IO_COMPLETION, LOGMGR, TempDB bottleneck • WRITELOG, PAGEIOLATCH_x • Too few spindles, HBA’s

  16. TYPICAL BLOCKING ISSUES Causes Symptoms High average row lock or latch waits Higher isolation levels • • • Will show up in • Index contention sp_configure “blocked process Lock escalation • • threshold” and Profiler “Blocked • Slow I/O process Report” Sequence number problem • Top wait statistics are LCK_x. See • sys.dm_os_wait_stats.

  17. TYPICAL MEMORY ISSUES Causes Symptoms Page life expectancy < 300 secs • Too many large scans (I/O) • • SQL Cache hit ratio < 99% • Bad query plans • Lazy writes/sec constantly External (other process) pressure • active • Out of memory errors

  18. PERFORMANCE AND SCALE FEATURES IN SQL [PRES ESEN ENTATI TION N TITLE LE] SERVER 2008 R2 [PRES ESEN ENTATI TION N TITLE LE] • Better query plans • Dynamic affinity (hard or soft) Hot-add CPU support • • Plan guides • Data Compression • Optimize for Unknown Especially if you have I/O issues • • Lock escalation hints • Partitioning • Resource governor Snapshot Isolation, RCSI • • Transparency and Diagnostics • Control Point – Xevent, DMV’s • > 64 thread support

  19. PLAN GUIDES [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] • Guide optimizer to use a fixed query plan Helps with plan predictability • • Use when you can’t change the application Simple example • SELECT TOP 1 * FROM Sales.SalesOrderHeader ORDER BY OrderDate DESC; • sp_create_plan_guide @name = N'Guide2', @stmt = N'SELECT TOP 1 * FROM • Sales.SalesOrderHeader ORDER BY OrderDate DESC', @type = N'SQL', @module_or_batch = NULL, @params = NULL, @hints = N'OPTION (MAXDOP 1)';

  20. OPTIMIZE FOR UNKNOWN [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] OPTIMIZE FOR UNKNOWN • • Hint directs the query optimizer to treat as if no parameters values had been passed Helps solve case where specific parameter values in query result in a bad plan for other values • • Example • @p1=1, @p2=9998, • SELECT * FROM t WHERE col > @p1 or col2 > @p2 ORDER BY col1 OPTION (OPTIMIZE FOR (@p1 UNKNOWN , @p2 UNKNOWN ))

  21. DEMO

  22. LOCK ESCALATION CONTROLS [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] Check if lock escalation is causing blocking before disabling • • Disable lock escalation at an object or table level Enable lock to be escalated to the partition of the table • • If the lock is escalated to partition (Hobt), it is not escalated further Alter table T1 set (LOCK_ESCALATION = DISABLE) •

  23. [PRES ESEN ENTATI TION N TITLE LE] RESOURCE GOVERNOR [PRES ESEN ENTATI TION N TITLE LE] Benefits SQL Server 2008 Provide deterministic Quality Of Service Admin Workload OLTP Workload Report Workload Prevent run-away queries Executive OLTP Backup Reports Tames ill behaved Apps Activity DW & Consolidation scenarios Admin Tasks Ad-hoc Reports High SQL Server 2008 RG Workloads are mapped to Resource Pools Min Memory 10% Online changes of groups and Max CPU pools Max Memory 90% 20% Real-time Resource Monitoring Max CPU 20% Up to 20 Resource Pools Application Pool Admin Pool

  24. EXTENDED EVENTS (XEVENT) [PRES ESEN ENTATI TION N TITLE LE] [PRES ESEN ENTATI TION N TITLE LE] • Extremely high performance and extensible event and trace mechanism Dynamic data collection on event fire • • Integrated with ETW (Event Tracing for Windows) Enables correlation with events exposed by Windows and third party applications • • Hundreds of event points throughout SQL Server code base Can identify session/statement level wait statistics •

  25. CORE SYSTEM COMPONENTS The key is to build a Balanced System without bottlenecks NIC 4 Network 1 Server Memory 2 HBA 5 3 Disk SQL File Layout Subsystem SQL Server is only part of the equation. Eco system needs to scale.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend