Vous êtes sur la page 1sur 27

CICS TS 2.

2 and Threadsafe

What’s in it for me?

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


Objectives
• History of Multithreading
• The Open Transaction Environment
• OTE and DB2
• Controlling Threadsafe
• Determining if a program is Threadsafe
• Making programs Threadsafe
• Recommendations
Copyright (c) 2003 R. E. Evans Consulting, LLC 2
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

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


History of Multithreading
• CICS Exploiting Multiple Processors
– Multiple TCBs
– Primary TCB is “QR”, Quasi-Reentrant
– Additional TCBs for:
• VSAM
• DB2
• Program Loader
• etc.

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


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

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


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

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


OTE and DB2
Without Threadsafe

QR TCB Open TCB


Task Starts
EXEC CICS
EXEC SQL DB2 Code executes
Application Code DB2 Code completes
EXEC SQL DB2 Code executes
DB2 Code completes
Copyright (c) 2003 R. E. Evans Consulting, LLC 7
OTE and DB2
With Threadsafe

QR TCB Open TCB


Task Starts
EXEC CICS
EXEC SQL DB2 Code executes
Application Code
DB2 Code executes
Task Termination Task completes
Copyright (c) 2003 R. E. Evans Consulting, LLC 8
CICS and OTE
Without Threadsafe

QR TCB OTE

L8 TCB
Active Task L8 TCB
DB2 SYSTEM CODE L8 TCB
DB2 SYSTEM CODE L8 TCB
DB2 SYSTEM CODE
DB2 SYSTEM CODE

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


CICS and OTE
With Threadsafe

QR TCB OTE

L8 TCB
Active Task L8 TCB
DB2 SYSTEM CODE L8 TCB
DB2 SYSTEM CODE L8 TCB
DB2 SYSTEM CODE
DB2 SYSTEM CODE

Active Task
Active Task
Active Task
Active Task
Copyright (c) 2003 R. E. Evans Consulting, LLC 10
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)

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


So, What’s the Problem
Continued...
Now, the same program running Threadsafe:
OTE TCB #1 OTE TCB #2

MOVE CWA-REC-COUNT TO MOVE CWA-REC-COUNT TO


KEY-UNIQUE-PORTION KEY-UNIQUE-PORTION
ADD +1 TO CWA-REC-COUNT ADD +1 TO CWA-REC-COUNT
EXEC CICS WRITE IMPORTANT-FILE EXEC CICS WRITE IMPORTANT-FILE
RIDFLD(KEY-COMPLETE) RIDFLD(KEY-COMPLETE)
Error, DUPREC
And, CWA-REC-COUNT is incremented by 2
Copyright (c) 2003 R. E. Evans Consulting, LLC 12
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
Copyright (c) 2003 R. E. Evans Consulting, LLC 13
Threadsafe CICS Commands
Not 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

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


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.
Copyright (c) 2003 R. E. Evans Consulting, LLC 15
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
Copyright (c) 2003 R. E. Evans Consulting, LLC 16
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

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


Identifying Threadsafe Programs
Continued...
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
Copyright (c) 2003 R. E. Evans Consulting, LLC 18
Making Programs Threadsafe
After identifying non-Threadsafe code you have
two choices:

1) Alter the code to serialize the shared storage


access

2) Do nothing

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


Making Programs Threadsafe
continued...

If shared storage use is limited to few programs:

• Leave non-threadsafe programs QUASIRENT


• CICS will switch to QR on LINK or XCTL
• Access to shared storage is automatically
serialized

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


Making Programs Threadsafe
continued...

Advantages:
• No coding changes, so quick implementation

Disadvantages:
• Additional TCB switching overhead
• Maintenance issues

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


Making Programs Threadsafe
continued...

Our CWA Issue Resolved by Marking Program QUASIRENT

OTE TCB #1 OTE TCB #2


Switch to QR TCB Switch to QR TCB
MOVE CWA-REC-COUNT TO Wait for QR TCB to become available
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

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


Making Programs Threadsafe
continued...

To serialize access to shared storage:


• “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
Copyright (c) 2003 R. E. Evans Consulting, LLC 23
Making Programs Threadsafe
continued...

Our CWA Issue Resolved by Marking Program QUASIRENT

OTE TCB #1 OTE TCB #2


EXEC CICS ENQ RESOURCE() EXEC CICS ENQ RESOURCE()
MOVE CWA-REC-COUNT TO .
KEY-UNIQUE-PORTION .
ADD +1 TO CWA-REC-COUNT .
EXEC CICS DEQ RESOURCE()
EXEC CICS WRITE IMPORTANT-FILE
RIDFLD(KEY-COMPLETE) MOVE CWA-REC-COUNT TO
KEY-UNIQUE-PORTION

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


Making Programs Threadsafe
continued...

Regardless of which method, remember:

All programs in an application,


or
all programs in a region

Must be converted before activating Threadsafe

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


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

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


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!

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

Vous aimerez peut-être aussi