Saturday, June 30, 2012

Worst Web Site Ever

I write this post as a reminder to myself. The NET10 website (as of this date, anyway) offers a perfect example of what not to do. Here's the story...

Their technical support page insists that I enter a PIN for Buy It Now. Never mind that I'm not buying anything. The submit button doesn't work at all. I hit continue a dozen times and nothing happens. Cancel works. It drops you back to the home page. This page has no way to submit a technical support ticket!

So I went looking for another way to add this PIN. I found the menu option for that. It says that I have no phone. Huh? The phone's listed right there on the home page. In effect, it's impossible to set the PIN. And it's impossible to log a ticket without a PIN. Therefore, it's impossible to log a technical support ticket.

Maybe it's your browser?

That is certainly possible. That merely begs the question, though. The site does not meet expectations. I expected to get help with a problem on the wife's phone. Instead, I ran around and around never accomplishing anything.

The user doesn't know or care about all of the little pieces that make up your application. They see that they can or cannot accomplish a goal. Anything else gets in the way. As the programmer, those details are my responsibility.

Tuesday, June 12, 2012

Indexes, Indexes, Indexes

Around 2:30 this afternoon one of our users comes by the Data area.

"PARS is running slow."

This is no surprise. PARS has been randomly performing mediocre to tolerable for most of my two years.

"I go get a cup of coffee and it finally times out just as I get back."

Uh-oh. Slow is annoying. A timeout means the system is down. First we check with the other users. Nope, nothing unusual here. Hmmm. This user performs a search. We emulate their exact criteria. Boom - PARS times out here too!

Okay, the search function calls a stored procedure that dynamically generates an SQL query. I copy out the relevant parts and build the query by hand. It takes 35 seconds and returns a dozen rows. First, I take out the date check. Presto, the query runs in 6 seconds.

Let's see what effect other criteria have. Comment out the client check - 6 seconds. Odd, I would have expected it was just the date search. A little more playing and it becomes clear that three search clauses take 35 seconds. Two only take 6 seconds.

Now I examine the execution plans. Aha! A clue! Two criteria go into a bitmap index. Three criteria do not have the bitmap. What happens if I index the three search fields? We use this query a lot. Relatively, we upload minute amounts of data. So an index won't affect load performance. What do I have to lose?

Well, how long does building the index take? Am I going to bring down the database for 2 hours? It's down now, so again, no harm. Turns out that I was being stupid. SQL Server built the index in like 2 seconds.

I hit the query again. It still takes 35 seconds. I found that very surprising. The execution plan put a lot of time into looking up those fields. The second worst spot was a sub-select. The sub-select checks if we have any records for this row in another table. Actually, I'm looking for the case where we don't have corresponding records. The second table has a foreign key that points back to this table.

No one ever added indices to the database. SQL Server does not automatically index foreign keys either. So for kicks, I indexed it. Pow! The query displays results immediately. I couldn't believe it. I usually hit the button, sit back, and watch the timer for when they finish. This sucker ran instantaneously! I was dumb-founded. My user was happy to get back to work.

What did I learn from this experience? First, I was an idiot for waiting this long. I had noticed that we had no indices two years ago. Performance wasn't that bad. So other priorities moved ahead.

Secondly, a well placed index can breathe new life into sluggish queries. I know, I know, a million DBA's just slapped their palms against their foreheads and exclaimed "duh!". Seriously, though, this was on my radar because, well, it might shave off a few seconds. Going from timeout to instant response, though. I had no idea the effect was so dramatic. Seeing was believing.

So go ahead and chuckle. I deserve it. And now it's time that we look at our other tables. I may be able to eek even more performance out of this system!

Sunday, June 3, 2012

All That You Can Be

Vania, we went for a walk on Saturday. You won't remember. You're too young. We walked around the entire park. Okay, I walked around the entire park. You rode in the stroller. That's life with a toddler.

As we walked, I made an effort to pay attention to the trees. There are LOTS of trees down by the creek. Little trees, big trees, trees with birds, and trees with bugs. I also noticed how the trees grew together. They each found space for their leaves. Every tree had value. The ones with birds provided a home. Close to the path, trees provide shade. And all turn nasty carbon dioxide into fresh air. Plus they look downright great all decked out in green.

It kind of reminded me of people. No, not little green men. People come in different shapes and sizes. We have different talents - different ways of changing the world around us. God created a place for each of us, even you, Vania. You will never be everyone else. Your body is broken. Yet in spite of that, you will become all that God created you to be.

In his book How To Be Good In A World Gone Bad, Dr. Jim Spiegel talks about how God plants metaphors of spiritual truths in the real world [chapter 10, Living Artfully]. You have a special place in the world. You will change those around you in some way. And that makes you unique.

Being unique means that it doesn't matter how you compare with other people. God never measures us against anyone else. He measures us against His plan for our life. He gives us all that we need. And expects us to make use of that. Pastor Bob O'Bannon gave a sermon about the parable of talents. Bob made a point that the master praised the first and second servants equally even though one made far less than the other.

God expects Vania to be Vania. He gave you very special talents. Never let the things you can't do distract you from the things you're supposed to do.

Sounds so simple, right? Never is. Too often, people let themselves get distracted by what they think they should do. Schools will want to make you a well rounded person. Your genetic condition puts you in a unique position to ignore all of the noise. Some things will come easy. You already solve puzzles, learn about machines, and manipulate shapes. Focus on those things. Struggling with some subject? Then ignore it. Don't waste your precious energy on things that come hard. Grow in the space God carved out just for you.