There was a Micro Focus COBOL program running on a Unix platform that processed millions of records. Every time we modified this program for a business requiremnt and tested it, it ran for about 1 hour, making the development and testing process both time-consuming and frustrating.
To improve the situation, I decided to investigate why the program's execution time was so high.
After analyzing the code, I found that for every input record, the program performed a dynamic read against a VSAM indexed file using a partial key and continued reading until the key changed. Since this operation was executed for every input record, it contributed significantly to the overall processing time.
What caught my attention was that the VSAM file contained only about 10,000 records. Given its relatively small size, I determined that loading the entire file into memory would be far more efficient than repeatedly performing indexed file reads. To minimize memory usage, I stored only the key fields and the specific portion of each record required for processing.
However, there was an additional challenge. The program needed to process all records that matched a partial key. Since binary search works only when the search key uniquely identifies an entry, duplicate partial keys required a different approach. To address this, I designed two working-storage tables:
WS-TABLE1 contained unique partial keys along with the starting and ending positions of their corresponding records in a second table.
WS-TABLE2 contained the full key and the data required for processing.
01 WS-TABLE1.
05 WS-TBL1-CNT PIC S9(08) COMP.
10 WS-TBL1-ENTRY OCCURS 1 TO 10000 TIMES
DEPENDING ON WS-TBL1-CNT
ASCENDING KEY WS-PARTIAL-KEY
INDEXED BY TBL1-IX.
15 WS-PARTIAL-KEY PIC X(06).
15 WS-START-POS-IN-TBL2 PIC S9(08) COMP.
15 WS-END-POS-IN-TBL2 PIC S9(08) COMP.
01 WS-TABLE2.
05 WS-TBL2-CNT PIC S9(08) COMP.
10 WS-TBL2-ENTRY OCCURS 1 TO 10000 TIMES
DEPENDING ON WS-TBL2-CNT.
15 WS-FULL-KEY PIC X(10).
15 WS-DATA-TO-PROCESSED PIC X(20).
The program logic was modified to use the following processing approach:
1. Load the VSAM file into the two in-memory tables during program initialization.
2. Perform a binary search on WS-TABLE1 using the partial key.
3. Once a match was found, retrieve the start and end positions stored in the matching entry.
4. Use those positions to access and process all corresponding records in WS-TABLE2.
By replacing the repeated VSAM indexed reads with an in-memory binary search solution, the program's execution time was reduced from approximately 60 minutes to just 15 minutes.
This optimization resulted in a 75% reduction in runtime, saving about 45 minutes per execution and significantly improving both development testing cycles.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.