30 October 2017

The Owl Has Been Fed

After two and one half years of on-again off-again effort - mostly a couple months up front and a few weeks at the end, I finally completed the final section in the Duolingo Spanish curriculum.  They optimistically rate me at 57% fluency, but I take that with quite a few grains of salt.

What it seem to mean is that, given time to think about it, I can recognize many of the major constructs of the language and piece together the meaning of various words and phrases.  

However, it doesn’t involve a lot of vocabulary and I still display an almost complete lack of verbal fluency.  I do notice I can pick out a little more of the commentator dialog when watching soccer, but cannot understand snippets of conversation in real-life.

All-in-all it was an enjoyable refresher for my 20-year old Spanish minor and, if I spend some time each day keeping the 62 sections colored gold, I would expect the average time to recognize and/or generate a word or phrase will continue to drop, as well as improved competence with the various verb tenses which came at a rapid pace near the end.

Next up will be "Duolingo Stories" which is a beta product that consists of four sets of ten "mini stories" that focus more on listening and reading comprehension for intermediate to advanced learners.  Should be a nice supplement to the basics supplied by the original courses and a good way to build out some more vocabulary and develop an "ear" for the language.

04 October 2011

JOIN Me

This month's T-SQL Tuesday (#23) is hosted by Stuart Ainsworth (Blog | Twitter) and he has selected JOINs as this month's topic.


I thought the topic seemed mildly interesting from a deep technical perspective.  If you agree, you might find some good reading here or here, and I've even touched on the topic of Legacy JOINs.  However, I do deep technical writing much of each day, and I sometimes like to relax and ramble a bit in the blog.  If it's SQL Server related rambling, so much the better.


Besides, I don't know anything particularly deep or technical about JOINs in SQL Server.  Come to think of it, there are a lot of deep technical things I don't know about SQL Server in general that can be solved by a few JOINs.


Here some JOINs that have helped me to solve deep technical problems in SQL Server.  Maybe they've helped you, too.


JOIN... the Professional Association for SQL Server
JOIN... your local SQL Server User Group
JOIN... your SQL Server Peers for a SQL Lunch
JOIN... an online SQL Server Forum
JOIN... an online SQL Server Community for the Inside scoop
JOIN... twitter for the #SQLHelp hash tag
JOIN... your workmates for lunch


All those things you don't know about SQL Server?  The places above are absolutely loaded with folks who DO know them... oftentimes even the coworker you didn't realize had seen it before.  And, do you know what else?  To somebody less experienced than you with SQL Server, you will be one of the ones with the answer.


So JOIN up with somebody else and promote some SQL Server excellence.

05 May 2011

Sometimes It's Not The Database

The other day for Meme Monday I put together a list of 9 Things That Go Wrong With SQL Server That Aren't The Disk.  That got me to thinking about the old "It's the database" stand-by for when The Application isn't working right.  Many of us have been there... The Application is acting up, and the knee-jerk response by the development or support team is, "it's the database"
The Database... Seriously?

The frustrating thing with this is when the problem is found to lie in The Application or in the computing infrastructure, as it often is, but all the business stakeholders remember hearing was "it's the database."

Then there are the few cases when it's true... a broken clock is right twice a day, after all.  This happens just often enough that the other support and infrastructure teams sometimes actively refuse to do any troubleshooting unless, and until, the DBA can prove that the problem lies with a non-database component.  Cross-discipline troubleshooting/resolution team?  Not when it's obviously the database

I was at a shop that recently had some recurring database connectivity issues with helpful error messages like "SQL Server Does Not Exist Or Access Denied", "Timeout Expired" and "General Network Error."  Now, you know where the finger points when the words "SQL Server" appear in an error message.

So the database team dutifully combed event logs, performance monitor and server side trace data, and was able to demonstrate pretty conclusively that nothing was wrong with the database or the server it was on.  Till the next time The Application got busy and started throwing errors, when they had to do it all over again.

What it ultimately came down to was the owners of The Application server had turned off connection pooling while troubleshooting an installation issue weeks earlier.  It turns out that, by default, Windows only allows 4000 sockets (ports) per destination IP address.  With the amount of database server traffic generated by the application server -- it had recently been "consolidated" -- they were able to hit that threshold pretty reliably.

Microsoft has a KB article on considerations for servers with connection pooling disabled that describes this nicely:
If you rapidly open and close 4000 sockets in less than 4 minutes, you will reach the default maximum setting for client anonymous ports, and new socket connection attempts fail until the existing set of TIME_WAIT sockets times out.
After weeks of recurring connection errors with the word "SQL Server" in them, the connection pooling issue was quietly fixed by upping the socket limit to some random number like 65535 :) and The Application performance returned to normal.  I'm sure you can guess the words that were never spoken to the business stakeholders... "It's Not The Database."

02 May 2011

Meme Monday: It's not the disk!

Thomas LaRock, aka @SQLRockstar (not THAT rock-star), has a fun way to get the blog month started: Meme Monday.  This month, it's just a list of 9 things we frequently see go wrong with a database server that are NOT related to disk issues.

In no particular order...

9. Good old boys
8. "It's just like a spreadsheet" database design
7. Out of date statistics 
6. Improperly partitioned tables (see 7 above)
5. Good old boys
4. Microsoft patches
3. Vendor software
2. Internally developed software
1. Good old boys

I couldn't believe the number of disk related problems that kept coming to mind while putting this nod-disk related list together - especially when considering the SAN as a black-box hard disk.

You may have noticed that Good old boys made the list slightly more than once.  Unfortunately, that is based on years of direct observation.  I'm even going to manufacture a statistic to support its frequency in the list:

Nearly 60% of production database outages are, directly or indirectly, caused by the incompetence fostered by Good old boy cronyism...  and that's NOT the disk.

22 April 2011

Nice Teeth

Some of the commentary about the recent Amazon "Cloud" has focused on the reliability of cloud offerings, and their aggressively high availability Service Level Agreements (SLA).  Just for reference, the Microsoft Azure SLA is 99.9%, and  Amazon’s availability SLA happens to be 99.95%

Didn't see that one coming
The interesting thing about an SLA is that it doesn't make the service, or its servers, more reliable, it just specifies penalties and/or contract options for when the services become unreliable unavailable.  To go with their aggressive promises, the SLA usually provides creative definitions for “available” to help ensure the SLA is met, e.g., if the service drops half your connections, it’s still available, and you’re Simply Out of Luck

If a company actually uses its data to make money, the SLA doesn't fund the enterprise while the service is unavailable.  And the SLA typically doesn’t cover service degradation, just the creatively defined “availability.”  It also doesn’t manage or repair your tarnished reputation with your customers or your business.

Want to bet your reputation, and that of your organization on the cloud?  It’s probably a good bet, since you’re likely not getting 99.9% uptime from your own servers.  But be prepared when that .1% kicks your reputation in the teeth.

13 April 2011

Passing the Word

So, I had this long running trace going through profiler last night (don't worry, it was just a DEV thing) and when I came in this morning, profiler had ended the trace with the following Trace Error:


-- 'Ӈ耇' was found in the text of this event.
-- The text has been replaced with this comment for security reasons.


At first, I feared a Chinese Injection Attack, but after a little digging around, I was able to reproduce it by running a trace, then stopping the traced SQL Service while profiler was still running the trace.  It's apparently a built in error code.

I thought I had seen similar behavior in the past around queries that include the word "PASSWORD" in them, so I started playing around to see if I remembered correctly.  It turns out my recollection wasn't perfect.

When you run a security statement that might contain a login's password, SQL Profiler will remove the TextData from the event.

Here are a few such statements where TextData is stripped:

sp_password
CREATE LOGIN
ALTER LOGIN


Of course, before rediscovering this, I had already run a statement using the word "PASSWORD" and profiler happily displayed my query text.  I thought I'd share, not because of the query is so profound, but because I wrote it simply for the joy of writing it.


CREATE DATABASE PASSWORD;
go
USE PASSWORD;
go
CREATE SCHEMA PASSWORD;
go
CREATE TABLE PASSWORD.PASSWORD (PASSWORD SYSNAME);
go
INSERT PASSWORD.PASSWORD.PASSWORD (PASSWORD) VALUES ('PASSWORD');
go
CREATE INDEX PASSWORD ON PASSWORD.PASSWORD.PASSWORD (PASSWORD);
go

SELECT  PASSWORD.PASSWORD.PASSWORD.PASSWORD
FROM    PASSWORD.PASSWORD.PASSWORD WITH(INDEX(PASSWORD))
WHERE   PASSWORD.PASSWORD.PASSWORD.PASSWORD = PASSWORD.PASSWORD.PASSWORD.PASSWORD;
go

DROP TABLE PASSWORD.PASSWORD;
go
DROP SCHEMA PASSWORD;
GO
USE TEMPDB;
go
DROP DATABASE PASSWORD;
GO


It's also amazingly blue because nearly every word is reserved.  If you'd like to play with it, it should run for you on any system that doesn't already have a database named "PASSWORD"

I hope you also find such light-hearted simple ways to enjoy the tools you work with.

08 March 2011

The Absolute Best

This month's T-SQL Tuesday is hosted by Jes Schultz Borland ( Blog | Twitter ) and she has selected Aggregate Functions as this month's topic.


Besides helping data make the transformation to information and to tell their story better, I would suggest that Aggregate Functions are the basis for all meaningful communication. 

Big claim, right?  Just remember, it can't be the worst claim without an aggregate function.  To illustrate, I'm going to tell a short story two times.  One time without aggregate fuctions, and one time with aggregate functions.

The story starts with Bobby.  Yes, that's Bobby Tables, but he's all grown up now, and sells leather-free cowboy boots.

Bobby went to the computer store and purchased a post-PC device.  He had just received his annual sales bonus, and wanted to splurge on something new.  After making it through the checkout process and returning home, Bobby was pleased to discover that he could access his home network through the device.  Bobby was content with his purchase.

Here it is again.  See if you can spot the aggregate functions...

Bobby went to his favorite computer store and purchased the market leading post-PC device.  He had just received his largest annual sales bonus, and wanted to splurge on something new.  After making in through the most customer friendly checkout process and returning home in record time, Bobby was pleased to discover that this device had the easiest setup for accessing his home network.  Bobby thought this was the best purchase he had ever made.

Did you spot the aggregate functions?

  • favorite computer store: having preference = max(preference)
  • market leading post-PC device: having market_share = max(market_share)
  • largest annual sales bonus: having bonus = max(bonus)
  • most customer friendly: having customer_experience = max(customer_experience)
  • returning home in record time: having transit_time = min(transit_time)
  • easiest setup: having setup_difficulty = min(setup_difficulty)
  • best purchase ever: having buyers_remorse = min(buyers_remorse)

Whether it's to define What's in a Name, or to describe an evening out on the town, we can't communicate effectively without aggregate functions, and we can't learn anything from our data without them.  Without aggregate functions, there is no superlative.  Nothing is better than average, nothing comes first, nothing comes last, there is no typical.

So, next time somebody tells you the bathroom is the first door on the left, or you do something the fastest, or you are rated the highest, take a moment to thank your aggregate functions.  

They are the best.

28 February 2011

Are you my type?


Sometimes it's fun to take a look at how people tick, even when those people are, well, myself.

I've taken the online Myers Briggs Type Indicator a few times over the years, and typically seem to wind up with INTP.

Beyond telling me that I'm slightly out-of-touch with the reality of day-to-day living, I don't know how much life-altering significance there is in this type of thing beyond explaining why I'm always first in the meeting to shout "Bingo!"

There are a few good sites explaining what the various personality types are.  PersonalityPage has a pretty good INTP overview.

Here is the description that Myers Briggs provided, which, aside from saying I should be a master designer of all kinds of theoretical systems, also gives me credit for being pragmatic - about ideas, so it's not quite completely contradictory.


Rational Portrait of the Architect (INTP)
Architects need not be thought of as only interested in drawing blueprints for buildings or roads or bridges. They are the master designers of all kinds of theoretical systems, including school curricula, corporate strategies, and new technologies. For Architects, the world exists primarily to be analyzed, understood, explained - and re-designed. External reality in itself is unimportant, little more than raw material to be organized into structural models. What is important for Architects is that they grasp fundamental principles and natural laws, and that their designs are elegant, that is, efficient and coherent.

Architects are rare - maybe one percent of the population - and show the greatest precision in thought and speech of all the types. They tend to see distinctions and inconsistencies instantaneously, and can detect contradictions no matter when or where they were made. It is difficult for an Architect to listen to nonsense, even in a casual conversation, without pointing out the speaker's error. And in any serious discussion or debate Architects are devastating, their skill in framing arguments giving them an enormous advantage. Architects regard all discussions as a search for understanding, and believe their function is to eliminate inconsistencies, which can make communication with them an uncomfortable experience for many.

Ruthless pragmatists about ideas, and insatiably curious, Architects are driven to find the most efficient means to their ends, and they will learn in any manner and degree they can. They will listen to amateurs if their ideas are useful, and will ignore the experts if theirs are not. Authority derived from office, credential, or celebrity does not impress them. Architects are interested only in what make sense, and thus only statements that are consistent and coherent carry any weight with them.

Architects often seem difficult to know. They are inclined to be shy except with close friends, and their reserve is difficult to penetrate. Able to concentrate better than any other type, they prefer to work quietly at their computers or drafting tables, and often alone. Architects also become obsessed with analysis, and this can seem to shut others out. Once caught up in a thought process, Architects close off and persevere until they comprehend the issue in all its complexity. Architects prize intelligence, and with their grand desire to grasp the structure of the universe, they can seem arrogant and may show impatience with others who have less ability, or who are less driven.


Have you found these types of evaluations to be useful?  Do certain types work better together on different projects, or does it all depend on how each type is manifested?

18 January 2011

The Abaculator

I enjoy using Red-Gate products.  Really.  I even suspect that the SQL Prompt code-completion product reduces the time it takes me to write SQL.

I enjoyed their recent add likening Hand Coding your SQL to an Abacus, while SQL Prompt was likened to a Calculator:
 

Think how much more efficient you could be with this product!  We can even get supporting evidence from the inter-webs showing just how slow the Abacus really is when compared to our electron chomping marvel:

Oops!  I had a feeling that the abacus would turn out to be pretty fast, but three times faster?  And that's just a virtual abacus - think of the power and air conditioning costs this 9 year old mathematician will save.

Now I'm slightly embarrassed to be a SQL Prompt user.

Red-Gate might want to take a lesson from MathSecret on this one.

13 January 2011

Hacking The Doctor's Credentials

Brent Ozar just published his Microsoft Certified Master certificate along with a call for enhancements.

I never excelled at Photoshop Tennis, but thought I'd take a stab at it using Microsoft's recent jab at VMWare as a starting point.


Of course, Brent's breadth and depth of SQL and IT experience, along with his presentation and writing skills, do a SQL master make.

Congratulations on the MCM!

10 January 2011

Lies, Damned Lies, and Resolutions

Thank you to Microsoft MVP and rampant blogger, tweeter, and silver-screen maven Jen McCown for hosting this month's T-SQL Tuesday (#14).  Congratulations, Jen! (Yes, I'm a fan of the Midnight DBAs)

Many people claim they don't make new year resolutions.  A few of them are telling the truth.  The rest have secret resolutions they won't disclose for fear of failing publicly.  I fall in the latter category.

With this in mind, I have not resolved to get a SQL Server Certification: I have pre-purchased an Exam 4-Pack to cover a double MCITP and am sitting the MCTS: SQL Server 2008, Database Developer today.

I have also not resolved to participate in a T-SQL Tuesday:  I am writing and submitting my first post right now. Insecure?  Yep.  Letting it trip me up?  Not this time.

These things started off as secret professional resolutions, but I've decided to take action on them.

I still have other secret resolutions, mainly recycled secret failures from years past.  Will I be acting on them?  Some yes, and some no.  Will I put them out there as "resolutions" and risk the public failure?  I guess so.
  • That 100 extra pounds (45 Kg / 7 stone) I've acquired since settling down?  Nope.  Not going to resolve it.  I am, however, "resolving" to spend some quality time with the exercise bike so I can manage the stairs better and let the weight take care of itself.  You have my permission to call me on it in a couple months.
  • Replace the broken dishwasher?  Nope.  I'm going to hire somebody who's good at it to do it for me.  I make my living specializing in SQL Server and don't expect my clients to be especially brilliant with database systems.  Why should I expect to hack together a home repair that's anything but mediocre?  A quick note here: my house of full of mediocre but largely functional do-it-yourself jobs, so letting this go is a bit of a challenge for me.
  • Speak at the local SQL Server User Group?  If they'll have me again.
So, nothing spectacular, just a few public steps out of the comfort zone.  Won't you join me?

You can't afford what?

Tibor Nagy recently did a nice intro to Populating a SQL Server Test Database with Random Data.

It was a good primer to generating gobs of data, but part of the problem the solution was addressing wasn't technical: "I heard about some excellent commercial tools but they are expensive and my company cannot afford them."  The first commercial tool that comes to mind is Red Gate's SQL Data Generator, which isn't expensive by any measure, least of all a DBAs time.

It sickens me when a company can afford to squander days of a $50/hour DBA's time hand rolling something that could be had commercially for only a few hundred dollars.  How can a company that can afford a DBA not afford a simple tool that will save days of effort and free up that expensive human time so it can be spent solving business problems?

To illustrate, a company where I used to work had an extravagantly expensive suite of database design, monitoring, and migration tools.  That was well and good, but the migration tool took hours to compare a simple database, and often didn't succeed (though you still had to wait hours to find out).  The result was a lot of squandered time and production releases that were often missing database objects or permissions.  Ouch!

This company frowned on any suggestion to evaluate a different tool-set, so one of the DBAs, who believed more in getting things done than toeing the line (this gave him a reputation as a something of a cowboy), downloaded a trial copy of Red Gate SQL-Compare and started playing with it.  This DBA's compare times went from hours to minutes (or less) and he no longer had last minute manual compare frenzies prior to production releases.

After a few more DBAs started using the evaluation - the tool completely paid for its purchase price in the first week of evaluation - the company finally realized that all this "free" salary time was being squandered, and decided to make the purchase.  The enterprise-class database tool was put to rest, along with its rather generous annual maintenance fees, and they never looked back.

Though I have yet to work there, someday I will work at or run a shop where each DBA has his or her own annual tools budget equal to roughly a single day's pay that can be used to purchase simple tools about which they are passionate.  They gain experience managing a corporate budgetary item and get the power and confidence to use that money to save even more money without any corporate red-tape, thank you very much.

15 November 2010

Nearly Competent

I thought this was a pretty good insight from Jeff Atwood over at CodingHorror…
You can tell a competent software developer from an incompetent one with a single interview question:
What's the worst code you've seen recently?
If their answer isn't immediately and without any hesitation these two words:
My own.
Then you should end the interview immediately. Sorry, pal.

I love the brutal efficiency of the question, and find it to be revealing in the same way as the “on a scale of 1 – 10, how would you rate yourself” question.  This question isn't quite as efficient -- there are more than two answers -- but any answer that isn't actually between 1 and 10 should end the interview.  If the applicant doesn’t realize that 15 is not less than 10, what can you possibly hope to salvage by continuing?

Yes. I’ve heard, with my own ears, somebody seriously rate themselves higher than 10 out of 10.  I'll never forget the claim: "On a scale of 1 to 10, I'm a 13.  My SQL Server skills are that good."  Of course the candidate was hired (it wouldn't be much of a story otherwise) and the consequences weren't pretty.  Years later, the team that made the hire is still trying to overcome the reputation of minimal competence, unresponsiveness, and outright contempt that this individual bequeathed them.

On a lighter note, a little tidbit about the most overlooked risk in software engineering (again, from CodingHorror):
Q: What is the most often-overlooked risk in software “engineering”?
A: Incompetent programmers.

My name is “Bob” and I’m a developer. Now let’s begin planning around my incompetence.

11 November 2010

Restore Me, Please

Our shop has a stored procedure to restore databases that takes care of all the ugly details of file moves and the like.  You supply a target_database_name and a backup_file and it does the rest.  No worrying about which paths to move your data and log files to on each server.  It's even supposed to distinguish between native and Red-Gate backups and do the appropriate magic.


A couple years ago, we had a rock-star DBA "optimize" the restore procedure, and it has only worked intermittently ever since.  We've all taken to using the native backup syntax so we don't depend on "the procedure."  However, we occasionally get a compressed database we need to restore (.sqb), and I recently ran through a painful restore that I thought I'd share to give a quick overview of restoring backups that have been compressed with Red-Gate SQL Backup.

After making a good-faith effort to restore with "the procedure," I grabbed version 6.4 of the Red-Gate SQB Converter so I could extract the .SQB file into its constituent .BAK files.  Not entirely related, but we tend to have 15 .BAK files wrapped up in each .SQB file.  It helps backup performance, but can be a killer on MemToLeave Virtual Address Space (VAS) on 32-bit servers.

In this particular case, it wouldn’t convert the file because it wanted a password.  This is often an indication that the converter version is older than the SQL backup version that created the .sqb file, but I'm sure it could have other meanings, too (like needing a password?).

Since I couldn't get my .bak files out of the .sqb file, I had to crack open "the procedure" and scarf its Red-Gate syntax to do the restore.  Other than the additional Red-Gate syntax, the process is the same we would use with native tools…

1.       Restore filelistonly to get your logical filenames
2.       Determine the location to place your .mdf and .ldf files on the server
3.       Restore your database with move

Here is the relevant syntax…

1.       Get your logical filenames with this:

EXEC master..sqlbackup N'-SQL "restore filelistonly from disk = ''path_to_your_sqb_file.sqb''"'

2.       Get the default file locations for your server (if you can create a database, you should have permissions to write restored database files there, too):

CREATE DATABASE bob
EXEC bob..sp_helpfile
DROP DATABASE bob

3.  Once you have your logical filenames, and the paths to where you want to move them, you can run the restore…

EXEC master..sqlbackup N'-SQL "restore database your_database from disk = ''path_to_your_sqb_file.sqb'' with move ''data_file'' to ''path_to_mdf_file.mdf'', move ''log_file'' to ''path_to_your_log_file.ldf''"'

I'm still a big fan of Red-Gate SQL Backup, I just don't listen to rock any more.

08 November 2010

The Patching Treadmill

Well, it's almost Patch Tuesday again.  Are you ready to apply and test them?  It's one of the most important things you can do to maintain the security and availability of your SQL Servers.  Remember Slammer?  The patch for that was months old, but hadn't been widely applied.

Keeping up with patches used to be a time consuming, hit-and-miss sort of affair.  By scheduling a regular monthly patch release, Microsoft has provided the predictability that many organizations need to manage and keep up with the patching process.  There isn't really an excuse any more for not having some sort of regularly scheduled patch deployment and testing process.

We happen to use Windows Server Update Services (WSUS) to authorize and deploy patches in our environment.  We push the patches through QA and test environments before pushing them to pilot groups then the rest of the enterprise.  It's a pretty decent system and has served us well.

Testing the patches is critical, because they do occasionally cause production outages of their own.  We had to back one out of production a couple of months ago because it affected the communication between one of our Windows applications and its WCF service.  Of course, since we're not perfect, the same patch made it back into test last month, but we were able to get it backed out before it made it through to production again (it had been mistakenly re-authorized in WSUS).  We'll have to really watch out this month: the only thing more embarrassing than getting caught by the same mistake twice is getting caught by it three times.  Three strikes, and you're out, right?

Just to help get things rolling, this is the schedule we use for applying Microsoft's monthly patches. Just place the Microsoft release on the second Tuesday then testing and production rollouts fall right in place.






This is based on an Excel Template by Vertex42

03 November 2010

My Descendents Thank You

I have 3,932,160 grandchildren.

At least I will in 600 years, if my children and theirs each produce two reproducing children per generation.  And that’s exactly when today’s performance optimization will pay for its own development time in CPU cycles.

I have written previously about intentionally leaving query results unordered to save some academic CPU cycles while burning money in end-user time – a poor “passive” optimization.  Now we’ll discuss actively making inane optimizations that will never pay for themselves – a poor “aggressive” optimization.

A developer modifies a query with the academic goal of saving several milliseconds per execution (perhaps as few as 6 ms).  If this was a query that ran thousands of times per hour during user time, we might have been able to quantify some savings to the business.  Unfortunately, the optimized queries were in some procedures that run once per day during a nightly batch cycle that had no time pressure.

I ran the numbers on the CPU savings and it will take more than 600 years for the saved CPU cycles to accumulate the same amount of time spent to “optimize” the query.  Because the CPU time for a batch process does not correspond to the real money being spent in user-time, this optimization will never be paid for… even in the 600 year break-even period for the CPU time.

These two types of performance optimization illustrate the danger of optimizing for purity of execution without giving any consideration to the practical implications of where our technical decisions force the business to spend its money.

If we keep wasting it like this, they certainly won’t be spending it on us.

29 October 2010

Don’t waste my (users’) time

Tradeoffs are everywhere.  This is particularly true in the realm of software development.  As the saying goes, “speed costs.  How fast do you want to go?”  We should always keep these tradeoffs in mind as we balance our technology decisions with the needs of the business.

Here is a quick tale of a not-so-great performance optimization that really emphasizes the importance of making optimization decisions that actually have business value…

The case of a missed sort optimization
A business user and her colleagues currently sort and search a grid manually because "without some kind of 'sort' you have no idea where in the list your application will be found".  These results apparently get scrambled each time the grid refreshes.  The company is spending wage dollars (read “real money”) to do the work that the CPU could be doing for “free”.

In this case, the ten seconds worth of real money spent by the developer to type “ORDER BY ” would have been a huge win.  One ten-second real money line of code would have saved thousands of several-second real money live employee sorts. I don’t know about you, but I get excited about single order-of-magnitude performance increases.  This was a three-orders-of-magnitude oversight!

Because the developer didn't make this 10 second investment up front, the company now has two options (there may be others... conversations are good at flushing out options!):
1.    do nothing and continue to spend  real money to do the sorting that the CPU could be doing for free
2.    spend thousands of dollars of real money to add an ORDER BY (or an appropriate index to force a sort).

I can hear you scoffing now, “Sure, thousands of dollars!” Picture it with this nearly exaggerated process –

We start with our line-of-business employees spending their time (remember, that’s real money) adding the suggestion to the feature request system and voting it up (picture Microsoft Connect for your business applications).  We just spent more real money getting the bug typed in and voted up than we would have spent with the initial sort, but I digress.

Next, we have the bug validation team spending real money making the appropriate contacts and follow ups with a decision maker who determines (spending more real money) if this is a legitimate feature request.

Once we have determined that this is a real bug, worthy of company resources (more real money), we proceed to the team (think real money multiplied by Dilbert) that determines which features and applications get worked by which development teams and when.

Now that we’ve gotten all the way through the verification, validation, prioritization, and schedulization phase, it’s time for a software development team (there’s that real money multiplier again) to actually begin working the bug – remember that ORDER BY thing we were talking about?  Our software development team is going to go through its own verification, validation, prioritization and schedulization process.

They have to reproduce the bug, find the source code module where they can actually make the fix, fix it (our initial 10 second line of code), then run it though the test deployment process, user acceptance testing, the pre-prod deployment process, the pre-prod testing process, the change request for production process (think about another team here), the production deployment process and the post-production testing process.

Don't get me wrong, this isn't some process oriented bureaucracy, this is a kanbanagilescrum .NET development shop with all the modern efficiencies as their disposal.

You probably thought I forgot where I was going with this.  It was close there for a second, but it's still here.  The problem with this isn't that the developer made a simple oversight on a search screen and nobody noticed before production.  That’s understandable, and we all do similar things routinely.  The problem is that there really are developers who intentionally leave all of the sorting to the end-user because they want to save the CPU sort cost for the 400 rows.

These decisions not only erode our users’ confidence in both the development team and the application, they consciously make the tradeoff between CPU time and User time – and choose infinitesimally small bits of CPU time in favor of measurably large amounts of real money paid in the form of user time.

Stop wasting my users’ time!

10 September 2010

Alter Ego

So the other day I'm doing some light reading from Paul Randal about DBCC CHECKDB when I learn that, beginning with SQL 2005, CHECKDB actually performs its checks on an internal database snapshot and not the "real" database.  That was a totally unexpected bit of knowledge, so it really caught my eye.  It's great to have somebody that loves to share these things with the world.  Thanks, Paul!

A little more reading revealed that the internal database snapshot is implemented as an alternate stream of the live database file.  And also that I have no control over where it's created, so it can cause a nearly full drive to fill up during a CHECKDB (the original reason for his original article).

I had never heard of an alternate stream before, but I did find a couple pretty good explanations, that I won't cover here, other than to mention that it's a feature of NTFS and allows multiple data streams to be stored within a single file (the second link has downloadable source-code for utilities that manipulate alternate data streams, if you really want to get down in the weeds).

I wanted to see one of these alternate streams in action myself, and discovered that you can view a file's alternate streams by using the /R switch of the DIR command.  Here is DBCC CHECKDB in action, complete with a peek at the alternate steam in the file system.

I'm using the following command to provide directory listings for the  AdventureWorks database:


declare @cmd sysname
set @cmd = 'dir /R "C:\\AdventureWorks_Data*"'
exec master..xp_cmdshell @cmd


This shows the AdventureWorks_Data.mdf file:


Now run dbcc checkdb('AdventureWorks') and, while that is still running, kick off the DIR command from a separate SSMS window.  This shows the AdventureWorks_Data.mdf file and the alternate stream that is used for the internal database snapshot:


Notice that the DIR command only reported a single file in the summary.  The alternate data stream is completely invisible to most DOS style commands, and you'll never see one in Windows Explorer.

I didn't really expect to do so much digging after a little reading about DBCC CHECKDB, but it turns out there was a lot to learn, and I couldn't resist diving into the mysterious internal database snapshot and its alternate data stream.

Enjoy!

07 September 2010

Feeling the Love

DBAs @ Midnight just kicked off its second season. If, like me, you missed the live season opener, you'll have to settle for the preview until the recording is available.

In the meantime, they are forming a zombie gang and soliciting public displays of affection. I don't know if I'd make a good zombie gangster but I sure do enjoy the show, so here's my PDA:



Have a great second season Sean and Jen!

06 September 2010

That's Virtually Twice as Fast

We do much of our software testing and validation on virtual machines. We happen to be using VMWare ESX as the host and are testing with Windows XP SP3 as the guest.

We were getting pretty poor launch performance from our application as compared to a physical machine. I'll measure launch time in Task Manager Grid Squares (TMGS). Think of them like story points for performance monitoring. They just represent some arbitrary amount of time (what it is... 9 seconds per square?).

We have a main application, a supporting GIS application and a 3rd application for moving things around the network, and it was taking as many as 10 Task Manager grid squares for the three applications to launch. Here is what the launch sequence looks like in Task Manager:

Here is the key for the image:
1. Main application launch
2. GIS application launch -- almost 1 minute of 100% CPU -- OUCH!
3. Network search
4. Opening the first search result
To try and help out with the launch speed, we added a virtual processor and a virtual GB of RAM to the virtual machines. This reduced our launch time from 10 Task Manager grid squares to just over 6.


You can see that opening a search result wasn't really helped out because it is rather network intensive. Main application launch is a mix of network and processor, and didn't fare much better with two processors than it did before the upgrade.

The real benefit we saw was the large gain in both the launch of the GIS application and the processing of search results, both of which are processor intensive. We see the times here cut by more than half.