27
Wed, Nov
0 New Articles

The Fastest Sequencing Method

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: