Upcoming Events

Executive conference

Cloud Connect March 16-18

Comprehensive thought leadership for executives, IT professionals and developers. Topics include: the ROI, cost and economics of on-demand computing; Migration strategies to move from on-premise to cloud-based IT; Vertical cloud specialization, tailoring features and architectures to specific applications, industries, and customer ecosystems

More Events »

Subscribe to Newsletter

  • Keep up with all of the latest news and analysis on the fast-moving IT industry with Network Computing newsletters.
Sign Up
Data Management & Storage Technology
W O R K S H O P  
Optimizing Performance on Public Domain Databases

  April 2, 2001
  By Ahmad Abualsamid


Most Web application development entails the use of a database. If your budget is small or you're an open-source buff, you'll probably use PHP and an open-source database. If so, you should familiarize yourself with the methods for getting the most out of your database. Here are some performance-improvement techniques you can use with most open-source databases.



Database-Level Optimizations

>> Use Stored Procedures

The quickest way to improve your code's performance is to replace your inline SQL statements with stored procedures. Stored procedures are routines that are stored in the database. They are precompiled by the database engine and offer substantial performance improvements over the process of going back and forth between your calling application (typically a PHP page) and your database engine.

In addition, stored procedures are much easier to maintain. Your logic resides within one piece of code; any changes are made in that one place, and all the code that uses it gets the fixes immediately. It is also easier to be certain that your business logic conforms to your functional requirements across the board if all your code refers to a single point. If your procedures are generic enough, you can reuse them in several projects and cut your development time.

Stored procedures also reduce network traffic, as compared with executing SQL code from within PHP, ASP (Active Server Pages), JSP (Java Server Pages) or other Web development languages. Finally, if scalability is an issue, it is much easier to scale your application code across several application servers if most of the database access logic is stored and executed inside the database.

>> Store Multimedia Files in the File Systems

Multimedia files -- whether still images, sound files or a movie -- often are dealt with as binary objects. More specifically, these are known as blobs (binary large objects). There are two ways to handle blobs: Store them in the database, or store them in the file system and their paths in the database. Storing blobs in the file system requires a little more work, but you get much better performance than if they are stored in the database.

The performance of your database engine can degrade quickly when you store a lot of binary objects. And deleting those files can result in large quantities of dead space in the database files. It is more difficult to multitask operations when everything is going through the database engine. In contrast, storing them in the file system makes creating download links from a Web page easy. On downloading, the Web server can serve the file while the database engine is used in other tasks. As an extra advantage, your administrator can back up, catalog and administer multimedia disk files with ease.

>> Use Indexing

Indexing is one sure way to speed up performance. It also is one of the most overlooked essentials in a database design. Typically, rows in a database are stored in the order in which they are created. Retrieving some random value from a database record requires a sequential scan of the database rows. An index creates a separate set of rows ordered according to the chosen index and containing pointers to the original rows. Database lookups on indexed databases are performed much faster than lookups on nonindexed tables. However, indexing consumes more disk space. In addition, updates to the table take longer, since all applicable indexes have to be updated as well.

>> Use Integer Key Fields

You might be tempted to create your table without an integer key field. For example, in a table of personnel records, you might create your table with one character field called last_name and one called first_name, plus address and contact information, and use the names in joins, lookups and so on. You should avoid such practice. Instead, use a numeric key field -- let's call it person_id. If your data does not have such a field, you should create an autoincrement field that does not hold real data but serves as a key field.

Numeric fields offer many advantages. Numbers are much less likely to be used incorrectly. If a person's name changes -- because of marriage, for example -- you do not need to change all references to it in your code. And numeric joins are more efficient than character-based joins. It is good practice to create a numeric primary key field whenever you are creating a new table.

Optimizing Code

Several strategies can be used within your code to optimize its performance when dealing with a database.

The following optimization should be usable in any Web development language.

>> Avoid Using Sessions

Several Web development environments support sessions. Sessions usually are implemented using cookies, and they are extremely popular among ASP and PHP programmers. Because the Web is a stateless environment, it does not afford programmers the luxury of knowing what the user may have done before landing on a particular page. Using sessions, the programmer can keep track of the user's navigation. As a side effect, many programmers tend to store everything in session variables. While it is tempting to store references to the database, such as connections or record sets in a session variable, this is bad practice. Storing connections in sessions prevents them from being pooled. That practice also eats memory and CPU power.

Unless the sessions are cleaned up explicitly, they exist until they time out. The time-out varies, but in most instances it is upward of 20 minutes. During this time, memory and CPU are being hogged for no reason. While opening a connection in the page and then closing it may seem to be a waste of resources, it is actually a much better way to preserve resources. The rule of thumb is to create the connection as late as possible and release it as soon as possible. The same rule applies to record sets.


   Page: 1 | 2 | Next Page

Best of the Web

Data deduplication: Declawing the clones

Data deduplication is emerging as a critically important new arrow in the storage administrator's quiver to answer hard questions about the increasing problem in storage growth costs.

Quick Read

Compression, Encryption, Deduplication, and Replication: Strange Bedfellows

One of the great ironies of storage technology is the inverse relationship between efficiency and security: Adding performance or reducing storage requirements almost always results in reducing the confidentiality, integrity, or availability of a system.

Quick Read

WAN Optimization Whitelists and Blacklists

Optimization is a fantastic way of saving money and creating really happy customers at the same time, but it doesn't work flawlessly for all applications.

Quick Read

WAN Optimization as a Managed Service: It's Not About the Cost

This insight examines how organizations outsourcing their WAN optimization initiatives to a third-party go about achieving their goals for application performance, reducing operational costs, and streamlining enterprise infrastructure.

Quick Read

  Sponsored Links

Premium Content

Data Centers Gone Wild
February 22, 2010

NWC


Salary

Video