Five rules for improving the performance of DB2 Web programs (I)

Source: Internet
Author: User
Tags ibm db2 table definition

Speed and scalability are important performance requirements for network development, and they are not difficult to achieve. Some simple rules can improve the performance of network applications. In this article, you will learn how to use Borland®C # Builder and IBM®DB2®General Database UDB) 8.1 quick development Microsoft®Five rules for ASP.net Web applications.
To analyze the performance of Web applications, we need to use some measures to detect the performance of each operation. For this reason, I created a TimeDiff class, which can be used to calculate database operations. You can use the TimeDiff detection results as a benchmark to measure the database operation performance and observe which operations are most effective. I also created a LOTSOFRECORDS table used in combination with the TimeDiff class. See program list 2). It contains 10,000 records. You can observe the performance differences between different technologies by performing operations on it. DB2 has an internal buffer pool. Once a query is run, the internal buffer pool is enabled, so the secondary query speed is faster. When detecting the query speed, ignore the results before the buffer pool is enabled and use the enabled results.
Program list 1. TimeDiff class

Using System;
Namespace quota iency
{
///
/// This class is used for time calculation. In the example,
/// We will use it to detect the speed at which database operations are performed,
/// For performance comparison.
///
Public class TimeDiff
{
DateTime StartTime;
DateTime EndTime;
Public TimeDiff (){}
Public void Start ()
{
StartTime = DateTime. Now;
}
Public void Stop ()
{
EndTime = DateTime. Now;
}
Public string TimeDifferenceText
{
Get
{
TimeSpan TimeDifference = EndTime-StartTime;
Return TimeDifference. ToString ();
}
}
}
}
Program list 2. Table definition of LOTSOFRECORDS
Create table "GLENN". "LOTSOFRECORDS "(
"KEYCOL" integer not null,
"COL1" CHAR (50 ),
"COL2" CHAR (50 ),
"COL3" CHAR (50 ),
"COL4" CHAR (50 ),
"COL5" CHAR (50 ),
"COL6" CHAR (50 ),
"COL7" CHAR (50 ),
"COL8" CHAR (50 ),
"COL9" CHAR (50 ),
"COL10" CHAR (50 ))
IN "USERSPACE1 ";
Comment on table "GLENN". "LOTSOFRECORDS" IS
'Table designed to Contain Lots of Records';
-- DDL Statements for primary key on Table "GLENN "."LOTSOFRECORDS"
ALTER TABLE "GLENN "."LOTSOFRECORDS"
ADD CONSTRAINT "CC1058255334652" PRIMARY KEY
("KEYCOL");
Next, we will introduce these rules to improve the performance of DB2 UDB Web applications. I will first introduce the basic rules for improving database performance, and then list some performance rules suitable for developing ASP. NET Applications with Borland Data Provider.

Rule 1: search on demand
If you can only remember one rule, remember this one: search on demand. If you are a loyal audience on the survivor TV festival, you will remember that contestants use the quota allocation to ensure that everyone has enough food. This method is also applicable to database development. If your application can run on demand, the database and network resources will be reasonably reserved for other applications. This sounds simple, but let's look at an example.
Suppose there is a table containing 10,000 rows of records and 10 fields, and a web page that needs to display all records but only three fields. Many developers often use the "select *" statement to select all fields for ease of use:
Select * from GLENN. LOTSOFRECORDS
This approach should be avoided, but efforts should be made to retrieve only required fields. You can define the fields to be retrieved in an SQL statement, for example:

select 
KEYCOL, COL1, COL2, COL7
from
GLENN.LOTSOFRECORDS
There are two source programs included in this article. net page: RetrievingAllFields. aspx, which executes the first query; the other is RetrievingLimitedFields. aspx, which executes the second query, that is, to retrieve only required fields.
The TimeDiff class is used for detection. It takes 1.622 seconds to execute the first query and 1.311 seconds to execute the second query. The latter uses only 80% of the former, which reduces network data congestion between Web applications and database servers.
This example only limits the search fields. You can also use the WHERE statement to limit the number of records to be retrieved. The WHERE statement can limit the number of records returned by the server, as shown in program listing 3 ). Remember that the fewer record data sent over the network, the better it is for applications, databases, users, and networks.
Rule 2: optimize the database
Sometimes your Web application may run well, but you want to make it better. A simple way to reduce search time is to create an index for a specific field. If a query is to search for products within a price range, see program list 3), but you have not defined an index for the price field, it takes more time to return the data. Once an index is created, DB2 will quickly return the expected results.
Program list 3. database search using Indexes
SELECT 
 PRODUCTCODE, PRODUCTNAME, DESCRIPTION, UNITPRICE
FROM
 GLENN.PRODUCTLIST
WHERE
 UNITPRICE > 20.00
Optimizing databases is not just about creating indexes for search fields. You should collect as much DB2 information as possible to make the application run better. Frequent access to some related Web sites or newsgroups such as IBM DB2 Developer Domain and comp. databases. ibm-db2comp.databases.ibm-db2 are a good way to keep DB2 development skills updated.
You should also try to get familiar with the tools attached to DB2, such as the DB2 Index Advisor ). The DB2 index recommender can return the best index list based on your submitted queries and connected databases.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.