Home > AS/400 Tips > iSeries administrator tips > Optimize your programs to increase performance
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES ADMINISTRATOR TIPS

Optimize your programs to increase performance


Ron Turull
06.08.2005
Rating: -4.17- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



Ron Turull

Way, way back, when the news was filled with the upcoming release of OS/400 V2R1, a program manager at IBM told me that IBM already knew how to optimize programs "up the wazoo," they just didn't have the right environment on the AS/400 yet to implement it. That right environment that the IBMer was referring to was ILE, which we got a few years later. Since then we have been able to reap the rewards of program optimization. If you're not using it, now is the time for administrators to consider it, especially if your system is getting sluggish.

How to optimize your programs

Programs are optimized using the ILE optimizing translator. Access to the optimizing translator is provided by the OPTIMIZE parameter of the CHGPGM, CHGMOD, CHGSRVPGM, and the various ILE create module and create bound program commands (e.g., CRTRPGMOD and CRTBNDRPG).

Optimization is done at the module level. (That is why there is an OPTIMIZE parameter on the CHGMOD and CRTxxxMOD commands.) Each module is optimized as a separate entity with no cross-module optimization taking place. (There is a way to do inter-module optimization, but that is the subject of another article.) When an entire program is optimize (e.g., using the CHGPGM or CHGSRVPGM commands), every module in the program is optimized, but they are still optimized at the module level. That flexibility gives you the ability to optimize some modules in a program while keeping others intact, or optimizing different modules at different levels.

More Information

Three basic levels of optimization

There are three basic levels of optimization from which to choose:

  1. *NONE. No optimization is done, except for what is necessary in order to translate the module.
  2. *BASIC. Some basic optimization is done, but more dramatic optimization -- optimization that can (in very rare instances) cause program errors -- is not performed.
  3. *FULL. All optimization techniques are applied. While this optimization level produces the fastest running code, it can also, in rare circumstances, cause programs to fail (see The price of optimization below). There is a fourth level of optimization, but in addition to doing everything that *FULL optimization does, it simply disables trace data.

The chart below shows an example program optimized at these three different levels and the affect it has on the program run-time performance and object size. It should be noted that while this example shows object size decreasing with increased levels of optimization, sometimes that is not the case; object size often increases as higher levels of optimization are applied.

Optimization level

Run time
(in CPU seconds)

Object size
(in bytes)

*NONE

559

49,664

*BASIC

513

48,640

*FULL

362

48,128

 


The price of optimization

Program optimization comes at a price. The price of optimization is made up of three factors: increased object size (sometimes), debugging difficulties and program errors. The following describes each and gives you some tips to lessen their effect.

Increased object size. Frequently the optimizing translator has to add some code to your program in order to optimize. While the optimizer will delete frivolous code, the code it adds often outweighs this and the net effect is a larger object. However, the increase is generally very small, and on most systems this cost is negligible.

Debugging difficulties. Even at the *BASIC level of optimization, the ILE optimizing translator often has to rearrange code. This can cause problems when debugging an optimized program. For example, a variable may not yet have the expected value when displayed at a certain breakpoint if the code that changes that variable has been rearranged (i.e., placed in a more strategic spot). Additionally, changing the value of a variable under debug may cause unexpected results, such as cause the job to end abnormally. There are two ways to overcome that obstacle:

  1. Thoroughly test your code in a production environment before optimizing it, minimizing the probability of having to debug it after it has been optimized.
  2. Un-optimize the program by either using the CHGPGM specifying OPTIMIZE(*NONE) or by recreating the program/modules. A variation of this is to debug an un-optimized copy of the program.

Program errors. In rare instances, programs optimized with *FULL can fail during run-time with message MCH3601. That is caused by the optimizer rearranging how arrays are processed in a loop. Worst of all, though, is that this error is not consistent; it may occur one time the program is executed and not the next. Take heart, though, because this error is very rare to non-existent (i.e., we haven't heard of any problems yet) in RPG and COBOL because of the way these compilers handle arrays and because array processing is not as common in these languages as it is in languages such as C (where this problem most frequently occurs). One way to avoid the problem is to increment array indexes at the end of the loop. Besides, this is better programming practice anyway.

-----------------------------------
About the author: Ron Turull is editor of Inside Version 5. He has more than 20 years' experience programming for and managing AS/400-iSeries systems.


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
iSeries ILE programming
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
How to use an embedded SQL statement and display the result in a subfile
Eight steps for creating program documentation using AS/400 utilities
Searching fields for values
Searching part of a name or address in AS/400
Top 10 programmer tips YTD
How to use the binder language to manage service programs -- Part 3: Examples and pitfalls
Top 10 programmer tips of 2005
Understanding the binder language on AS/400

Performance
Will overloaded discs impact iSeries performance?
Extend storage capacity on an IBM i without negatively effecting system performance
Database drivers on the i: MySQL vs. IBM Toolbox
Performance tuning for IBM i: The basics and beyond
IBM releases new Power products for the midrange
Top System i admin tips for 2006
Catholic Charities keeps track of homeless with iSeries
i5 error messages: What you need to know
IBM races for clock speed
System shutting down after cleanup

iSeries administrator tips
Analyze the health of your IBM i server with iScore
Researching high availability for your System i shop
Translating Linux for IBM i admins: Using GUI to make it easy
Translating Linux for IBM i admins: Working with jobs and networking
OpenOffice: What to know before making the transition from Microsoft Office
OpenOffice: An enterprise open source solution
Database performance comparisons on IBM i
Translating Linux for IBM i admins: User profile commands
Modern System i reports using Client Access
Tips for installing Lotus Domino server on a System i partition

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts