Forced parameterization to the rescue

Published Jan 15 2019 04:34 PM 124 Views
Microsoft
First published on MSDN on Apr 22, 2015

Some of the features have been around for a long time.  But we keep seeing users not taking advantage of it.   I wanted to give you an example how forced parameterization can help you.

Recently I worked with a customer with a very active system serving many concurrent users.  Here is some basic information:

  1. CPU: 160 logical CPU (80 cores with hyper-threading enabled)
  2. RAM: 2TB RAM
  3. Active users: about 1400
  4. Batch requests/sec:  averaging 4000 or above

This is very mission critical system.  When their users reached max of 1400 and CPU reached above 70-80%, their application started to slow down.    With high CPU, the usual troubleshooting is the tune heavy hitter queries.  But SQL Nexus & RML report showed that there wasn’t predominant set of queries to tune.  The screenshot bellowed showed that top 10 queries accumulatively accounted for less than 20% of total CPU consumed.   This made it hard to focus and tune individual queries.

We noticed that the compilation was fairly high as shown in the screenshot below.  SQL Compilation/sec averaged 730.

With compilation being this high, it usually was because ad hoc queries were used at high rate.  To prove this, we pulled out “SQL Plan” out of “Cache Object Counts”.   It was almost over 160,000 (see screenshot below)!   This counter meant that there were almost 160,000 ad hoc plans in the plan cache!

Solution

Many times, ad hoc queries at high rate can cause issues such as wasting CPU to compile and wasting plan cache memory.   We had this customer enable “Forced Parameterization” for the database.  After that, the CPU dropped to 10-20% even with highest user load and performance became super fast.

Sometimes, a solution may be simpler than you might have thought.  Just keep this option handy.  If things don’t work out, it’s easy to back it out.  Over the course of troubleshooting performance issues, I have used this trick many times.  I hope this serve as a reminder for you.

Jack Li | Senior Escalation Engineer | Microsoft SQL Server Support

twitter | pssdiag | Sql Nexus

%3CLINGO-SUB%20id%3D%22lingo-sub-318560%22%20slang%3D%22en-US%22%3EForced%20parameterization%20to%20the%20rescue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-318560%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Apr%2022%2C%202015%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3ESome%20of%20the%20features%20have%20been%20around%20for%20a%20long%20time.%26nbsp%3B%20But%20we%20keep%20seeing%20users%20not%20taking%20advantage%20of%20it.%26nbsp%3B%26nbsp%3B%20I%20wanted%20to%20give%20you%20an%20example%20how%20forced%20parameterization%20can%20help%20you.%3C%2FP%3E%0A%20%20%3CP%3ERecently%20I%20worked%20with%20a%20customer%20with%20a%20very%20active%20system%20serving%20many%20concurrent%20users.%26nbsp%3B%20Here%20is%20some%20basic%20information%3A%3C%2FP%3E%0A%20%20%3COL%3E%0A%20%20%20%3CLI%3ECPU%3A%20160%20logical%20CPU%20(80%20cores%20with%20hyper-threading%20enabled)%3C%2FLI%3E%0A%20%20%20%3CLI%3ERAM%3A%202TB%20RAM%3C%2FLI%3E%0A%20%20%20%3CLI%3EActive%20users%3A%20about%201400%3C%2FLI%3E%0A%20%20%20%3CLI%3EBatch%20requests%2Fsec%3A%26nbsp%3B%20averaging%204000%20or%20above%3C%2FLI%3E%0A%20%20%3C%2FOL%3E%0A%20%20%3CP%3EThis%20is%20very%20mission%20critical%20system.%26nbsp%3B%20When%20their%20users%20reached%20max%20of%201400%20and%20CPU%20reached%20above%2070-80%25%2C%20their%20application%20started%20to%20slow%20down.%26nbsp%3B%26nbsp%3B%26nbsp%3B%20With%20high%20CPU%2C%20the%20usual%20troubleshooting%20is%20the%20tune%20heavy%20hitter%20queries.%26nbsp%3B%20But%20%3CA%20href%3D%22http%3A%2F%2Fsqlnexus.codeplex.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20SQL%20Nexus%20%3C%2FA%3E%20%26amp%3B%20%3CA%20href%3D%22http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F944837%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20RML%20%3C%2FA%3E%20report%20showed%20that%20there%20wasn%E2%80%99t%20predominant%20set%20of%20queries%20to%20tune.%26nbsp%3B%20The%20screenshot%20bellowed%20showed%20that%20top%2010%20queries%20accumulatively%20accounted%20for%20less%20than%2020%25%20of%20total%20CPU%20consumed.%26nbsp%3B%26nbsp%3B%20This%20made%20it%20hard%20to%20focus%20and%20tune%20individual%20queries.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68303iA8762C20E39ADEA1%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EWe%20noticed%20that%20the%20compilation%20was%20fairly%20high%20as%20shown%20in%20the%20screenshot%20below.%26nbsp%3B%20SQL%20Compilation%2Fsec%20averaged%20730.%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68304i4A10B6EEDCD8F547%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EWith%20compilation%20being%20this%20high%2C%20it%20usually%20was%20because%20ad%20hoc%20queries%20were%20used%20at%20high%20rate.%26nbsp%3B%20To%20prove%20this%2C%20we%20pulled%20out%20%E2%80%9CSQL%20Plan%E2%80%9D%20out%20of%20%E2%80%9CCache%20Object%20Counts%E2%80%9D.%26nbsp%3B%26nbsp%3B%20It%20was%20almost%20over%20160%2C000%20(see%20screenshot%20below)!%26nbsp%3B%26nbsp%3B%20This%20counter%20meant%20that%20there%20were%20almost%20160%2C000%20ad%20hoc%20plans%20in%20the%20plan%20cache!%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F68305iDAE34E4D676853F8%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CH2%20id%3D%22toc-hId-1764907189%22%20id%3D%22toc-hId-1765742148%22%3ESolution%3C%2FH2%3E%0A%20%20%3CP%3EMany%20times%2C%20ad%20hoc%20queries%20at%20high%20rate%20can%20cause%20issues%20such%20as%20wasting%20CPU%20to%20compile%20and%20wasting%20plan%20cache%20memory.%26nbsp%3B%26nbsp%3B%20We%20had%20this%20customer%20enable%20%E2%80%9CForced%20Parameterization%E2%80%9D%20for%20the%20database.%26nbsp%3B%20After%20that%2C%20the%20CPU%20dropped%20to%2010-20%25%20even%20with%20highest%20user%20load%20and%20performance%20became%20super%20fast.%3C%2FP%3E%0A%20%20%3CP%3ESometimes%2C%20a%20solution%20may%20be%20simpler%20than%20you%20might%20have%20thought.%26nbsp%3B%20Just%20keep%20this%20option%20handy.%26nbsp%3B%20If%20things%20don%E2%80%99t%20work%20out%2C%20it%E2%80%99s%20easy%20to%20back%20it%20out.%26nbsp%3B%20Over%20the%20course%20of%20troubleshooting%20performance%20issues%2C%20I%20have%20used%20this%20trick%20many%20times.%26nbsp%3B%20I%20hope%20this%20serve%20as%20a%20reminder%20for%20you.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EJack%20Li%20%7C%20Senior%20Escalation%20Engineer%20%7C%20Microsoft%20SQL%20Server%20Support%3C%2FP%3E%0A%20%20%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fjackli8898%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Etwitter%20%3C%2FA%3E%20%7C%20%3CA%20href%3D%22http%3A%2F%2Fdiagmanager.codeplex.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20pssdiag%20%3C%2FA%3E%20%7C%20%3CA%20href%3D%22http%3A%2F%2Fsqlnexus.codeplex.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Sql%20Nexus%3C%2FA%3E%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-318560%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Apr%2022%2C%202015%20Some%20of%20the%20features%20have%20been%20around%20for%20a%20long%20time.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-318560%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPerformance%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jan 15 2019 04:34 PM
Updated by: