27
Wed, Nov
0 New Articles

Lab Notes: Improve Performance of Group Processing

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

Group processing is one of the most common reporting requirements-an application summarizes multiple records and provides a group summary record. SQL and the Open Query File (OPNQRYF) command support a special function for grouping. Another traditional method is to use a sort, and summarize the data in a high level language (HLL) program. A less traditional method is to provide for an "in memory" summary (e.g., the use of arrays to accumulate by group). Loading an array for this type of work was described in "The Truth About RPG Performance Coding Techniques," MC, September 1993. The fastest solution shown in that article (except for a technique where the search argument itself could be used as the array index) used the RPG Alternate Lookup (RPGALTLKP) tool from QUSRTOOL. The tool provides standard code that uses a simple hashing algorithm to access an array element that is accumulating values. The tool avoids using the RPG LOKUP op code which takes a long time to accumulate multiple group summaries. RPGALTLKP is in the April 1994 update to QUSRTOOL. To receive this update, ask your SE to send a note to the QUSRTOOL node at RCHVMX2 in Rochester. (For more information, see "Tips for Managing the QUSRTOOL Library," MC, October 1993. ) In the set of tests shown in 1, the traditional solutions of OPNQRYF group processing (case 1) and an OPNQRYF sort with an HLL summarization (case 2) are compared against the RPGALTLKP tool (case 3). The three cases all produce the same result (a printed listing in group order with a count of the records in each group). Each test used no more than 1,000 groups (unique values). The record size was 200 bytes.

Group processing is one of the most common reporting requirements-an application summarizes multiple records and provides a group summary record. SQL and the Open Query File (OPNQRYF) command support a special function for grouping. Another traditional method is to use a sort, and summarize the data in a high level language (HLL) program. A less traditional method is to provide for an "in memory" summary (e.g., the use of arrays to accumulate by group). Loading an array for this type of work was described in "The Truth About RPG Performance Coding Techniques," MC, September 1993. The fastest solution shown in that article (except for a technique where the search argument itself could be used as the array index) used the RPG Alternate Lookup (RPGALTLKP) tool from QUSRTOOL. The tool provides standard code that uses a simple hashing algorithm to access an array element that is accumulating values. The tool avoids using the RPG LOKUP op code which takes a long time to accumulate multiple group summaries. RPGALTLKP is in the April 1994 update to QUSRTOOL. To receive this update, ask your SE to send a note to the QUSRTOOL node at RCHVMX2 in Rochester. (For more information, see "Tips for Managing the QUSRTOOL Library," MC, October 1993. ) In the set of tests shown in Figure 1, the traditional solutions of OPNQRYF group processing (case 1) and an OPNQRYF sort with an HLL summarization (case 2) are compared against the RPGALTLKP tool (case 3). The three cases all produce the same result (a printed listing in group order with a count of the records in each group). Each test used no more than 1,000 groups (unique values). The record size was 200 bytes.

Test Results The SQL and OPNQRYF group functions cause an access path to be built if none exists over the group field. Keyed sequential processing is used to access all records in the file. Although only the summary records are passed to the HLL program, the solution is slow because of the amount of disk access required for keyed processing. In test case 1, no access path existed for the group field. If an access path had existed on the group, the results of case 1 in each test would have been better-but not by a margin large enough to make a difference in the conclusion. The use of OPNQRYF to sort the data provides a better solution than the OPNQRYF group function. Sorting avoids all the random arm movement to access every record. The best solution is the RPGALTLKP tool. This avoids the sort and still lets the file be processed in arrival sequence. The RPGALTLKP tool is a performance-oriented hashing technique. It generates a random number based on a control group's fields. The random number is used as an index to an array that stores the group totals. Because the RPGALTLKP algorithm uses no divide or multiply operations, it is very efficient. The more unique the values of the control group, the better the technique will perform. The tool has a limit of 2,000 groups. In this test, the hashing algorithm used by RPGALTLKP does not produce any duplicates (only unique values exist). In a real situation, this would not be realistic and the performance would be somewhat slower. However, the solution is so much better than sorting that, even with a reasonable number of duplicate hashing values, RPGALTLKP would still produce the best results. This test only summarizes a count of the records in each group. The RPLALTLKP tool sorted the array before printing to provide the correct sequence for the report. You can accumulate other fields and take percentages (including a percentage of each group's part of the total). You can sequence the array on the group field, on any field you are accumulating, or on one of the percentage fields you have created. The tool is reasonably flexible.

When to Use RPGALTLKP The key decision with the RPGALTLKP tool is to determine what produces the best hashing algorithm for your data. You want to choose the positions of your control group field(s) that will produce the most unique values. For example, if your control field is a 5-digit, sequential number, you would want to use positions 3, 4, and 5 rather than 1, 2, and 3, since the low-order positions are more likely to be different than the high-order positions. The Analyze RPG Lookup (ANZRPGLKP) command, shown in 2 assists you in determining what will produce the best results. The ANZRPGLKP command is automatically created when you create the RPGALTLKP tool. It asks you to identify the fields and byte positions within the fields that will provide the best hashing solution and produces spooled output that resembles 3. By default, the command compares a traditional look-up method of loading an array versus the RPGALTLKP approach. You are concerned with the figure that describes the average compares per record for the alternate look-up technique. Any value that approaches 1.0000 shows that the fields and byte positions you specified will produce a fast solution. To use RPGALTLKP, copy the code from the TAARPGFR3 member in file QATTRPG in library QUSRTOOL. It contains instructions (in the form of special comments) to modify the code to fit your needs. Once you have a working program, you can get rid of all the special comments with another TAA tool, RMVSRCCMT. If RPGALTLKP fits your application need, you certainly want to use it from a performance viewpoint.

When to Use RPGALTLKP The key decision with the RPGALTLKP tool is to determine what produces the best hashing algorithm for your data. You want to choose the positions of your control group field(s) that will produce the most unique values. For example, if your control field is a 5-digit, sequential number, you would want to use positions 3, 4, and 5 rather than 1, 2, and 3, since the low-order positions are more likely to be different than the high-order positions. The Analyze RPG Lookup (ANZRPGLKP) command, shown in Figure 2 assists you in determining what will produce the best results. The ANZRPGLKP command is automatically created when you create the RPGALTLKP tool. It asks you to identify the fields and byte positions within the fields that will provide the best hashing solution and produces spooled output that resembles Figure 3. By default, the command compares a traditional look-up method of loading an array versus the RPGALTLKP approach. You are concerned with the figure that describes the average compares per record for the alternate look-up technique. Any value that approaches 1.0000 shows that the fields and byte positions you specified will produce a fast solution. To use RPGALTLKP, copy the code from the TAARPGFR3 member in file QATTRPG in library QUSRTOOL. It contains instructions (in the form of special comments) to modify the code to fit your needs. Once you have a working program, you can get rid of all the special comments with another TAA tool, RMVSRCCMT. If RPGALTLKP fits your application need, you certainly want to use it from a performance viewpoint.

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 the 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.


Lab Notes: Improve Performance of Group Processing

Figure 1 Performance Test Results

 CPU Total Job Results on 1,000 records Seconds Seconds Case 1 OPNQRYF group processing 14.8 30 Case 2 OPNQRYF sort and HLL summarization 9.4 23 Case 3 RPLALTLKP Tool 6.5 15 CPU Total Job Results on 10,000 records Seconds Seconds Case 1 OPNQRYF group processing 75.4 153 Case 2 OPNQRYF sort and HLL summarization 44.0 62 Case 3 RPLALTLKP Tool 22.3 32 CPU Total Job Results on 50,000 records Seconds Seconds Case 1 OPNQRYF group processing 411.2 1166 Case 2 OPNQRYF sort and HLL summarization 211.4 260 Case 3 RPLALTLKP Tool 85.7 102 
Lab Notes: Improve Performance of Group Processing

Figure 2 The Analyze RPG Lookup Command

 UNABLE TO REPRODUCE GRAPHICS 
Lab Notes: Improve Performance of Group Processing

Figure 3 The Analyze RPG Lookup Output

 11/09/94 19:34:12 MCPGMR ANZRPGLKP - Analyze RPG Alternate LOKUP Method File name - DSPOBJDP Library - $SHARIC Member - DSPOBJDP Field 1 - ODOBSZ First pos - 7 Field 2 - ODOBSZ Second pos - 8 Field 3 - ODOBSZ Third pos - 9 Number of records requested - 10,000 Normal lookup request - *YES Number of records in the file - 125 Data values found in the records Unique values - 66 Duplicate values - 59 Records read - 125 Normal load of array and LOKUP operation Total compares - 4,054 Average compares per record - 32.4320 Alternate LOKUP method Total compares - 125 Average compares per record - 1.0000 The discussion of how to use the tool is in member RPGALTLKP for file QATTINFO in QUSRTOOL. The sample source to be copied is in member TAARPGFR3 for file QATTRPG in QUSRTOOL. 
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: