The system supports two basic methods of sequencing data:
o Access paths. These must be built if they do not exist. The data is processed in keyed sequence, which normally requires a good deal of disk arm movement to access the data. (The access path and the physical file must be read.) The same technique is used by logical files, OPNQRYF and SQL.
o Sorting. Physically sorting the data allows it to be processed in arrival sequence. OPNQRYF supports an option to allow a physical sort to occur, but it isn't the default. You must specify ALWCPYDTA(*OPTIMIZE). The Format Data (FMTDTA) command, or the Sort Database (SORTDB) command in QUSRTOOL which acts as a front-end to FMT-DTA, can be used to physically sequence the data.
Building an access path always takes less time than physically sorting the records. However, processing in arrival sequence is faster than keyed processing. If you plan to process records in sequence, a fair test considers both the sequencing and accessing of the data.
This article reveals the results of seven sequencing tests I ran against four files with the same record length, but with different record counts. The tests were conducted on one of the slower AS/400 models-a D02. What is important is not the actual times, but the relative difference between performance times generated by the seven approaches. The results show that physically sorting data with the OPNQRYF command and then processing it in arrival sequence is the fastest sequencing method.
I ran the following tests in an attempt to provide a basis for selecting one method over the other.
Uses an existing access path; processes data in keyed sequence.
Executes an Add Logical File Member (ADDLFM) command on an existing logical file and processes the data in keyed sequence. The difference between tests 1 and 2 is the time to add the logical file member and build the access path.
Uses the FMTDTA command (by way of the SORTDB TAA tool); processes records in arrival sequence.
Executes an OPNQRYF command specifying a key field which allows OPNQRYF to use an existing access path. The records are processed in keyed sequence. The default value of *YES is taken for the ALWCPYDTA parameter (this does not request a sort).
Executes the same OPNQRYF as in test 4 (an access path exists), but ALWCPYDTA(*OPTIMIZE) is specified to allow a sort.
Uses OPNQRYF with a key field which causes an access path to be built; processes records in keyed sequence. The default of *YES is taken for ALWCPYDTA.
Executes the same OPNQRYF as in test 6 (an access path does not exist), but ALWCPYDTA(*OPTIMIZE) is specified to allow a sort.
The Test Environment
The record size used is 200 bytes and the data is in random sequence based on the key field used. The processing program used for all of the tests counts the records that are read and prints one line at the end of the program. No selection occurs in any of these tests; all of the records in the file are processed. (An article in an upcoming issue of MC will discuss the performance effect of selection and sequencing.)
All jobs were run in debug mode with a spooled job log so the OPNQRYF messages could be read. When you operate in debug mode, OPNQRYF sends messages about which access path is used, whether an access path is built (and how long it takes), and whether a temporary file is built (and how long it takes).
Because some noise level comes into any test, I ran each test several times to obtain reliable results. In some cases, the times are slightly altered to avoid trivial differences. 1 summarizes the results of the tests.
Because some noise level comes into any test, I ran each test several times to obtain reliable results. In some cases, the times are slightly altered to avoid trivial differences. Figure 1 summarizes the results of the tests.
Analyzing the Results
Arrival sequence processing is very fast. If you need to sequence and process a reasonable number of records, physically sorting the records and processing in arrival sequence has a definite payoff.
To request a physical sort, you can use FMTDTA or OPNQRYF with ALWCPYDTA(*OPTIMIZE). The re-sults from this test show that OPNQRYF with ALWCPYDTA(*OPTIMIZE) performs better than FMTDTA.
The FMTDTA command was tested using the SORTDB TAA tool. This adds a few seconds to the FMTDTA time that you can eliminate by creating a permanent set of sort source specs for FMTDTA to use. In this case, a sufficient gap between the results indicates that OPNQRYF still performs better than using FMTDTA with a permanent set of sort source specs.
Keyed processing performed better than OPNQRYF with ALWCPY-DTA(*OPTIMIZE) in only a single case. This occurred when I processed 1,000 or fewer records and the access path already existed. Keyed processing is more effective when you deal with a small number of records.
Tests 5 and 7 used OPNQRYF statements with ALWCPYDTA(*OPTIMIZE) to request a physical sort. Even though test 5 had an existing access path and test 7 did not, the results of these tests were identical in all cases. This occurs because OPNQRYF determines that a physical sort provides better performance than using the access path. When I ran test 7 with 1,000 records, OPNQRYF could have used the access path. The performance difference would probably be negligible.
The use of ALWCPYDTA(*OPTIMIZE) incurs one disadvantage. When the system sorts data, it builds a temporary file. Your program then accesses data that is no longer current. For the typical application, designed to produce a printed report from all records, this is rarely a consideration.
A smaller record size (e.g., 50 bytes) causes all of the benchmarks to reflect the greatest improvement using the functions that physically sort the data. The time consumed by a physical sort is very dependent on how many bytes are shuffled around. Conversely, a physical sort on a larger record size performs more slowly.
In some other tests I've run, OPNQRYF stops using keyed sequence and starts using a physical sort when the number of records is greater than 900. The internal algorithm used to make this decision probably varies depending on the record size. A good ballpark figure to keep in mind is that the breakpoint occurs at approximately 1,000 records.
And the Winner is...
OPNQRYF is a winner when you need to sequence and process 1,000 or more records. The key factor is the *OPTIMIZE value on the ALWCPYDTA parameter. When you specify *OPTIMIZE, you tell OPNQRYF that a sort is acceptable-and a physical sort is often precisely what you need to minimize CPU time.
Jim Sloan is president of Jim Sloan, Inc., a consulting company. Now a retired IBMer, Sloan was a software planner on the S/38 when it began as a piece of paper. He also worked on the planning and early releases of AS/400. In addition, Jim wrote the TAA tools that exist in QUSRTOOL. He has been a speaker at COMMON and the AS/400 Technical Conferences for many years.
The Fastest Sequencing Method
Figure 1 Test Results
OPNQRYF Feedback Keyed Access Temporary Results on 1,000 records CPU Job Access Path File Seconds Seconds Path Build Build Used Time Time (secs) (secs) Test Description 1 Process existing access path 5.9 21 2 ADDLFM to build access path 9.0 29 3 FMTDTA to sort 18.0 54 4 OPNQRYF and existing access path 8.4 28 Yes - - 5 OPNQRYF *OPTIMIZE access path 9.1 25 No - 6.1 exists 6 OPNQRYF to build access path 10.5 30 Yes 3.3 - 7 OPNQRYF *OPTIMIZE no access path 9.1 25 No - 6.1 Keyed Access Temporary Results on 5,000 records CPU Job Access Path File Seconds Seconds Path Build Build Used Time Time (secs) (secs) Test Description 1 Process existing access path 19.2 59 2 ADDLFM to build access path 30.2 87 3 FMTDTA to sort 33.2 74 4 OPNQRYF and existing access path 23.9 69 Yes - - 5 OPNQRYF *OPTIMIZE access path 22.8 42 No - 17.2 exists 6 OPNQRYF to build access path 35.9 79 Yes 11.8 - 7 OPNQRYF *OPTIMIZE no access path 22.8 42 No - 17.2 Keyed Access Temporary Results on 10,000 records CPU Job Access Path File Seconds Seconds Path Build Build Used Time Time (secs) (secs) Test Description 1 Process existing access path 39.0 139 2 ADDLFM to build access path 58.2 158 3 FMTDTA to sort 52.6 96 4 OPNQRYF and existing access path 44.8 133 Yes - - 5 OPNQRYF *OPTIMIZE access path 42.1 65 No - 33.3 exists 6 OPNQRYF to build access path 72.8 169 Yes 24.3 - 7 OPNQRYF *OPTIMIZE no access path 42.1 65 No - 33.3 Keyed Access Temporary Results on 50,000 records CPU Job Access Path File Seconds Seconds Path Build Build Used Time Time (secs) (secs) Test Description 1 Process existing access path 231.2 1003 2 ADDLFM to build access path 321.5 1102 3 FMTDTA to sort 231.3 319 4 OPNQRYF and existing access path 258.7 1036 Yes - - 5 OPNQRYF *OPTIMIZE access 210.5 262 No - 182.4 path exists 6 OPNQRYF to build access path 393.8 1163 Yes 115.6 - 7 OPNQRYF *OPTIMIZE no access path 210.5 262 No - 182.4
LATEST COMMENTS
MC Press Online