January 8, 2007

Understanding and improving ADO performance

Ado as a technology offers a lot of usefulness. It can help you manage concur connections. Lock records; ease inserting, manipulating, and deleting individual records; and overall manage database manipulation. It tries to provide a layer of abstraction between the developer/application and the database/database provider. It accomplishes this goal fairly well. Unfortunately though, it comes at a price: performance. To understand how to improve performance, we need to understand the basics of how ADO works.

ADO does a lot behind the scene. First it must be able to communicate with your database provider. To do this it has to translate all of your ADO commands into its SQL specific counter parts. There is no getting around this. But it is additional layer that needs to be accounted for. This isn’t the biggest hit in performance though. What is the foundation of how ADO works; Record sets.

Record sets are the result of your SQL command, the records that get returned. ADO returns all of the records you asked for in one big lump and loads it into memory. Memory is cheap and memory operations are fast, but the overhead of managing large amounts of data this way is costly. Operations such as sort, find, and filter can be huge if the data is as well. These commands and others are done on the client side and on the entire record set.

Transferring that large amount of data can be part of the overhead as well. Traditional client/server databases can handle this, but if you are using access which uses a file connection this can pull an application to its knees.

By default when you open up a generic ADO connection, it opens and returns the whole table. Depending upon the table this can be a long and resource intensive operation. The best way to handle these performance issues are to follow these simple steps to improve your performance.

Steps to improve ADO and query performance:

  1. Use the .command method. This will give you greater control over what you bring over. By limiting the amount of data to what you just need, you save network bandwidth, client memory, and client CPU time. Let the database engine do the work for you.
  2. Use the where clause in your SQL command. Again this goes along with #1.
  3. Don’t use Select * in your SQL command. Using column names gives lets you specify the order that columns get returned in. You can change the names of the columns. You don’t have to fumble with ADOx to figure out the column names (giving your code that much more readability). Finally, if the database is changed and a columns get added you aren’t suddenly faced with a degrade in performance because the added extra data is being brought over.
  4. Do all of your sorting, grouping, and aggregates (Min, max, sum, count, distinct, …) in your SQL command. The database is designed and optimized to do these functions. Let it do it for you.
  5. Be smart with your queries. Know your data and look at your most used queries and optimize them against your existing indexes and add indexes where you need them.

I followed these steps with a customer’s existing Access database and saved them from rewriting the entire application. It sped up the application from opening up this one screen in 3 min to 20 seconds. That was before optimizing the queries too.

What other tips and tricks do you have for speeding up an ADO connection/query?

Technorati Tags: , , , , , ,

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • BlinkList
  • blogmarks
  • del.icio.us
  • digg
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • YahooMyWeb
Permalink • Print • Comment

September 11, 2006

On being the responsible technologist

mushroom-cloudAlbert Einstein once said, “Technological progress is like an axe in the hands of a pathological criminal.” I look at the progress we have made in the past 20 years and especially in the last 5. We have gone from technology being in the hands of geeky privileged few, to it being common place everywhere. It is no more apparent than watching how people view and use the web. We live in a world where people can not go from place to place without a GPS; Google is now considered a verb (much to their chagrin); email is now passe amongst 20 somethings; and anyone can interweave services from Yahoo, Amazon, Google, and the likes of Zillow to create some scarily accurate and inaccurate pictures of us.

This generation or iteration of software and the internet is one of openness and transparency. This means as technologists and corporations, we have a responsibility not only to our shareholders and employers but also to our user community. We can still be socially responsible and still make a profit. Even if that responsibility means that we only create a trail of how people are using our hardware and software. Some are going to scream about Privacy. Others will call out that we are just feeding big brother and making him into an ever more aware beast. We need to do something to protect us and yes perhaps help big brother and the authorities.

Just look at what is happening all around us. Go to MySpace, Facebook, Google a friend or colleagues name, or choose your favorite topic and find a forum on it; you’d be surprised at the amount of personal information you will find, most of it is posted out in the open. Molly H. found out that a lot of her personal info was posted on Aboutus.org. Some that she may not have chosen to be posted. My 13 yr old niece set her away message on AIM to be her cell phone number. Whether or not if its voluntary or not, there is a lot of personal information out there that can be pieced together pretty easily and quickly. Until the public and the government is fully educated and appreciates the ramifications of such transparency, then we are obligated to assist them when possible.

Should we keep detailed records, with names and personal records available? Its not necessary, but we
can keep an auditable trail for a time period and insure that it is purged on a regular basis. This we have in our individual abilities. Through my career I have emphasized this with my employers and customers. If something ever happened like on MySpace, then we should be able to help them when necessary.

Storage space is cheap. The required computing power is minimal and the technology required to create is very straightforward. In a subsequent article, I will detail some of the steps that I have done to do this (programmatically in VB) and what I am using today achieve this (SQL triggers). If we are going to make the Axe and WMD, then let’s at least try to make it difficult for the psychos to use it.

Technorati Tags: , , , , , ,

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • BlinkList
  • blogmarks
  • del.icio.us
  • digg
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • YahooMyWeb
Permalink • Print • Comment
Made with WordPress and an easy to customize WordPress theme • Electric Kubrick skin by Denis de Bernardy