thread safe

27
Copyright (c) 2003 R. E. Evans Consulting, LLC 1 CICS TS 2.2 and Threadsafe What’s in it for me?

Upload: minsarakanna

Post on 12-Nov-2014

191 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

1

CICS TS 2.2 and Threadsafe

What’s in it for me?

Page 2: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

2

Objectives

• History of Multithreading

• The Open Transaction Environment

• OTE and DB2

• Controlling Threadsafe

• Determining if a program is Threadsafe

• Making programs Threadsafe

• Recommendations

Page 3: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

3

History of Multithreading

• CICS as a Single TCB– Most efficient on a uni-processor– “Quasi-Reentrancy”– Issues:

• Runaway tasks

• OS Waits = Region Wait

• Many restricted OS and COBOL Commands

• Limited by speed of one processor

Page 4: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

4

History of Multithreading

• CICS Exploiting Multiple Processors– Multiple TCBs– Primary TCB is “QR”, Quasi-Reentrant– Additional TCBs for:

• VSAM

• DB2

• Program Loader

• etc.

Page 5: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

5

History of Multithreading

• CICS and DB2

– Separate TCB (‘thread’) for each DB2 Request– Task is switched to DB2 TCB for DB2 work,

DB2 system code runs on DB2 TCB– Significant workload shifted to DB2 TCBs, but

measurable overhead from TCB switching

Page 6: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

6

Open Transaction Environment

• Transaction runs under own TCB

• Introduced in TS 1.3 for Java

• DB2 Support added for TS 2.2

• Supports full OS function

• Allows true Multitasking in CICS

Page 7: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

7

OTE and DB2

QR TCB

Task Starts

EXEC CICS

EXEC SQL

Application Code

EXEC SQL

Open TCB

DB2 Code executes

DB2 Code completes

DB2 Code executes

DB2 Code completes

Without Threadsafe

Page 8: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

8

OTE and DB2

QR TCB

Task Starts

EXEC CICS

EXEC SQL

Task Termination

Open TCB

DB2 Code executes

Application Code

DB2 Code executes

Task completes

With Threadsafe

Page 9: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

9

L8 TCBDB2 SYSTEM CODE

L8 TCBDB2 SYSTEM CODE

L8 TCBDB2 SYSTEM CODE

CICS and OTEWithout Threadsafe

QR TCB

Active Task

OTE

L8 TCBDB2 SYSTEM CODE

Page 10: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

10

Active TaskActive TaskActive Task

L8 TCBDB2 SYSTEM CODE

L8 TCBDB2 SYSTEM CODE

L8 TCBDB2 SYSTEM CODE

CICS and OTEWith Threadsafe

QR TCB

Active Task

OTE

L8 TCBDB2 SYSTEM CODE

Active Task

Page 11: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

11

So, What’s the Problem

Consider a common use of CWA, holding a record counter used to make keys unique:

MOVE CWA-REC-COUNT TO KEY-UNIQUE-PORTION

ADD +1 TO CWA-REC-COUNT

EXEC CICS WRITE IMPORTANT-FILE

RIDFLD(KEY-COMPLETE)

Page 12: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

12

So, What’s the ProblemContinued...

Now, the same program running Threadsafe:

OTE TCB #1 OTE TCB #2

MOVE CWA-REC-COUNT TO KEY-UNIQUE-PORTION

ADD +1 TO CWA-REC-COUNT EXEC CICS WRITE IMPORTANT-FILE

RIDFLD(KEY-COMPLETE)

MOVE CWA-REC-COUNT TO KEY-UNIQUE-PORTION

ADD +1 TO CWA-REC-COUNT EXEC CICS WRITE IMPORTANT-FILE

RIDFLD(KEY-COMPLETE)

Error, DUPREC

And, CWA-REC-COUNT is incremented by 2

Page 13: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

13

Non-Threadsafe CICS Commands

• Many commands not Threadsafe

• Use of non-Threadsafe commands is fully supported by CICS

• CICS detects non-threadsafe command and switches task to QR TCB

• Task remains on QR TCB until next SQL

• Worst case: no CPU improvement if every SQL stmt followed by non-threadsafe cmd

Page 14: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

14

Threadsafe CICS CommandsNot all Exec CICS commands are threadsafe. Here is a list of threadsafe commands supplied by IBM at the last Share conference. All commands not listed are not threadsafe.

ABEND ADDRESS ASSIGN

DELETEQ TS DEQ ENQ

ENTER TRACENUM FREEMAIN GETMAIN

HANDLE CONDITION IGNORE CONDITION LINK

LOAD MONITOR POP HANDLE

PUSH HANDLE READQ TS RELEASE

RETURN SUSPEND WAIT EXTERNAL

WRITEQ TS XCTL DISCARD DB2CON

DISCARD DB2ENTRY DISCARD DB2TRAN INQUIRE DB2CONN

INQUIRE DB2ENTRY INQUIRE DB2TRAN INQUIRE EXITPROGRAM

INQUIRE TASK SET DB2CONN SET DB2ENTRY

Page 15: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

15

Non-Threadsafe CICS Exits

• Area of concern

• Task switched to QR for duration of exit, then back to Open TCB

• Infrequently referenced exits not a problem

• Frequently referenced exits (eg., XEIIN) are a major performance problem

• Worst case: significant (20%++?) increase in CPU utilization.

Page 16: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

16

Controlling Threadsafe• At the region level, new SIT parm:

FORCEQR=YES/NO• FORCEQR=YES All programs run non-Threadsafe

• FORCEQR=NO Programs follow CONCURRENCY parm on program definition

• At the program level:New parameter on Program Definition

• CONCURRENCY=QUASIRENT Not Threadsafe

• CONCURRENCY=THREADSAFE

Page 17: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

17

Identifying Threadsafe Programs

• No automated method of identification

• CONCURRENCY parm is a promise by you, not an order to CICS

• Must be Reentrant– COBOL programs compiled/linked with RENT– Asm programs linked with RENT, test with

RENTPGM=PROTECT

Page 18: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

18

Identifying Threadsafe ProgramsContinued...

There is a tool available to help start…..

• Utility DFHEISUP will scan for CICS commands commonly used in non-threadsafe applications

• Use command table DFHEIDTH

• But, the only way to ensure that an application is Threadsafe is a complete review by an experienced programmer

Page 19: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

19

Making Programs Threadsafe

1) Alter the code to serialize the shared storage access

2) Do nothing

After identifying non-Threadsafe code you have two choices:

Page 20: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

20

Making Programs Threadsafecontinued...

• Leave non-threadsafe programs QUASIRENT

• CICS will switch to QR on LINK or XCTL

• Access to shared storage is automatically serialized

If shared storage use is limited to few programs:

Page 21: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

21

Making Programs Threadsafecontinued...

Advantages:

• No coding changes, so quick implementation

Disadvantages:

• Additional TCB switching overhead

• Maintenance issues

Page 22: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

22

OTE TCB #1 OTE TCB #2

MOVE CWA-REC-COUNT TO KEY-UNIQUE-PORTION

ADD +1 TO CWA-REC-COUNT EXEC CICS WRITE IMPORTANT-FILE

RIDFLD(KEY-COMPLETE)

Wait for QR TCB to become available

Making Programs Threadsafecontinued...

Our CWA Issue Resolved by Marking Program QUASIRENT

Switch to QR TCB Switch to QR TCB

MOVE CWA-REC-COUNT TO KEY-UNIQUE-PORTION

Page 23: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

23

Making Programs Threadsafecontinued...

• “Wrap” access in CICS ENQ/DEQ

• For Assembler, use CS/CDS

• Move data to a serialized facility:– Temporary Storage– DB2 table– …..

NOTE: Avoid OS ENQ

To serialize access to shared storage:

Page 24: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

24

OTE TCB #1 OTE TCB #2

EXEC CICS ENQ RESOURCE()MOVE CWA-REC-COUNT TO

KEY-UNIQUE-PORTIONADD +1 TO CWA-REC-COUNTEXEC CICS DEQ RESOURCE() EXEC CICS WRITE IMPORTANT-FILE

RIDFLD(KEY-COMPLETE)

Making Programs Threadsafecontinued...

Our CWA Issue Resolved by Marking Program QUASIRENT

EXEC CICS ENQ RESOURCE()...

MOVE CWA-REC-COUNT TO KEY-UNIQUE-PORTION

Page 25: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

25

Making Programs Threadsafecontinued...

All programs in an application,

or

all programs in a region

Must be converted before activating Threadsafe

Regardless of which method, remember:

Page 26: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

26

Futures

• Should see more OTE in future releases

• OTE Changes Everything– Loosens OS command restrictions– Better support for “batch” transactions

• task owns the TCB, not the region

– Provides CPU constraint relief

Page 27: Thread Safe

Copyright (c) 2003 R. E. Evans Consulting, LLC

27

Recommendations

• Consider Threadsafe implications now.

• Heavy DB2 users receive greatest savings.

• Convert by application, not by program

• Don’t forget purchased packages

• Watch out for exits!