01.05.2013 Views

Optimizing Your Visual COBOL Applications Darren ... - Micro Focus

Optimizing Your Visual COBOL Applications Darren ... - Micro Focus

Optimizing Your Visual COBOL Applications Darren ... - Micro Focus

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Optimizing</strong> <strong>Your</strong> <strong>Visual</strong> <strong>COBOL</strong><br />

<strong>Applications</strong><br />

<strong>Darren</strong> Self & Chris Glazier<br />

<strong>Micro</strong> <strong>Focus</strong>


Performance matters because…<br />

2


Agenda<br />

• Locating Bottlenecks<br />

• Tuning your Files and the<br />

File Handler<br />

• Configuring OpenESQL<br />

Database Access<br />

• <strong>Optimizing</strong> <strong>Your</strong><br />

Application<br />

3


Out of the Box Performance


Finely Badly<br />

Tuned


The choice is yours…


Locating the Bottlenecks<br />

• <strong>Visual</strong> <strong>COBOL</strong> Profiler<br />

– Native code<br />

– Report at <strong>COBOL</strong><br />

source level<br />

• <strong>Visual</strong> Studio Profiler<br />

– Managed code<br />

– Report at method level<br />

7


<strong>Visual</strong> <strong>COBOL</strong> Profiler<br />

• Works with native code<br />

• Compile with PROFILE directive<br />

• Run application to generate .prf<br />

• Run Profiler to create report<br />

• What information does it provide?<br />

– Gives the total execution time<br />

– By section and paragraph<br />

8


<strong>Visual</strong> Studio Profiler<br />

• Integrated with <strong>Visual</strong> Studio IDE<br />

• Works with .NET managed code<br />

• Allows comparison of profiling data<br />

between different runs<br />

• What information does it provide?<br />

– Gives total execution time by module<br />

– Shows hot code execution paths<br />

9


Tuning <strong>Your</strong> Files and the File Handler<br />

• Access Permissions<br />

• File Definition - Keys<br />

• Fine Tuning EXTFH.CFG<br />

10


Access Permissions<br />

• Examine your data files on a per-file basis.<br />

– How are they being used?<br />

• When opening files:<br />

– Don’t just use open I-O for everything<br />

– Use exclusive access where possible<br />

– Otherwise, allow only readers<br />

– Only where absolutely necessary, give<br />

all others complete access to the file


Access Permissions – Sharing Modes<br />

• Can be specified in SELECT:<br />

or<br />

select test-file assign to “testfile.dat”<br />

…<br />

sharing with |all other|<br />

|no other|.<br />

lock mode is exclusive.<br />

• Can be specified on OPEN:<br />

open i-o sharing with |all other | test-file<br />

|no other |<br />

|read only|.


Access Permissions - READ<br />

Time Taken to Read Records<br />

Exclusive Access Allow Readers Allow All Others<br />

2 mins 2 secs 4 mins 23 secs 8 mins 40 secs<br />

Reading 8,000,000 records from IDX Format 8 file<br />

Sequentially


File Definition - Keys<br />

• If you don’t use it, then lose it! – each key needs<br />

to be updated for each insert and delete.<br />

• Shorter the key the better – fit more in a node<br />

2 Alternate<br />

Keys<br />

Time Taken to Create File<br />

Number of Alternate Keys<br />

3 Alternate<br />

Keys<br />

4 Alternate<br />

Keys<br />

5 Alternate<br />

Keys<br />

5 mins 48 secs 6 mins 19 secs 6 mins 29 secs 30 mins 06 secs<br />

File size<br />

2 alternates = 4,908,620,800<br />

3 alternates = 5,172,377,600<br />

4 alternates = 5,500,134,400<br />

5 alternates = 5,763,891,200


File Definition - Compression<br />

• Data compression<br />

– Minimal performance hit<br />

• Index compression<br />

– Always a performance hit, sometimes severe.<br />

– File Handler must sequentially search entire<br />

node when looking for a key


Compression<br />

Sequential<br />

WRITE<br />

Random<br />

READ<br />

Sequential<br />

READ<br />

Compression Type<br />

None Data Data + Keys<br />

5 mins 35 secs 5 mins 45 secs 9 mins 50 secs<br />

3 mins 34 secs 3 mins 46 secs 4 mins 56 secs<br />

2 mins 04 secs 2 mins 46 secs 2 mins 50 secs


It doesn’t help…


Neither does this…


Fine Tuning the File Handler – EXTFH.CFG<br />

• Options must be set in a configuration file<br />

set EXTFH=c:\extfh.cfg<br />

Can be set in <strong>Visual</strong> Studio<br />

app.config file<br />

• Set on a per file basis<br />

– INDEXCOUNT<br />

– NODESIZE<br />

– LOADONTOHEAP


INDEXCOUNT<br />

• Specifies the number of index nodes to be cached for an<br />

index file. - Default cache size used is now 32 nodes.<br />

• Use when writing files where there are multiple keys<br />

• Use when reading files randomly<br />

• Reading files – sequentially may degrade performance<br />

• Ideal INDEXCOUNT = (Max Tree Depth * No. keys) + No. keys<br />

– Use rebuild /f - to find max tree depth<br />

[XFH-DEFAULT]<br />

[file1.dat]<br />

INDEXCOUNT=42


INDEXCOUNT<br />

2 alt keys 3 alt keys<br />

5 min 48 secs 6 min 19 secs<br />

Time Taken to Create File<br />

4 alt keys 5 alt keys<br />

6 min 29 secs 7 30 mins min 32 6 secs<br />

8 million records, 5 alternate keys, resulting file 5GB


NODESIZE<br />

• The NODESIZE option specifies the size of the<br />

index nodes to use for an indexed file when it is<br />

created.<br />

• NODESIZE={512|1024|4096|16384}<br />

• Use when reading records sequentially<br />

• Avoid using with INDEXCOUNT set high<br />

[XFH-DEFAULT]<br />

[file1.dat]<br />

NODESIZE=4096


NODESIZE – Reading Records<br />

NODESIZE Sequential Access Random Access<br />

1024 3 mins 55 secs 3 mins 09 secs<br />

4096 3 mins 03 secs 4 mins 01 secs<br />

16384 1 mins 59 secs 4 mins 27 secs


LOADONTOHEAP<br />

• Forces the File Handler to load an entire file<br />

onto a memory heap<br />

• All file operations execute in memory, only<br />

writing back to disk when it is closed<br />

• Use only in exclusive mode<br />

• Use only on small files<br />

• Use with caution- Speed vs Data Integrity!<br />

[XFH-DEFAULT]<br />

[file1.dat]<br />

LOADONTOHEAP=ON


File Handling Summary<br />

• Consider tuneables on a file-per-file basis<br />

• Think about permissions.<br />

Can you use exclusive access?<br />

• Avoid key compression if possible.<br />

• Random access – calculate the optimum<br />

INDEXCOUNT figure with rebuild /f<br />

• Sequential access – look at NODESIZE<br />

• Small exclusive files – look at LOADONTOHEAP


Configuring OpenESQL Database Access<br />

• Database Drivers<br />

• OpenESQL Behavior Directive<br />

26


Database Drivers<br />

• Drivers to use<br />

– ODBC = Native Code<br />

– ADO = Managed .NET<br />

– JDBC = Managed JVM<br />

• SQL Server - ODBC vs Native Client<br />

– Do NOT use old SQL Server ODBC drivers<br />

– Use SQL Server Native Client 10.0 or higher<br />

• Oracle – ADO<br />

– Use Oracle Data Provider ODP.NET<br />

– Do not use <strong>Micro</strong>soft’s Oracle Client driver<br />

27


OpenESQL Behavior Directive<br />

• SQL(BEHAVIOR=MAINFRAME) – Fastest<br />

– data access for cursors is read only for all by default<br />

– SQL Server uses firehose cursors, Oracle and DB2 use block fetches<br />

• SQL(BEHAVIOR=ANSI) – Medium Fast<br />

– data access for cursors is updateable for all by default<br />

– SQL Server uses firehose cursors, Oracle and DB2 use block fetches<br />

• SQL(BEHAVIOR=UNOPTIMIZED) – Slowest<br />

– data access for cursors is updateable for all by default<br />

– no block fetching done<br />

– compatible with older MF products<br />

• esqlconfigw utility - Set default BEHAVIOR directive for system<br />

28


Optimization Demo


<strong>Optimizing</strong> <strong>Your</strong> Application<br />

• Application Structure<br />

• Program Structure<br />

• Data<br />

• Code<br />

30


Application Structure<br />

• It’s important!<br />

• Execution formats<br />

• Modularity<br />

31


Execution Formats<br />

• INT code<br />

– Slow, portable, dynamically loaded, not shared<br />

• GNT code<br />

– Fast, dynamically loaded, not shared<br />

• Object code<br />

– OS defined format, not directly executable<br />

– Basis for native executable formats (exe, dll etc)<br />

– More efficient than .gnt<br />

• Managed code (IL, JVM)<br />

– Third party managed environment<br />

– Portable and interoperable on that framework<br />

32


Communicating<br />

• PERFORM - very fast<br />

– Acts locally, potentially on all data<br />

– Does not take parameters<br />

• CALL - slower<br />

– Called code is external<br />

– Takes parameters<br />

– Only those parameters are affected<br />

33


Demo - Execution Formats


Managed code boundary<br />

• Compiled for JVM<br />

– Uses JNI<br />

– Notoriously slow<br />

• Compiled for .NET<br />

– Uses Platform Invoke<br />

– Minimal overhead<br />

36


Program Structure<br />

• Independent procedures<br />

• Logical separation of functionality<br />

• Use sections/paragraphs consistently<br />

37


In <strong>Micro</strong> <strong>Focus</strong>, the guidelines are...<br />

• Do...<br />

– Use SECTIONs<br />

– PERFORM these sections<br />

– Use GOBACK rather than EXIT PROGRAM<br />

• Don’t...<br />

– Use PERFORM THRU or PERFORM paragraphs<br />

– Use inter-section GOTOs<br />

– Use alter, segments, OSVS or RM PERFORM-STYLE<br />

38


A Word on ‘In line Perform’s<br />

• Excellent structured programming technique<br />

• Keep the loop condition simple<br />

– Remember it’s tested each iteration<br />

• Avoid ‘goto’s out of the loop<br />

– Code generator optimises well structured, single exit loops<br />

– Easier to understand<br />

– Avoid problems when moving to managed code


Data - Alignment<br />

• Memory organised into 4 or 8 byte words<br />

• Access across word boundaries is slow<br />

– At least twice as slow<br />

– Up to 50 times slower<br />

• Access across word boundaries gives larger code<br />

– Nine extra instructions for a 4 byte item<br />

on Itanium machines


Data – Alignment Example<br />

• This comp-5 item count-a is aligned<br />

01 grp-item.<br />

03 count-a pic x(4) comp-5.<br />

03 ch pic x.<br />

• This comp-5 item count-b is not aligned<br />

01 grp2-item.<br />

03 ch2 pic x.<br />

03 count-b pic x(4) comp-5.


Data – Alignment Example in Tables<br />

• The stride of a table should be a multiple of 4<br />

– Pad the table to ensure this is true<br />

• Misaligned table item<br />

01 tbl1 occurs 200.<br />

03 count-a pic x(4) comp-5.<br />

03 ref-a pic x(2) comp-5.<br />

03 loc-a pic x comp-5.<br />

• Aligned table item<br />

01 tbl2 occurs 200.<br />

03 count-a pic x(4) comp-5.<br />

03 ref-a pic x(2) comp-5.<br />

03 loc-a pic x comp-5.<br />

03 pic x.


Demo - Alignment Issues


Data Types - Numerics<br />

• Optimal is 4 byte integer comp-5<br />

– Signed or unsigned, but try not to mix in same statement<br />

• 1, 2 or 8 byte OK if required<br />

• Advantages<br />

– Smaller faster code<br />

– Required for some APIs<br />

– Quicker to generate


Data Types – Managed<br />

• Specify managed types whenever possible<br />

– binary-long or float instead of COMP-3 or DISPLAY<br />

– Use at 01 level<br />

• no group items where possible<br />

– Use types instead of <strong>COBOL</strong> PICs<br />

• Managed code directives<br />

– ILEXPONENTIATION”FLOAT” for exponentiation speed


Code - Arithmetic<br />

• Use operands of same type<br />

• Two operand style is always efficient<br />

– add a to b<br />

– divide c into d<br />

• Compute statement without divide operations<br />

– Split into separate COMPUTE and DIVIDE statements<br />

• Avoid using the ON SIZE error


Demo – Arithmetic Issues


<strong>Your</strong> Mission...<br />

• Identification<br />

• Awareness<br />

• Resolution<br />

• Communication<br />

– http://community.microfocus.com


Performance may feel like this...


When it should be like this...


Some Useful Checker Directives<br />

noalter<br />

noseg<br />

noqualproc<br />

noimplicitscope<br />

nocheck<br />

Improves checker speed<br />

Improves checker speed. Catches use of<br />

identical, and confusing, paragraph names<br />

Enforce use of scope delimiters<br />

Catch subtle bugs early<br />

Turn off run time checking


Some useful NCG Directives<br />

nocheck<br />

lnkalign<br />

opt<br />

litlink<br />

linkalias<br />

Turn off run time checking, including<br />

subscript, linkage and divide-by-0 checks<br />

Assert that linkage items aligned<br />

Generates faster code<br />

Turn on global optimisations. Generates<br />

faster code, but takes longer to generate<br />

Ensure calls are linked rather than<br />

dynamically bound<br />

Specify aliasing of linkage items


@microfocus or hashtag #devcon2013<br />

Follow us on LinkedIn or join the group<br />

Connect with your peers on the Community

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!