Upload
brent-ozar
View
10.141
Download
0
Embed Size (px)
Citation preview
Last Season's Performance Tuning Techniques
Brent, Ozar, Founder, Brent Ozar Unlimited
Erik Darling, Consultant, Brent Ozar Unlimited
Moderated By: Damu Venkatesan
If you require assistance
during the session, type
your inquiry into the
question pane on the right
side.
Maximize your screen with
the zoom button on the
top of the presentation
window.
Please fill in the short
evaluation following the
session. It will appear in
your web browser.
Technical Assistance
Thank You to Our Sponsors
Quest helps our customers reduce tedious
administration tasks so they can focus on the
innovation necessary for their businesses to
grow. Quest® solutions are scalable,
affordable and simple-to-use, and they deliver
unmatched efficiency and productivity.
Combined with Quest’s invitation to the global
community to be a part of its innovation, as
well as our firm commitment to ensuring
customer satisfaction, Quest will continue to
accelerate the delivery of the most
comprehensive solutions for Azure cloud
management, SaaS, security, workforce
mobility and data-driven insight.
Melissa Global Intelligence provides data
quality and identity resolution tools for SQL
Server and .NET to perform the tasks of
ensuring new incoming data is in good
condition and maintaining data quality over
time. Utilizing comprehensive reference
datasets, Melissa solutions verify, standardize,
dedupe, enrich, geocode and update global
contact data including address, name, email
and phone data. Since 1985, Melissa has
helped businesses of any size improve data
management, data governance and business
analytics with clean, reliable and actionable
data. Melissa is a Registered Microsoft Partner
with international offices in the U.K, Germany
and India.
Nutanix makes IT infrastructure invisible with
an enterprise cloud platform that delivers the
agility and economics of the public cloud,
without sacrificing the security and control of
on-premises infrastructure. Whether
upgrading existing infrastructure or deploying
new environments, Nutanix is the ideal
solution for virtualized SQL Server
deployments.
• Consolidate SQL Server databases and VMs onto a single
converged platform
• Run Microsoft SQL Server with other critical workloads,
without sacrificing performance or reliability
• Remove the complexity and reduce the costs of traditional
storage
• Eliminate planned downtime and protect against
unplanned issues to deliver continuous availability
• Keep pace with rapidly growing business needs
Access to online
training and
content
Enjoy discounted
event rates
Join Local Groups
and Virtual Groups
Get advance notice
of member
exclusives
PASS is a not-for-profit organization which offers year-round learning opportunities
to data professionals.
Check Out Your Member Benefits Today.
www.pass.org
Make the Most Out of your PASS Membership
Where Data
Professionals Connect,
Share, and Learn
REGISTER NOW www.PASSsummit.com
OCT 31 – NOV 3 SEATTLE WA
Developer stuff
What are you wearing to PASS?
Erik Darling
SQL or whatever
You’re a carb.
DBA stuff
Bo-ring, let’s go take pictures of food we’re not gonna eat.Ew. Old people.
Over it.
Quelle horreur!
WANNA FOLLOW ALONG?
Get the slides & demos: BrentOzar.com/go/fashion
Brent Ozar
PRETTY GOOD AT DATABASES
Microsoft Certified Master, working with SQL Server for 20+ years.
EXTREMELY BAD AT FASHION
And plenty of photo albums from over the years to prove it.Facebook.com/BrentOzar
@BrentO
LinkedIn.com/in/BrentOzar
Today’s topic: unfashionable performance skills.
WE ALL LEARN THIS STUFF AS WE GO
We don’t grow up with Stacy London and Karl Lagerfeld giving us style advice, nor does Joe Celko mentor us as we write our first T-SQL.
WE JUST NEED TO CATCH UP
Every now and then, we need to revisit our clothes and our database skills and make sure that they still work in today’s world.
WE THINK WE’RE COOL AT THE TIME
We emulate things we see on TV or read about online, like copy/pasting code from random answers on Stack Overflow or techniques from really old blog posts.
Rocket science fashion told me,”Fragmentation is really bad.”
REMEMBER YOUR PARENTS’ SQL SERVER?
It had two hard drives for the data files, and two hard drives for the log files,and a vinyl record player to install SQL Server.
SO WE WATCHED FRAGMENTATION CAREFULLY.
And we watched any indicators that might mean fragmentation was happening.
REMEMBER WINDOWS DEFRAG?
It shuffled your pages around to put them in order because sequential access was so much faster than random access.
“Page splits mean fragmentation is happening.”
SQL SERVER STORES STUFF IN 8KB PAGES.
You saw How to Think Like the Engine last year at the Summit, right?
THE NEW PAGE WOULDN’T BE IN ORDER.
It’s added wherever there happened to be free space in the data file. That meant fragmentation! So we watched page splits carefully. I tracked them on my Swatch.
A FULL PAGE IS LIKE A POPPED COLLAR:YOU CAN’T POP IT ANY FURTHER.
When you try to insert a new row into it, or update an existing row to make it wider, SQL Server can’t cram any more data in – so it splits the page.
Perfmon’s Page Splits/sec is the Milli Vanilli of metrics.
GIRL YOU KNOW IT’S FALSE.
Even if you believe out-of-order pages on disk represents a performance problem, the Page Splits per Second counter doesn’t mean things are getting worse.
And if you’ve been adjusting Fill Factor in order to reduce page splits per second, you might have been making things even worse.
Like wearing a formal ”gold” watch with an OP shirt, print pants, and sneakers.
I know what you’re up to
When you create temp objects, it’s a real coin-toss
• One day it might be a temp table
Past results, future performance
You’ve heard some bad things about table variables
• Modifications are forced serial
• You always get a 1 row estimate
• Unless you RECOMPILE
And you’ve finally let go of the only-in-memory mantra
• Big surprise, a 10 GB table won’t fit in 8 GB of RAM
But you say he’s just an estimated plan
But on the flip side, what about SELECT queries?
• Well, they still can go parallel with a table variable
• But…
I did what I was told.
They told me magnetic hard drives were:
• Really fast at sequential activities
• Really slow at random activities
Then they told me that SQL Server’s:
• Log file writes were sequential
• Data file reads & writes were random
So they said I needed to keep log files on their own volume so they’d be sequential and fast.
(They also said striped socks and striped shorts match.)
Some of this is still true today.
Even today, solid state drives are:
• Really fast at sequential activities
• Really slow Sorta fast at random activities
(Striped socks and striped shorts do actually match, but it turns out that you don’t want matchy-matchy.)
But part of it is a lie.
SQL Server’s log file writes are sequential –but only for one database’s log file writes.
Most of us have more than one database.
And our databases don’t take turns to write.
And when you put more than one log file on a volume, that volume’s access is random.
(They also said striped socks and striped shorts match.)
Inseparable.
Even when you try to separate data & logs,you’re usually using one pool of disks.
If they’re sharing drives anyway,especially sharing with multiple servers,what’s the point of separation?
To make your servers more reliable? Debunked:https://www.brentozar.com/archive/2017/06/separating-data-log-files-make-server-reliable/
Separating log filesis like wearing racing stripes.
It doesn’t magically make you faster or more reliable.
NANANANANANANANANANANANA
There are some things I always hear about CTEs
• They don’t use indexes
• They’re in memory
• SQL persists the results like a temp table
• They’re better than derived tables
It’s a cruel, cruel winterDressing me in acid washed jeans
Many people saying these things call themselves “Senior”
• These are pretty lousy misconceptions
• Especially for people with 10+ years of experience
CTEs have many fine uses
• Making query intent more clear
• Paging queries
• Getting around ‘wide’ queries
It’s the thought that counts,and some gifts aren’t thoughtful.
THE MISSING INDEX HINTS ARE JUST A QUICK GIFT.
SQL Server only casually throws these out as a byproduct of building a plan.
OR YOU COULD PICK A WORSE ONE.
I actually bought this entire outfit with my own money. Top down: mullet, gold chain over sweater, wannabe Cosby sweater, wool pants, boat shoes. Not pictured: taste.
YOU COULD PICK A BETTER GIFT YOURSELF.
SQL Server only puts a few milliseconds into building these, and you could do way, way better by thinking through the query yourself.
Missing index hintsaren’t thinking too much.
YOU ONLY SEE THE FIRST ONE.
Go into the XML and search for the word “missing” to check for more.
FIELDS MAY BE MISSING ENTIRELY.
SQL Server typically suggests indexes for the WHERE clause and ignores ordering, grouping, having clauses.
When you see a missing index, smile, nod, and come up with your own.
FIELDS AREN’T SHOWN IN ORDER.
It’s just a comma-delimited list of things you should think about indexing.
Flags of our fathers
It used to be that if you wanted performance
• Especially if you’re running a ‘big box’
• You needed about one trace flag per core
If tempdb performance sucked
• 1117 and 1118
If you hit CMEMTHREAD waits
• 8048
If stats didn’t update often enough automatically
• 2371
The list goes on and on
1204
1222
2301
2389
2390
2549
2562
3226
4199
7470
9024
Hey kid, want some Trace Flags?
You
what?
No more rocket surgery
SQL Server 2016 makes some good choices for you
• Trace Flags for tempdb are automatic
• And they only apply to tempdb
• Plus smart tempdb config at startup
Auto update stats threshold based on # of rows
• Just like 2371!
Automatic memory partitioning
• No more 8048!
• No more CMEMTHREAD!
• Kinda…
Your performance skillsmight be out of fashion.
WERE YOU SURPRISED BY STUFF TODAY?
It’s okay: so were we as our careers progressed. Learning is a good thing.
GOOD NEWS: WE’VE GOT A PRE-CON TO HELP.
We’re teaching Expert Performance Tuning for SQL Server 2016 & 2017.
Your job is making SQL Server go faster, but you haven’t been to a performance tuning class since 2016 came out. You’ve heard things have gotten way better with 2016 and 2017, but you haven’t had the chance to dig into the new plan cache tools, DMVs, adaptive joins, and wait stats updates.
In one fun-filled day, Brent Ozar and Erik Darling will future-proof your tuning skills. You’ll learn our most in-depth techniques to tune SQL Server leveraging DMVs, query plans, sp_BlitzCache, and sp_BlitzFirst. You’ll find your server’s bottleneck, identify the right queries to tune, and understand why they're killing your server. If you bring a laptop with SQL Server 2016 and 120GB free space, you can follow along with us in the Stack Overflow database, too.
Learn more now: BrentOzar.com/go/summit