41
® IBM Software Group © 2008 IBM Corporation DB2 for z/OS Stored Procedures Performance & Hot Topics Nogi Simanjuntak, IBM SHARE session 1334 February 27, 2008

DB2 for zOS Stored Procedures Performance Hot Topics

Embed Size (px)

Citation preview

Page 1: DB2 for zOS Stored Procedures Performance Hot Topics

®

IBM Software Group

© 2008 IBM Corporation

DB2 for z/OS Stored Procedures Performance & Hot Topics

Nogi Simanjuntak, IBMSHARE session 1334February 27, 2008

Page 2: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

2SHARE session 1334 © 2008 IBM Corporation

Important Disclaimer

THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILE EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN ADDITION, THIS INFORMATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM WITHOUT NOTICE. IBM SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION. NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:

• CREATING ANY WARRANTY OR REPRESENTATION FROM IBM (OR ITS AFFILIATES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS); OR

• ALTERING THE TERMS AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT GOVERNING THE USE OF IBM SOFTWARE.

Page 3: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

3SHARE session 1334 © 2008 IBM Corporation

Agenda

Performance considerations

Managing the environments

Hot topics

Java routines

Page 4: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

4SHARE session 1334 © 2008 IBM Corporation

Performance considerations

Consider path length of each invocation

Tune the SQL statements

Page 5: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

5SHARE session 1334 © 2008 IBM Corporation

z/OS

DB2

Sched PROGX

Execute SQL locally

Execute SQLlocally Return parms

C1 rows (only stored procedures)

WLM-SPAS

DRDA orJava orBatch

Client

EXEC SQL CALL PROGX

EXEC SQL OPEN C1 ‘ WITH ‘ RETURN

EXEC SQL

proc end.

PROGX:

Catalog EntrySPASJCL

PROCLIB

STEPLIBPDS/PDSELoad Library(PROGX)

DB2 z/OS Stored Procedures and User-Defined Functions execution

LE Enclave

Page 6: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

6SHARE session 1334 © 2008 IBM Corporation

Should we use stored procedure locally?

When code reuse benefit outweigh overhead (additional 30K+ instructions)

High overhead environment such as Java on z/OS

Dynamic SQL but prefers static SQL

Page 7: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

7SHARE session 1334 © 2008 IBM Corporation

Nested and concurrent routines

Multiple invocations of stored procedures/UDFs requires multiple the resourceOne task per routineScheduling time for each routine

Cancel scenarios become more complexFollow recommended order of eventsCurrent cancel maintenance: PK22811

Page 8: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

8SHARE session 1334 © 2008 IBM Corporation

Performance considerations

Do not call the metadata routinesSYSIBM.SQLPROCEDURECOLSMetadata stored procedure supplied by server Invoked implicitly by V8 CLI clientDB2 LUW client FP4: only invoked if first attempt

fails

DescribeParam=0 in db2cli.iniNeed proper data type assignments

Page 9: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

9SHARE session 1334 © 2008 IBM Corporation

Performance considerations

Do not display/printf() in ProductionDisplay/printf() add debugging statements

Put routine name, timestamps on messages

Multiple routines output to SYSOUT: 02A abendRunopts: 'MSGFILE(SYSOUT,,,, ENQ)'

Expensive

Page 10: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

10SHARE session 1334 © 2008 IBM Corporation

Interactive debugging

IBM Debug Toolwww.software.ibm.com/awdtools/debugtoolCOBOL, C/C++, PL/IHow-to: DB2 Application Programming and SQL

Guide

SQL Procedures debugging in V8

Unified debugger support in V9IBM Data Studio

Page 11: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

11SHARE session 1334 © 2008 IBM Corporation

Performance considerations

STAY RESIDENT YES

PROGRAM TYPE SUB

Different runopts on separate WLM Environment

Page 12: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

12SHARE session 1334 © 2008 IBM Corporation

STAY RESIDENT YES

Reentrant

Stays in storage

Subroutines not affectedMay see many loads of subroutines

Page 13: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

13SHARE session 1334 © 2008 IBM Corporation

PROGRAM TYPE SUB

LE does less processing

May help subroutines stay in storage

Local variables need to be initialized on each invocationSQL-INIT-FLAG in COBOLLINKAGE SECTION vs. WORKING STORAGE

Need to keep LE enclaveNo STOP RUN in COBOL

Different runopts cause LE to build new enclaveDifferent runopts on separate WLM Environment

Page 14: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

14SHARE session 1334 © 2008 IBM Corporation

Performance considerations

Use SP authorization cache ZPARM

ROUTINE AUTH CACHE option on INSTALL DB2 PROTECTION PANEL

If set to 0 no caching is done: catalog access on each invocation

Default 100K Max 5M

Max of 5 IDs cached for each routine

Page 15: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

15SHARE session 1334 © 2008 IBM Corporation

Performance considerations

Use Security DB2

If not accessing non-SQL resources

No need to build special external security environment

Page 16: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

16SHARE session 1334 © 2008 IBM Corporation

Performance considerations

No more than 512 different load modules in one WLM environment

512 entries in table storing load module names

No fancy replacement algorithm

Page 17: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

17SHARE session 1334 © 2008 IBM Corporation

Managing the environment

WLM-SPAS considerations

WLM management of tasks

Control runaways

Page 18: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

18SHARE session 1334 © 2008 IBM Corporation

WLM-SPAS considerations

How many to define

Sensitive applications

TYPE SUB with special runopts

Test/development

Java

Separate if need special JCL

Page 19: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

19SHARE session 1334 © 2008 IBM Corporation

WLM-SPAS considerations

Need to refresh if code modified

V WLM,APPLENV=<APPLENV>,REFRESH

DB2 supplies WLM_RESFRESH SPUse RACF Authority checkCan be invoked remotely

STOP/START SP does not affect load modules in WLM-SPAS

Page 20: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

20SHARE session 1334 © 2008 IBM Corporation

WLM management of tasks

Pre-V8: Enough storage in WLM-SPAS?Too many tasks on NUMTCBMany successful with 40-60If CPU-starved, may need to use less

V8: Tasks are managed by WLMNUMTCB is max

Page 21: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

21SHARE session 1334 © 2008 IBM Corporation

WLM management of tasks

‘1 per system’ vs. ‘no limit’‘no limit’ = managed by wlm

1 TCB per concurrent SP/UDF request?No, managed by WLMRequest queued, more responsive on workload

spikesNUMTCB is max value

Page 22: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

22SHARE session 1334 © 2008 IBM Corporation

WLM Management of Tasks

How to control-STOP PROC/FUNC-CANCEL THDWLM QUISCE

Manual Control http://www-1.ibm.com/support/docview.wss?

uid=swg21239743

Page 23: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

23SHARE session 1334 © 2008 IBM Corporation

Control runaways

Use ASUTIME to control looping

Specified on CREATE

Monitored every 20 seconds

If no ASUTIME specified and looping-Cancel Thread – wait couple minsRefresh WLM environmentCancel WLM address space as a last resortIn the order above!

Page 24: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

24SHARE session 1334 © 2008 IBM Corporation

Hot Topics

zIIP and stored procedures

Native SQL Procedure language

Package Path

Page 25: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

25SHARE session 1334 © 2008 IBM Corporation

zIIP and Stored Procedures

TCB execution not eligible for redirect

Processing on DDF SRB is eligibleCommit, result sets processings

SP benefits still appliesLess network tripsBetter concurrencyStatic sql package invoked from dynamic

DB2 9 Native SQL PL procedure zIIP eligible when invoked over DDF

Page 26: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

26SHARE session 1334 © 2008 IBM Corporation

Native SQL PL procedure language – DB2 9

Eliminates Generated C code and compilation

Fully integrated into DB2 engine

Extensive support for versioningVERSION keyword on CREATE PROCEDURECURRENT ROUTINE VERSION special registerALTERs

Page 27: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

27SHARE session 1334 © 2008 IBM Corporation

Package Path on Create SP – DB9

V8 provides special register to identify list of package collectionSET CURRENT PACKAGE PATH

DB9 added capability to specify during CREATE or ALTER Does not need to be set by invokerDoes not need program change

Simplified administration and management

Page 28: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

28SHARE session 1334 © 2008 IBM Corporation

Java Routines

Performance Considerations

zAAP

Java shared classes

Common JAR

Tips

Page 29: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

29SHARE session 1334 © 2008 IBM Corporation

Java Routine Performance Considerations

Similar considerations applies

Consider path length for each invocation

Tune the SQL statements

Do not call metadata routines

Use SP authorization cache

Do not println() in production

Page 30: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

30SHARE session 1334 © 2008 IBM Corporation

Java Routine Performance Considerations

Use nonresettable JVMGone from JVM 5Not used in DB2 9

Keep JVM alive between invocationTest using JSPDEBUG

Do not use JSPDEBUG in production

Page 31: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

31SHARE session 1334 © 2008 IBM Corporation

Runtime Errors

Uncaught SQL Exceptions-443 SQLCODEStored procedure not put in STOPABN

Other uncaught Java Exceptions-4302 SQLCODEJVM is destroyedStored procedure put in STOPABN

Developer should use try/catch/logic

Print stack trace, fix problem

Page 32: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

32SHARE session 1334 © 2008 IBM Corporation

JSPDEBUG

Information that can be used to debug Java stored procedureCLASSPATHJVM started, brought down

Enabled by JSPDEBUG DD statement

Do not use on production

Page 33: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

33SHARE session 1334 © 2008 IBM Corporation

zAAP

System z Application Assist Processor

Runs Java workload (Java application code)

Java stored procedures eligible

Native system services (i.e.. I/O) not eligible

Page 34: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

34SHARE session 1334 © 2008 IBM Corporation

Java Shared Classes – Java 5

Uses z/OS shared memory segments

Parameter on JVM property file:-Xscmx4M-Xshareclasses:name=myCache

StatisticJava –Xshareclasses:name=myCache,printStats

DestroyJava –Xshareclasses:name=myCache,destroy

Page 35: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

35SHARE session 1334 © 2008 IBM Corporation

Common JAR

V8: Common routines have to be:Included in each JAR that reference them, orStored in HFS and included in CLASSPATH

DB2 9 can install common JAR onceCommon routines packaged in common JARSpecifies other JARs can add it in search pathSQLJ.ALTER_JAVA_PATH

Page 36: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

36SHARE session 1334 © 2008 IBM Corporation

Tips

JVM property startup options – in ENVARHeap size example

"JVMPROPS=/u/<filename>"create a text file in HFS

add this line to the file: -Xmx100M Support for envars > 254 chars in a separate HFS

file:

ENVAR("_CEE_ENVFILE=/u/<filename>"

Page 37: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

37SHARE session 1334 © 2008 IBM Corporation

Tips

Support to direct output to dataset or HFS fileFor println( ) debugging statementsJava logging

//JAVAOUT DD PATH='/u/javasp/out/javaout.txt', // PATHOPTS=(ORDWR,OCREAT,OAPPEND), // PATHMODE=(SIRUSR,SIWUSR,SIRGRP,SIWGRP,SIROTH, SIWOTH) //JAVAERR DD PATH='/u/javasp/out/javaerr.txt', // PATHOPTS=(ORDWR,OCREAT,OAPPEND), // PATHMODE=(SIRUSR,SIWUSR,SIRGRP,SIWGRP,SIROTH, SIWOTH)

Page 38: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

38SHARE session 1334 © 2008 IBM Corporation

Handy Java UDF

CREATE FUNCTION SYSADM.JAVDRVV ( )

RETURNS VARCHAR(100)

FENCED NO SQL

LANGUAGE JAVA

SPECIFIC JAVDRVV

EXTERNAL NAME 'com.ibm.db2.jcc.DB2Version.getVersion'

WLM ENVIRONMENT WLMJAVA

NO EXTERNAL ACTION

NO FINAL CALL

PROGRAM TYPE SUB

PARAMETER STYLE JAVA;

Page 39: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

39SHARE session 1334 © 2008 IBM Corporation

References

Redbookswww.redbooks.ibm.comSG24-7083 Through the call and beyond

DB2 for z/OS: www.ibm.com/software/db2zosFollow ‘support’ link for FAQ’s

DB2 Developer Domain: www.ibm.com/software/data/developer

Page 40: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

40SHARE session 1334 © 2008 IBM Corporation

DB2 UDB for z/OS information resources

• Information center http://publib.boulder.ibm.com/infocenter/dzichelp/index.jsp• Information roadmap www.ibm.com/software/data/db2/zos/roadmap.html• DB2 UDB for z/OS library page www.ibm.com/software/data/db2/zos/library.html• Examples trading post www.ibm.com/software/data/db2/zos/exHome.html• DB2 for z/OS support www.ibm.com/software/data/db2/zos/support.html• Official Introduction to DB2 for z/OS www.ibm.com/software/data/education/bookstore

Take advantage of the following information resources available for DB2 UDB for z/OS:

Page 41: DB2 for zOS Stored Procedures Performance Hot Topics

IBM Software Group

41SHARE session 1334 © 2008 IBM Corporation

Summary

Performance considerations

Managing the environments

Hot topics

Java routines

Nogi Simanjuntak, [email protected]