Optimizing Your Visual COBOLApplicationsDarren Self & Chris GlazierMicro Focus
2Performance matters because…
• Locating Bottlenecks• Tuning your Files and theFile Handler• Configuring OpenESQLDatabase Access• Optimizing YourApplica...
Out of the Box Performance
Finely TunedBadly
The choice is yours…
• Visual COBOL Profiler– Native code– Report at COBOLsource level• Visual Studio Profiler– Managed code– Report at method ...
• Works with native code• Compile with PROFILE directive• Run application to generate .prf• Run Profiler to create report•...
• Integrated with Visual Studio IDE• Works with .NET managed code• Allows comparison of profiling databetween different ru...
• Access Permissions• File Definition - Keys• Fine Tuning EXTFH.CFG10Tuning Your Files and the File Handler
Access Permissions• Examine your data files on a per-file basis.– How are they being used?• When opening files:– Don’t jus...
Access Permissions – Sharing Modes• Can be specified in SELECT:select test-file assign to “testfile.dat”…sharing with |all...
Access Permissions - READReading 8,000,000 records from IDX Format 8 fileSequentiallyTime Taken to Read RecordsExclusive A...
File Definition - Keys• If you don’t use it, then lose it! – each key needsto be updated for each insert and delete.• Shor...
File Definition - Compression• Data compression– Minimal performance hit• Index compression– Always a performance hit, som...
CompressionCompression TypeNone Data Data + KeysSequentialWRITE5 mins 35 secs 5 mins 45 secs 9 mins 50 secsRandomREAD3 min...
It doesn’t help…
Neither does this…
Fine Tuning the File Handler – EXTFH.CFG• Options must be set in a configuration fileset EXTFH=c:extfh.cfgCan be set in Vi...
INDEXCOUNT• Specifies the number of index nodes to be cached for anindex file. - Default cache size used is now 32 nodes.•...
INDEXCOUNT8 million records, 5 alternate keys, resulting file 5GBTime Taken to Create File2 alt keys 3 alt keys 4 alt keys...
NODESIZE• The NODESIZE option specifies the size of theindex nodes to use for an indexed file when it iscreated.• NODESIZE...
NODESIZE – Reading RecordsNODESIZE Sequential Access Random Access1024 3 mins 55 secs 3 mins 09 secs4096 3 mins 03 secs 4 ...
LOADONTOHEAP• Forces the File Handler to load an entire fileonto a memory heap• All file operations execute in memory, onl...
File Handling Summary• Consider tuneables on a file-per-file basis• Think about permissions.Can you use exclusive access?•...
• Database Drivers• OpenESQL Behavior Directive26Configuring OpenESQL Database Access
• Drivers to use– ODBC = Native Code– ADO = Managed .NET– JDBC = Managed JVM• SQL Server - ODBC vs Native Client– Do NOT u...
• SQL(BEHAVIOR=MAINFRAME) – Fastest– data access for cursors is read only for all by default– SQL Server uses firehose cur...
Optimization Demo
• Application Structure• Program Structure• Data• Code30Optimizing Your Application
• It’s important!• Execution formats• Modularity31Application Structure
• INT code– Slow, portable, dynamically loaded, not shared• GNT code– Fast, dynamically loaded, not shared• Object code– O...
• PERFORM - very fast– Acts locally, potentially on all data– Does not take parameters• CALL - slower– Called code is exte...
Demo - Execution Formats
• Compiled for JVM– Uses JNI– Notoriously slow• Compiled for .NET– Uses Platform Invoke– Minimal overhead36Managed code bo...
• Independent procedures• Logical separation of functionality• Use sections/paragraphs consistently37Program Structure
• Do...– Use SECTIONs– PERFORM these sections– Use GOBACK rather than EXIT PROGRAM• Don’t...– Use PERFORM THRU or PERFORM ...
A Word on ‘In line Perform’s• Excellent structured programming technique• Keep the loop condition simple– Remember it’s te...
Data - Alignment• Memory organised into 4 or 8 byte words• Access across word boundaries is slow– At least twice as slow– ...
Data – Alignment Example• This comp-5 item count-a is aligned01 grp-item.03 count-a pic x(4) comp-5.03 ch pic x.• This com...
Data – Alignment Example in Tables• The stride of a table should be a multiple of 4– Pad the table to ensure this is true•...
Demo - Alignment Issues
Data Types - Numerics• Optimal is 4 byte integer comp-5– Signed or unsigned, but try not to mix in same statement• 1, 2 or...
Data Types – Managed• Specify managed types whenever possible– binary-long or float instead of COMP-3 or DISPLAY– Use at 0...
Code - Arithmetic• Use operands of same type• Two operand style is always efficient– add a to b– divide c into d• Compute ...
Demo – Arithmetic Issues
Your Mission...• Identification• Awareness• Resolution• Communication– http://community.microfocus.com
Performance may feel like this...
When it should be like this...
Some Useful Checker DirectivesEnforce use of scope delimitersCatch subtle bugs earlynoimplicitscopeTurn off run time check...
Some useful NCG DirectivesSpecify aliasing of linkage itemslinkaliasEnsure calls are linked rather thandynamically boundli...
@microfocus or hashtag #devcon2013Follow us on LinkedIn or join the groupConnect with your peers on the Community
2.4   Optimizing your Visual COBOL Applications
2.4   Optimizing your Visual COBOL Applications
Upcoming SlideShare
Loading in …5
×

2.4 Optimizing your Visual COBOL Applications

1,184 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

2.4 Optimizing your Visual COBOL Applications

  1. 1. Optimizing Your Visual COBOLApplicationsDarren Self & Chris GlazierMicro Focus
  2. 2. 2Performance matters because…
  3. 3. • Locating Bottlenecks• Tuning your Files and theFile Handler• Configuring OpenESQLDatabase Access• Optimizing YourApplication3Agenda
  4. 4. Out of the Box Performance
  5. 5. Finely TunedBadly
  6. 6. The choice is yours…
  7. 7. • Visual COBOL Profiler– Native code– Report at COBOLsource level• Visual Studio Profiler– Managed code– Report at method level7Locating the Bottlenecks
  8. 8. • Works with native code• Compile with PROFILE directive• Run application to generate .prf• Run Profiler to create report• What information does it provide?– Gives the total execution time– By section and paragraph8Visual COBOL Profiler
  9. 9. • Integrated with Visual Studio IDE• Works with .NET managed code• Allows comparison of profiling databetween different runs• What information does it provide?– Gives total execution time by module– Shows hot code execution paths9Visual Studio Profiler
  10. 10. • Access Permissions• File Definition - Keys• Fine Tuning EXTFH.CFG10Tuning Your Files and the File Handler
  11. 11. Access Permissions• Examine your data files on a per-file basis.– How are they being used?• When opening files:– Don’t just use open I-O for everything– Use exclusive access where possible– Otherwise, allow only readers– Only where absolutely necessary, giveall others complete access to the file
  12. 12. Access Permissions – Sharing Modes• Can be specified in SELECT:select test-file assign to “testfile.dat”…sharing with |all other||no other|.orlock mode is exclusive.• Can be specified on OPEN:open i-o sharing with |all other | test-file|no other ||read only|.
  13. 13. Access Permissions - READReading 8,000,000 records from IDX Format 8 fileSequentiallyTime Taken to Read RecordsExclusive Access Allow Readers Allow All Others2 mins 2 secs 4 mins 23 secs 8 mins 40 secs
  14. 14. File Definition - Keys• If you don’t use it, then lose it! – each key needsto be updated for each insert and delete.• Shorter the key the better – fit more in a nodeTime Taken to Create FileNumber of Alternate Keys2 AlternateKeys3 AlternateKeys4 AlternateKeys5 AlternateKeys5 mins 48 secs 6 mins 19 secs 6 mins 29 secs 30 mins 06 secsFile size2 alternates = 4,908,620,8003 alternates = 5,172,377,6004 alternates = 5,500,134,4005 alternates = 5,763,891,200
  15. 15. File Definition - Compression• Data compression– Minimal performance hit• Index compression– Always a performance hit, sometimes severe.– File Handler must sequentially search entirenode when looking for a key
  16. 16. CompressionCompression TypeNone Data Data + KeysSequentialWRITE5 mins 35 secs 5 mins 45 secs 9 mins 50 secsRandomREAD3 mins 34 secs 3 mins 46 secs 4 mins 56 secsSequentialREAD2 mins 04 secs 2 mins 46 secs 2 mins 50 secs
  17. 17. It doesn’t help…
  18. 18. Neither does this…
  19. 19. Fine Tuning the File Handler – EXTFH.CFG• Options must be set in a configuration fileset EXTFH=c:extfh.cfgCan be set in Visual Studioapp.config file• Set on a per file basis– INDEXCOUNT– NODESIZE– LOADONTOHEAP
  20. 20. INDEXCOUNT• Specifies the number of index nodes to be cached for anindex file. - Default cache size used is now 32 nodes.• Use when writing files where there are multiple keys• Use when reading files randomly• Reading files – sequentially may degrade performance• Ideal INDEXCOUNT = (Max Tree Depth * No. keys) + No. keys– Use rebuild /f - to find max tree depth[XFH-DEFAULT][file1.dat]INDEXCOUNT=42
  21. 21. INDEXCOUNT8 million records, 5 alternate keys, resulting file 5GBTime Taken to Create File2 alt keys 3 alt keys 4 alt keys 5 alt keys5 min 48 secs 6 min 19 secs 6 min 29 secs 7 mins 32 secs30 min 6 secs
  22. 22. NODESIZE• The NODESIZE option specifies the size of theindex nodes to use for an indexed file when it iscreated.• NODESIZE={512|1024|4096|16384}• Use when reading records sequentially• Avoid using with INDEXCOUNT set high[XFH-DEFAULT][file1.dat]NODESIZE=4096
  23. 23. NODESIZE – Reading RecordsNODESIZE Sequential Access Random Access1024 3 mins 55 secs 3 mins 09 secs4096 3 mins 03 secs 4 mins 01 secs16384 1 mins 59 secs 4 mins 27 secs
  24. 24. LOADONTOHEAP• Forces the File Handler to load an entire fileonto a memory heap• All file operations execute in memory, onlywriting back to disk when it is closed• Use only in exclusive mode• Use only on small files• Use with caution- Speed vs Data Integrity![XFH-DEFAULT][file1.dat]LOADONTOHEAP=ON
  25. 25. File Handling Summary• Consider tuneables on a file-per-file basis• Think about permissions.Can you use exclusive access?• Avoid key compression if possible.• Random access – calculate the optimumINDEXCOUNT figure with rebuild /f• Sequential access – look at NODESIZE• Small exclusive files – look at LOADONTOHEAP
  26. 26. • Database Drivers• OpenESQL Behavior Directive26Configuring OpenESQL Database Access
  27. 27. • Drivers to use– ODBC = Native Code– ADO = Managed .NET– JDBC = Managed JVM• SQL Server - ODBC vs Native Client– Do NOT use old SQL Server ODBC drivers– Use SQL Server Native Client 10.0 or higher• Oracle – ADO– Use Oracle Data Provider ODP.NET– Do not use Microsoft’s Oracle Client driver27Database Drivers
  28. 28. • SQL(BEHAVIOR=MAINFRAME) – Fastest– data access for cursors is read only for all by default– SQL Server uses firehose cursors, Oracle and DB2 use block fetches• SQL(BEHAVIOR=ANSI) – Medium Fast– data access for cursors is updateable for all by default– SQL Server uses firehose cursors, Oracle and DB2 use block fetches• SQL(BEHAVIOR=UNOPTIMIZED) – Slowest– data access for cursors is updateable for all by default– no block fetching done– compatible with older MF products• esqlconfigw utility - Set default BEHAVIOR directive for system28OpenESQL Behavior Directive
  29. 29. Optimization Demo
  30. 30. • Application Structure• Program Structure• Data• Code30Optimizing Your Application
  31. 31. • It’s important!• Execution formats• Modularity31Application Structure
  32. 32. • INT code– Slow, portable, dynamically loaded, not shared• GNT code– Fast, dynamically loaded, not shared• Object code– OS defined format, not directly executable– Basis for native executable formats (exe, dll etc)– More efficient than .gnt• Managed code (IL, JVM)– Third party managed environment– Portable and interoperable on that framework32Execution Formats
  33. 33. • PERFORM - very fast– Acts locally, potentially on all data– Does not take parameters• CALL - slower– Called code is external– Takes parameters– Only those parameters are affected33Communicating
  34. 34. Demo - Execution Formats
  35. 35. • Compiled for JVM– Uses JNI– Notoriously slow• Compiled for .NET– Uses Platform Invoke– Minimal overhead36Managed code boundary
  36. 36. • Independent procedures• Logical separation of functionality• Use sections/paragraphs consistently37Program Structure
  37. 37. • Do...– Use SECTIONs– PERFORM these sections– Use GOBACK rather than EXIT PROGRAM• Don’t...– Use PERFORM THRU or PERFORM paragraphs– Use inter-section GOTOs– Use alter, segments, OSVS or RM PERFORM-STYLE38In Micro Focus, the guidelines are...
  38. 38. A Word on ‘In line Perform’s• Excellent structured programming technique• Keep the loop condition simple– Remember it’s tested each iteration• Avoid ‘goto’s out of the loop– Code generator optimises well structured, single exit loops– Easier to understand– Avoid problems when moving to managed code
  39. 39. Data - Alignment• Memory organised into 4 or 8 byte words• Access across word boundaries is slow– At least twice as slow– Up to 50 times slower• Access across word boundaries gives larger code– Nine extra instructions for a 4 byte itemon Itanium machines
  40. 40. Data – Alignment Example• This comp-5 item count-a is aligned01 grp-item.03 count-a pic x(4) comp-5.03 ch pic x.• This comp-5 item count-b is not aligned01 grp2-item.03 ch2 pic x.03 count-b pic x(4) comp-5.
  41. 41. Data – Alignment Example in Tables• The stride of a table should be a multiple of 4– Pad the table to ensure this is true• Misaligned table item01 tbl1 occurs 200.03 count-a pic x(4) comp-5.03 ref-a pic x(2) comp-5.03 loc-a pic x comp-5.• Aligned table item01 tbl2 occurs 200.03 count-a pic x(4) comp-5.03 ref-a pic x(2) comp-5.03 loc-a pic x comp-5.03 pic x.
  42. 42. Demo - Alignment Issues
  43. 43. Data Types - Numerics• Optimal is 4 byte integer comp-5– Signed or unsigned, but try not to mix in same statement• 1, 2 or 8 byte OK if required• Advantages– Smaller faster code– Required for some APIs– Quicker to generate
  44. 44. Data Types – Managed• Specify managed types whenever possible– binary-long or float instead of COMP-3 or DISPLAY– Use at 01 level• no group items where possible– Use types instead of COBOL PICs• Managed code directives– ILEXPONENTIATION”FLOAT” for exponentiation speed
  45. 45. Code - Arithmetic• Use operands of same type• Two operand style is always efficient– add a to b– divide c into d• Compute statement without divide operations– Split into separate COMPUTE and DIVIDE statements• Avoid using the ON SIZE error
  46. 46. Demo – Arithmetic Issues
  47. 47. Your Mission...• Identification• Awareness• Resolution• Communication– http://community.microfocus.com
  48. 48. Performance may feel like this...
  49. 49. When it should be like this...
  50. 50. Some Useful Checker DirectivesEnforce use of scope delimitersCatch subtle bugs earlynoimplicitscopeTurn off run time checkingnocheckImproves checker speed. Catches use ofidentical, and confusing, paragraph namesnoqualprocImproves checker speednoalternoseg
  51. 51. Some useful NCG DirectivesSpecify aliasing of linkage itemslinkaliasEnsure calls are linked rather thandynamically boundlitlinkTurn on global optimisations. Generatesfaster code, but takes longer to generateoptAssert that linkage items alignedGenerates faster codelnkalignTurn off run time checking, includingsubscript, linkage and divide-by-0 checksnocheck
  52. 52. @microfocus or hashtag #devcon2013Follow us on LinkedIn or join the groupConnect with your peers on the Community

×