Performance Tune Iseries Access Odbc: I Want Stress-Free It. I Want Control. I Want An
Performance Tune Iseries Access Odbc: I Want Stress-Free It. I Want Control. I Want An
Session: 401918
Agenda Key: 42MK
i want an i.
IBM System i
Client
Network
Server
1
IBM System i
• Fetching data
• Long-running SQL queries
• Network issues
• Inserting data
• Lots of connections
Applications
Database (Host)
DB2 Control PCOMM File
iSeries Navigator Data Transfer On
Center Transfer
Demand
Middleware
ODBC CLI/ODBC
JDBC .NET .NET
(Windows, DB APIs OLE DB (Windows, JDBC OLE DB
Linux) Toolbox Linux, AIX)
ODBC iSeries
JDBC HTTP
Database (Linux Access
Toolbox DDM / DRDA File Transfer
Host Server partition) for Web
Server Server
Websphere [Link]
Middleware
Native
Stored Stored
Procedures Native Native Procedures
CLI JDBC
System i5
2
IBM System i
Explanation of Scale
Programming Potential
Required? Benefit
Y 3
Y = Yes 1 = Low
N = No 2 = Medium
3 = High
IBM System i
Agenda
3
IBM System i
IBM System i
4
IBM System i
IBM System i
• Research options
• Understand the benefits to different alternatives
5
IBM System i
• Make changes
• Compare performance before / after
IBM System i
Performance Considerations
• Application design
– Choice of programming interface
– Connection pooling
– Inserting data
– Fetching data
– Isolation level and concurrency
• Network
• Database design
6
IBM System i
Y 2
Choosing a Programming Interface
Application
[Link] ADO
Delphi Powerbuilder PHP
ODBC .NET MSDASQL
Provider Provider
IBM System i
Y 3
Connection Pooling
1 2 3 1 3 2
C1 C2 C3 C1 C2
7
IBM System i
IBM System i
System i5
8
IBM System i
Y 2
Insert Data - Prepare Once, Execute Many
‘book’, 12345
‘watch’, 12345
‘phone’, 12345
System i5
IBM System i
Y 3
Insert Data - Block Insert
‘book’, 12345
‘watch’, 12345
‘phone’, 12345
System i5
9
IBM System i
• Drawbacks
– May not be practical for all applications
– AS/400 only feature if use "? rows" SQL clause
IBM System i
Block insert
Block Insert
x
0 20 40 60 80 100
Response Time
10
IBM System i
Deleting Data Y 1
• Consider:
CALL [Link]( ‘CLRPFM FILE(MYLIB/MYFILE)’,0000000025.00000)
• Instead of:
DELETE FROM [Link]
IBM System i
11
IBM System i
• Cursor Type
– SQLSetStmtAttr API with SQL_ATTR_CURSOR_TYPE option
– Forward-only versus Scrollable
• Rowset size
– SQLSetStmtAttr API with SQL_ATTR_ROW_ARRAY_SIZE option
• Block fetch of 1 row option (BLOCKFETCH keyword)
– Block size option – (BLOCKSIZE keyword)
• Cursor Concurrency
– SQLSetStmtAttr API with SQL_ATTR_CONCURRENCY option
IBM System i
12
IBM System i
• Example 1:
– Application is fetching one row at a time App Driver Server
– Results: 1 Row is fetched at a time
• Example 2:
– Application is fetching with rowset size of 4 rows
App Driver Server
– Results: 4 Rows are fetched at a time
IBM System i
• Example:
– SQLBindCol usage: COL1 COL2 COL3
• 3 SQLBindCol calls
• up to 5 SQLFetch calls
– SQLGetData usage:
• 5 SQLFetch calls
• 15 SQLGetData calls
13
IBM System i
N 2
Large Objects (LOBs)
• MAXFIELDLEN keyword
– Default is 32 (KB)
– Lower setting usually better
• Inserting data
– Use SQLParamData / SQLPutData
• Fetching data
– Use SQLGetData
IBM System i
Y 1
Isolation Level
14
IBM System i
IBM System i
Performance Considerations
• Application design
• Network
– Reduce Trips to Server
– Reduce Data Between Server
• Database design
15
IBM System i
Network
IBM System i
N 2
Reduce Trips to Server
• Stored procedures
• Triggers
• Connection pooling
• Block inserts
• Block fetches
• Lazy close
• Pre-fetch
16
IBM System i
IBM System i
• Data compression
• LOB threshold
• Avoid “SELECT *” SQL statements
17
IBM System i
N 3
Data Compression
IBM System i
N 2
CWBCOPWR
18
IBM System i
Network Summary
IBM System i
• Performance tab
• Advanced performance options
• Package tab
19
IBM System i
N 3
Linux ODBC DSN GUI
IBM System i
Performance Considerations
• Application design
• Network
• Database design
– Indexes
– Extended dynamic support
– Stored procedures
– Trigger programs
20
IBM System i
SQL Interfaces
ODBC / JDBC / ADO
Network
Host Server
Optimizer
DB2 UDB
(Data Storage & Management)
IBM System i
Y 2
SQL Statement Tuning
• Avoid SELECT *
• SQL clauses:
– OPTIMIZE FOR N ROWS
– FOR FETCH ONLY / FOR UPDATE
– FETCH FIRST N ROWS ONLY
21
IBM System i
Indexes N 3
IBM System i
Indexes
22
IBM System i
Indexes
• Create index over tables when queries return less than 20% of table
– Create index over columns used in WHERE clause
– Create index over columns used to join tables
– Create index on grouping columns
IBM System i
23
IBM System i
1. Application runs:
SELECT * FROM MYTABLE
SELECT * FROM MYTABLE WHERE COL1=? WHERE COL1=?
2. Application re-runs: Access plan
SELECT * FROM MYTABLE WHERE COL1=?
Package
IBM System i
24
IBM System i
• The following SQL statements are put into extended dynamic packages:
– Statements that contain parameter markers
– INSERT with subselect
– Positioned UPDATE or DELETE
– SELECT FOR UPDATE
– DECLARE PROCEDURE
IBM System i
N 2
QAQQINI file
• OPTIMIZATION_GOAL
– *DEFAULT
• Packages: *ALLIO
• No Packages: *FIRSTIO
– *FIRSTIO
– *ALLIO
25
IBM System i
Stored Procedures Y 3
IBM System i
Stored Procedures
26
IBM System i
IBM System i
set sqlstmt = 'insert into ORDERS values ( ''' || ITEM || ''', ' || CUSTID || ')';
execute immediate sqlstmt;
end
27
IBM System i
Y 2
Insert Data - Stored Procedure
CALL PLACEORDER ( ? , ? )
C1 S1
‘book’, 12345
PLACEORDER
‘watch’, 12345 Stored Procedure
‘phone’, 12345
IBM System i
set sqlstmt = 'insert into ORDERS values ( ''' || ITEM || ''', ' || CUSTID || ')';
execute immediate sqlstmt;
set sqlstmt =
'update ORDERLOG set TIME=CURRENT_TIMESTAMP
where CUSTID = ' || CUSTID;
execute immediate sqlstmt;
end
28
IBM System i
Y 2
Trigger Programs
IBM System i
• Links:
– [Link]
– [Link]
29
IBM System i
• Graphical
– Centerfield Technology DB Essentials
• [Link]
• Text-based
– Debug joblogs
– SST (iSeries Communication Trace)
– ODBC trace ([Link])
IBM System i
30
IBM System i
Examples
• 3-Tier application
• Stand-alone application
• Solutions for typical performance problems
IBM System i
Any
Web/
App
Server
31
IBM System i
• Goals
• Settings
– Connection pooling
– Stored procedures
– Block fetches
IBM System i
[Link] ADO
Delphi Powerbuilder PHP
ODBC .NET MSDASQL
Provider Provider
32
IBM System i
• Goals
• Settings
– Block fetch of 1 row
– Compression
– LOB threshold
– Packages
IBM System i
Summary
• Process
– Understand application
– Narrow problem
– Understand options
– Fix problem
• Application Design:
– Use parameter markers
– Prepare once, execute many
• Network:
– Adjust data compression as needed
– Use blocking
• Database Design:
– Indexes
– Use stored procedures
33
IBM System i
IBM System i
34
IBM System i
Appendices
• A – Reference Information
• B – Insert data example code
• C – Compression
• D – Extended Dynamic Packages
IBM System i
• ODBC
– [Link]
• OLE DB
– See OLE DB Tech Ref installed with iSeries Access
• .NET
– See .NET Tech Ref installed with V5R4 iSeries Access
• JDBC
– [Link]
35
IBM System i
IBM System i
36
IBM System i
• DB2 UDB for iSeries has a phenomenal query optimizer built into it.
– without the DB2 Symmetric Multiprocessing (SMP) feature your SQL database tasks
and index builds are running single-threaded?
– the DEFAULT system tuning setup could be significantly hindering ODBC performance?
– the database utility called DB2 OLAP can provide sub-second response times to
complex queries?
• For more information about query optimization, check out these resources:
– S6140 – iSeries/i5 Performance Analysis Workshop:
• [Link]
– DB2 Symmetric Multiprocessing and DB2 OLAP Utilities:
• [Link]
IBM System i
37
IBM System i
strcpy(szItem, ”book”);
custID = 123
rc = SQLExecute(hStmt);
strcpy(szItem, ”watch”);
rc = SQLExecute(hStmt);
strcpy(szItem, ”phone”);
rc = SQLExecute(hStmt);
IBM System i
strcpy(szItemArray[0], ”book”);
strcpy(szItemArray[1], ”watch”);
strcpy(szItemArray[2], ”phone”);
custID = 12345;
rc = SQLExecute(hStmt);
38
IBM System i
strcpy(szItem, ”book”);
custID = 123
rc = SQLExecute(hStmt);
strcpy(szItem, ”watch”);
rc = SQLExecute(hStmt);
strcpy(szItem, ”phone”);
rc = SQLExecute(hStmt);
IBM System i
C.1 - Compression
39
IBM System i
• Extended dynamic
– Use iSeries Navigator to view the contents of the package
– Alternatively, you can use the PRTSQLINF command on the System i5 to
dump the package containing your statements
– PRTSQLINF produces spoolfile showing syntax and optimization information
IBM System i
Extended Dynamic
Sample PRTSQLINF output:
40
IBM System i
IBM System i
41
IBM System i
This material contains IBM copyrighted sample programming source code for your
consideration. This sample code has not been thoroughly tested under all conditions. IBM,
therefore, cannot guarantee or imply reliability, serviceability, or function. IBM provides no
program services for this material. This material is provided "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. SOME JURISDICTIONS DO NOT ALLOW THE
EXCLUSION OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSIONS MAY NOT
APPLY TO YOU. IN NO EVENT WILL IBM BE LIABLE TO ANY PARTY FOR ANY
DIRECT, INDIRECT, SPECIAL OR OTHER CONSEQUENTIAL DAMAGES FOR ANY USE
OF THIS MATERIAL INCLUDING, WITHOUT LIMITATION, ANY LOST PROFITS,
BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR OTHER DATA ON YOUR
INFORMATION HANDLING SYSTEM OR OTHERWISE, EVEN IF EXPRESSLY ADVISED
OF THE POSSIBILITY OF SUCH DAMAGES.
IBM System i
Trademarks of International Business Machines Corporation in the United States, other countries, or both can be found on the World Wide Web at
[Link]
Intel, Intel logo, Intel Inside, Intel Inside logo, Intel Centrino, Intel Centrino logo, Celeron, Intel Xeon, Intel SpeedStep, Itanium, and Pentium are trademarks or registered
trademarks of Intel Corporation or its subsidiaries in the United States and other countries.
Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both.
Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both.
UNIX is a registered trademark of The Open Group in the United States and other countries.
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.
Other company, product, or service names may be trademarks or service marks of others.
The customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual
environmental costs and performance characteristics may vary by customer.
Information concerning non-IBM products was obtained from a supplier of these products, published announcement material, or other publicly available sources and does
not constitute an endorsement of such products by IBM. Sources for non-IBM list prices and performance numbers are taken from publicly available information,
including vendor announcements and vendor worldwide homepages. IBM has not tested these products and cannot confirm the accuracy of performance, capability, or
any other claims related to non-IBM products. Questions on the capability of non-IBM products should be addressed to the supplier of those products.
All statements regarding IBM future direction and intent are subject to change or withdrawal without notice, and represent goals and objectives only.
Some information addresses anticipated future capabilities. Such information is not intended as a definitive statement of a commitment to specific levels of performance,
function or delivery schedules with respect to any future products. Such commitments are only made in IBM product announcements. The information is presented here
to communicate IBM's current investment and development activities as a good faith effort to help with our customers' future planning.
Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual throughput or performance that any
user will experience will vary depending upon considerations such as the amount of multiprogramming in the user's job stream, the I/O configuration, the storage
configuration, and the workload processed. Therefore, no assurance can be given that an individual user will achieve throughput or performance improvements
equivalent to the ratios stated here.
Photographs shown may be engineering prototypes. Changes may be incorporated in production models.
42