Showing posts with label NUMPROC. Show all posts
Showing posts with label NUMPROC. Show all posts

Sunday, 11 August 2013

COBOL Performance Tuning: Compiler Options and Runtime Tips

A COBOL batch job that runs for four hours rarely has one magic fix. The slow part may be a table search inside a million-record loop, a small QSAM block size, a SORT returning control record by record, decimal data that needs extra sign handling, or a production compile still using development options. Good COBOL performance tuning starts with evidence from the job log, SMF data, Application Performance Analyzer, RMF, or the site tool your shop uses.

COBOL performance tuning diagram showing measurement, compiler options, file I/O, and FASTSRT
Measure before changing options.

What is COBOL performance tuning?

COBOL performance tuning means reducing CPU time, elapsed time, I/O waits, storage pressure, or chargeable cost without changing the business result. On z/OS, that usually means checking the program logic, compile options, Language Environment settings, file handling, DB2 or VSAM access, and SORT usage together.

The compile listing is the first low-effort check. It shows the actual compiler options used at your site, including any installation defaults that were applied even when the JCL did not specify them.

Start with measurement

Do not tune a job from memory or from a copied option list. Capture the current behavior first. A small change that reduces CPU but increases elapsed time may still be a bad trade in a nightly batch window.

Signal What it tells you Where to look
CPU time Program instruction cost. Job log, SMF, performance tool.
Elapsed time Wall-clock batch window impact. Scheduler history, job output, SMF.
EXCP or I/O count Dataset access cost. SMF, job accounting, monitor reports.
DB2 calls SQL access path and fetch volume. DB2 accounting, EXPLAIN, package stats.
Abends or bad data Options may be hiding data issues. SYSUDUMP, CEEDUMP, application logs.

Compiler options that affect runtime

IBM lists several Enterprise COBOL compiler options that can affect runtime behavior. The right setting depends on the compiler level, processor level, program data, and whether the compile is for test or production.

OPT, ARCH, and TUNE

IBM recommends OPT(2), ARCH(x), and TUNE(y) for best Enterprise COBOL 6 performance. Choose ARCH for the oldest processor where the program may run, including disaster recovery. Choose TUNE for the processor where it usually runs. TUNE must be equal to or higher than ARCH.

//COBOL.SYSIN DD *
       CBL OPT(2),ARCH(12),TUNE(12)
       IDENTIFICATION DIVISION.
       PROGRAM-ID. PAYTUNE.
       ...
/*

Do not copy the sample values blindly. A module compiled for a higher ARCH level can fail if it is moved to an older machine.

TEST and SSRANGE

TEST and SSRANGE are useful during testing and debugging. They can also add overhead. For production, many shops move to NOTEST or a lower-impact debug setting, and NOSSRANGE after bounds issues have been tested. Keep the site standard and audit requirements in mind.

NUMPROC, TRUNC, and ARITH

Numeric options can affect both speed and correctness. NUMPROC(PFD) can reduce extra sign-fix processing, but only when packed and display numeric data contains preferred signs. TRUNC(OPT) can avoid extra binary truncation code, but it assumes data follows the declared picture and usage. ARITH(EXTEND) allows larger intermediate decimal results and can cost more CPU for decimal-heavy programs.

DYNAM, RENT, and THREAD

DYNAM can make maintenance easier because called subprograms can be replaced without relinking the main load module. It can add call overhead. RENT and THREAD may be needed for the runtime environment, but do not treat them as free speed settings. Use them because the program and environment need them.

File I/O tuning

Many COBOL batch jobs spend more time waiting on data than calculating. For QSAM files, check block size, record format, buffering, and whether the file is read in the best sequence. IBM notes that AWO can reduce calls to data management services for QSAM variable-mode output files, and BLOCK0 can let the system determine block size for eligible QSAM output files.

Check these file items

  • Use sensible block sizes instead of forcing tiny blocks.
  • Read the file in key or physical sequence when the job allows it.
  • Avoid opening and closing the same file repeatedly inside a loop.
  • Use the file status field so failed I/O does not trigger wasteful retry paths.
  • For VSAM, check whether the access pattern matches KSDS, ESDS, RRDS, or LDS usage.

SORT and FASTSRT

If a COBOL program uses the SORT statement, check whether FASTSRT applies. IBM describes FASTSRT as a way for DFSORT or an equivalent product to handle input and output without returning to COBOL after each record. Not every sort is eligible, so verify the compile listing and SORT messages.

       SORT SORT-FILE
            ON ASCENDING KEY SORT-ACCOUNT
            USING INPUT-FILE
            GIVING OUTPUT-FILE.

When the SORT step is the bottleneck, also review SORT work space, input order, record length, and whether the sort belongs inside COBOL or as a separate JCL SORT step.

Code patterns that often cost CPU

Compile options help, but source code still matters. A clean compile cannot save a program that searches a 50,000-row table for every input record when a sorted table, binary search, or indexed lookup would fit the problem better.

Look for these patterns

  • Linear table searches inside high-volume loops.
  • Repeated date or string conversion for the same value.
  • Moving large group items when only one elementary field is needed.
  • Calling a small subprogram millions of times when inline logic would be safer and faster.
  • Repeated SQL singleton SELECTs where one cursor fetch can reduce DB2 calls.

A practical tuning checklist

  1. Capture current CPU, elapsed time, I/O count, and major waits.
  2. Read the compile listing and record the actual compiler options.
  3. Check whether production modules are still compiled with debug-heavy settings.
  4. Review hot loops, table searches, calls, file reads, and SQL calls.
  5. Change one major item at a time and rerun the same workload.
  6. Keep a note of the old value, new value, test data, and measured result.

Safe production approach

Tuning should go through the same control path as any other production change. Recompile with the chosen options, compare output files, compare return codes, check numeric totals, and keep the old load module available for rollback. For money fields and packed decimals, include bad-data tests before changing NUMPROC, TRUNC, or ARITH.

Related COBOL tuning topics

For specific compiler option notes, read COBOL OPTIMIZE Compiler Option, COBOL ARITH Compiler Option, COBOL FASTSRT Compiler Option, COBOL AWO Compiler Option, COBOL SSRANGE Compiler Option, COBOL TEST Compiler Option, and COBOL NUMPROC Compiler Option.

External references

Technical notes in this refresh were checked against IBM guidance for tuning COBOL 6 compiler options, IBM performance-related compiler options, and IBM Enterprise COBOL compiler options.

FAQ

Which COBOL compiler options usually affect performance?

Common options include OPT, ARCH, TUNE, FASTSRT, AWO, NUMPROC, TRUNC, ARITH, SSRANGE, TEST, DYNAM, and THREAD.

Should production COBOL always use OPT(2)?

IBM recommends OPT(2) for best Enterprise COBOL 6 performance, but production settings must match your shop standard, debug needs, data quality, and processor compatibility.

Can compiler options fix slow SQL?

No. If the main cost is DB2 access, review SQL predicates, indexes, EXPLAIN output, fetch count, and commit pattern. COBOL compile options will not fix a bad access path.

When should I use FASTSRT?

Use FASTSRT when the COBOL SORT is eligible and the site SORT product can handle the input and output path more efficiently than record-by-record COBOL control.

New In-feed ads