Performance Tuning


Title and name of the article: SQL Server Performance Tuning

SQL Server performs fast enough most of the time. Only the most successful companies require SQL Server Performance Tuning. Why? Because SQL response becomes too slow.

 

What is SQL Server Performance Tuning?

SQL Tuning is when slow performing T-SQL is messed with and all of a sudden it returns really fast. Very simple.

 

Examples of SQL Server Slowness:

  1. You have a website, fill out a “Search” form, hit “Search” and it takes too long to come back.
  2. You have an app, and the app takes too long to respond.
  3. You have a SQL Server, and when you look at the Performance Monitor, it shows CPU at 100%.
  4. SQL Agent jobs can not finish in time or start spilling over into production or high usage windows.
  5. Reports take too long to process. Or never finish.
  6. T-SQL runs fast with one set of parameters, but with others it is slow or never completes.
  7. Many more…

Most often, what we hear is “this was fast (or OK) before, and now it’s crazy slow”

 

Slow SQL Shows Up Only In a Few Ways:

  1. T-SQL was fast before and gradually it became slower.
  2. T-SQL was always slow (or never finishes).
  3. T-SQL was fine before, but after a change (often seemingly unrelated), sql is now slow.

 

Reasons Why SQL Servers Become Slow

There can be many reasons. Here are a few we see most often in the field:

  1. Lack of good SQL Server Maintenance in place. This affects backups, index and statistics maintenance, corruption checks, etc.
  2. Lack of Configuration Optimization of the SQL Machine. You need settings tweaked in multiple places (yes, BIOS!), Win OS, Security, Group Policy, Active Directory, Instance Settings, database settings
  3. Faulty Architecture. Good example is database is setup with one data file and that’s it. It should have multiple files, spreading the load to multiple drives.
  4. Bad Indexing. Lack of indexes, too many indexes, indexes on wrong columns, duplicate indexes, almost duplicate indexes, indexes that can be merged, missing index warnings, indexes with a high cost, but do not provide any help.
  5. Change in Size of Data. Data has grown over time, and now SQL is processing millions or billions of rows, instead of a couple of thousand, as it was initially designed.
  6. Bad queries. Either old queries become slow, or new ones use up all of the SQL Server Power available, leaving other queries starved for resources.
  7. Bad Database Design. A good example we see a lot, is the database has a single data file. And many others.
  8. Code Deployment. After code deployment, things started to run slow.
  9. Change in Infrastructure. This one you may know about, or you may not. A good example would be storage or network changes. This usually makes all queries become slower.
  10. Failing hardware. Certain type of hardware failures, such as storage or networking, will not break the SQL Server, but it will make it re-try the same operation a couple of times.
  11. And Many More…

 

How SQL Slowness Shows Up

 

Happens in two ways:

  1. Easy to catch slowness. You know app screen used to take half a second and now it’s been 2 minutes, and is still spinning and hasn’t finished.
  2. Tougher to catch slowness. When query used to take 4 min 37 seconds, and now it is taking 6 min 11 seconds. To catch something like that, you have to have some type of SQL Server Monitoring in place.

 

What To Do When SQL Server Is Slow

Don’t restart the server, or start pulling cords. You want to collect some data first. Or you won’t know why it happened. Which will pretty much guarantee the issue is going to come back.

You want to narrow down why SQL is running slow. Couple questions you want to answer:

  1. Is there any T-SQL being blocked right now?
  2. Is there T-SQL that has been running for a long time or consumed lots of resources?
  3. Are there transactions that are open and never closed?
  4. Is one query slow or is everything slow (possibly a system wide change in play)?

Then depending on what the answers are, you want to narrow down to an exact T-SQL call, ideally with actual parameters that were used.

 

Mistakes People Make With SQL Server Performance Tuning

  1. Reboot too fast. This is one of the worst things you can do, because of the multiple issues this creates. Number one, you just wiped out all of the SQL data collection (DMV) tables. Number two, you did not look into what else was also running at the same time. Unless you have a SQL Monitoring tool, or your own custom data collection scripts that grab necessary performance data – a reboot will wipe out those performance stats which can help identify what went wrong.
  2. At the other end of the spectrum, Reboot is too slow. During production times, if you know a reboot will “fix” the issue, it may be better to reboot, and have a few minutes of an outage, rather than to try to troubleshoot for 30 minutes and then have to reboot anyway. It may be better to reboot. Then spend some time to prepare what you will do next when this issue hits again. Prepare some scripts you will run. Write some jobs that will auto-capture some problematic details.
  3. Not knowing what is slow. The more specifics you have about what exactly is slow, the easier it is to troubleshoot
  4. Not knowing exact parameters sent into a slow running query.
  5. Not preparing for the next slowness problem. Slowness should never surprise you. You need to know steps to take before it happens.

 

When It Is Impossible To Tune SQL Server (Or Crippled Tuning):

  1. You lack enough visibility into the issue. For example, you are not system admin on the server. This will limit what you can look at.
  2. You can’t run some tools. You don’t know any. Never used any.
  3. The older the SQL Server version, the harder it is to tune performance.
  4. The older the Win OS, the harder it will be.
  5. Not being able to talk to people responsible for every layer (Windows sys-admins, storage admins, networking admins, etc.)
  6. Not having any tools or scripts ready to go.
  7. Taking too long. Any problem can be solved— eventually. The question is do you have the time it may take to tune, or is it better to pull in someone who does only tuning?
  8. Not allowed to make changes.
  9. No place to test in.
  10. Making Performance tuning someone’s problem who has never done this before.

 

How To Be Ready For SQL Server Performance Slowness and Tuning

  1. Know what you will do next time. Especially if you have hit performance problems before. Spend time now to educate yourself about what to do when it happens. Fair warning: this is not an easy thing to learn. It’s a lot easier if you have a good understanding of how bits and bytes move, or a decent Computer Science understanding, or both.
  2. Dedicate someone. Bring in a database administrator, database developer or programmer. Just know it will take time. Especially if this person doesn’t deal with performance problems everyday.
  3. Make performance someone else’s problem. Hire a company like ours. We’d love to help! We do tuning every day and have done it for over a decade now.

 

Typical SQL Performance Tuning Results

Sometimes changes can make TSQL run 20,000% faster, sometimes 50%, other times slicing 20% off the cost is great help. Bottom line – tuning results vary. They vary based on the complexity of the query, how much tuning has gone into it already, etc. But we rarely can’t make TSQL perform faster.

 

Make SQL Performance Tuning someone else’s problem. Hire someone. We’d love if you chose us, and we would love to help! We do tuning every day, and have done it for over a decade now!

 

FREE Executive
Report

21 Revealing Questions You Should Ask Any SQL Server Consultant Before Giving Them Access To Your Database

We will email you a copy of our report, "How to Hire Database Consultant – 21 Revealing Questions You Should Ask Any SQL Consultant Before Giving Them Access To Your Company’s Database". !

Send Us a Message

Thank you for contacting us!

See What Other IT Managers Are Saying About Us...

Yielded some very impressive results

The breadth and depth of knowledge of the Microsoft SQL Database platform and ancillary technology stack that Mark brought, has already yielded some very impressive results from both a physical and logical architecture perspective.

Preferred to stay anonymous

Quickly identified and fixed SQL performance issues we had struggled with for weeks

Mark was able to quickly identify and fix several SQL performance issues we had been struggling to trace for several weeks. Additionally, he made several other recommendations and configuration changes that had a significant positive impact on database performance.

Nick Kelland
Vice President of Ops & IT, SJV & Associates

With little notice, Mark was able to find and fix a number of different SQL misconfigurations and wasteful practices.

After a weekend of work, the customer realized a 60% decrease in CPU utilization as a direct result of Mark's work.

Jason Milgram
Azure Practice Director, Champion Solutions Group, AllAware.com

Complex and heavy 5,000+ concurrent connection databases need tuning, indexes, best practices, up-time, and smooth performance over all

He has mastered the understanding of complex, heavy load TSQL transactions. When tuning, database structure, indexes, stored procedure, best practices, up-time, and smooth performance are all important, Mark is the type of DBA who truly knows how to keep these high standards.

Tim Janssen
Application Manager, Service King