57
DB2 Under the Hood: An OS/390 Performance Primer Jim Wankowski Quest Software WWW.Quest.Com/DB2

DB2 Under the Hood: An OS/390 Performance Primer

  • Upload
    tess98

  • View
    1.395

  • Download
    2

Embed Size (px)

Citation preview

Page 1: DB2 Under the Hood: An OS/390 Performance Primer

DB2 Under the Hood:An OS/390 Performance Primer

Jim WankowskiQuest Software

WWW.Quest.Com/DB2

Page 2: DB2 Under the Hood: An OS/390 Performance Primer

Agenda

Defining PerformanceIdentifying/Resolving Performance Issues

The SubsystemPhysical Design ConsiderationsSpace managementApplication Design

Page 3: DB2 Under the Hood: An OS/390 Performance Primer

What is Performance?

Performance: noun“The fulfillment of a claim, promise, or

request”

How does your company define performance?– System availability– Transaction throughput– Minimum response times (SLA’s)

Page 4: DB2 Under the Hood: An OS/390 Performance Primer

Subsystem Monitoring

All aspects of the subsystem need to be monitored.–Not just SQL–Take a look at the big picture

•Where are your bottlenecks?

Page 5: DB2 Under the Hood: An OS/390 Performance Primer

Subsystem Performance

Components to monitor–EDM Pool–RID Pool–Buffer pool–Sort pool

Page 6: DB2 Under the Hood: An OS/390 Performance Primer

Monitoring Subsystem Performance

EDM Pool (Environmental Descriptor Management Pool)

– DBD (Database Descriptor)– CT (Cursor Table)– PT (Package Table)– SKCT (Skeleton Cursor Table)– SKPT (Skeleton Package Table)– Plan/Package authorization Cache (CACHESIZE > 0)– Dynamic SQL skeletons (Dynamic SQL caching

active)

“System Bufferpool”– Minimizes I/O against catalog and directory

Page 7: DB2 Under the Hood: An OS/390 Performance Primer

Problem: An EDM pool that is too small causes:

Increased I/O activity against DSNDB01• SCT02• SPT01• DBD01

Increased response times due to loading the SKCTs, SKPTs, and DBDs Re-preparation of Dynamic SQL Fewer threads used concurrently, due to a lack of storageResource unavailable “-904”

Page 8: DB2 Under the Hood: An OS/390 Performance Primer

What to monitor

EDM Pool hit ratio should be at least 80%– PT/CT’s

• 80-90%– DBD requests

• 100%– Pages used for Package/Cursor tables <50% of pool

Page 9: DB2 Under the Hood: An OS/390 Performance Primer

Sizing EDM Pools

Determining size of EDM Pool– Average DBD size– Average Plan/Package size– Average cache size for Plans

Don’t be afraid to make EDM too big!

Page 10: DB2 Under the Hood: An OS/390 Performance Primer

Managing EDM Pool Size

Reduce size of DBD’sTry to minimize # of objects in database

Use 32K Pieces for large databasesRun MODIFY utility regularly to remove old recovery info.

Dropped objectsREORG tablespaces when tables dropped/recreated

• Dataspaces for Dynamic CachingSpecify a portion of EDM pool in a dataspace

EDMPOOL DATA SPACE SIZE > 0

Page 11: DB2 Under the Hood: An OS/390 Performance Primer

Impact of Plans/Packages onEDM Pool SizeAvoid large Plans

• Use Packages (avoid DBRM’s)• Break applications into separate Plans

DEGREE(ANY) maintains 2 access pathsOne each for Parallelism YES/NO

Bind w/AQUIRE(USE) vs. AQUIRE(ALLOCATE) when possible.Use RELEASE(COMMIT) for infrequently used Plans/Pkg’sUse RELEASE(DEALLOCATE) cautiously

• Can cause EDM pool to grow enormously.• Only change a few programs at a time.

– Monitor EDM pool and IRLM memory usage before/after changing from COMMIT to DEALLLOCATE

Page 12: DB2 Under the Hood: An OS/390 Performance Primer

RID Pool

“Row Identifier” Pool– Enforces unique keys during multi-row

updates– Used for Storing and Sorting RID’s for:

• List Prefetch• Multiple index access• Hybrid Joins

Default size = 4MB– 1000MB max– 0 deactivates Prefetch and multi-IX scans

Page 13: DB2 Under the Hood: An OS/390 Performance Primer

Problem

If RID pool is too small– Previously mentioned access paths can

revert to TS scans

How Big?– #SQL statements requiring RID processing

X Avg number of RID’s X 2 X 4 (5 for LOBs)

Page 14: DB2 Under the Hood: An OS/390 Performance Primer

What to Monitor

Insufficient pool size– RID pool too small

RDS Limit– RID list > 25% #rows in table

• Prefetch turned off and TS scan results

– Determined at Bind time

DM Limit– RIDs req’d to satisfy query >

16 million– TS scan results

Page 15: DB2 Under the Hood: An OS/390 Performance Primer

RID Pool TuningInsufficient pool size– Recalculate RID pool size

– # of concurrent RIDS x Avg #RIDs x 2 x5 bytes/RID

RDS Limit– Have tables grown since

BIND?

–Make sure stats are accurate

• RUNSTATS/REBIND

DM Limit– Is TS Scan best access?– Re-evaluate indexes– Add additional filtering

Page 16: DB2 Under the Hood: An OS/390 Performance Primer

BufferpoolsBuffer Pages

Hiperpool

Virtual storage for temporarily holding data and IX pages– Use DBM1 address space

• Virtual bufferpools• Can define up to 80 BP’s

– Limited to 1.6GB total

– DBM1 + Hiperspace• Hiperpools• Additional 8GB of extended storage• “Holding tank” for infrequently updated data

– MVS Dataspace• Support up to 8M buffers• Allows for direct I/O from extended storage

DASD

Buffer Pages

Virtual BP

Page 17: DB2 Under the Hood: An OS/390 Performance Primer

BufferpoolsHiperpools

Advantages– Less space required for virtual pools

• Reduce central storage requirements– Serve as cache for infrequently accessed

data• Reduced response times vs. accessing DASD

– Use hiperpools when paging rates are high on virtual pools

Disadvantage– No direct I/O from Hiperpool

• Data is transferred back into virtual pool

Page 18: DB2 Under the Hood: An OS/390 Performance Primer

Monitoring Bufferpools-Display BP

3rd Party monitor

Page 19: DB2 Under the Hood: An OS/390 Performance Primer

What to Monitor Buffer Pool hit ratio

(GETPAGES – pages read)/GETPAGES

Hiperpool Hit Ratio– #pages read from

hiperpool/pages written

Page Externalization– Excessive writes to disk

• Deferred write threshold (DWQT)

• Vertical Deferred Write Threshold (VDQWT)

Page 20: DB2 Under the Hood: An OS/390 Performance Primer

Effective Use of BufferpoolsThe single biggest performance mistake is to stick everything in BP0!– DB2 has 80 bufferpools available for a reason!

Separate bufferpools for:Catalog and Directory (BP0)DSNDB07Tablespaces Indexes

• Large VPSIZE• More than one

Small, Read-only tablesLarge tablespaces w/random processingSmall frequently updated tables and IX’sTest environment for isolating test cases

Page 21: DB2 Under the Hood: An OS/390 Performance Primer

Sort PoolsSort pools should be made as large as possible– 240K – 64MB

• The larger the sort pool, the more efficient the sort

• Default to 1MB

Minimizes externalizing to physical sort files and BP’s

•DSNDB07

Page 22: DB2 Under the Hood: An OS/390 Performance Primer

Optimizing SortDSNDB07– Do not use BP0!– 4 –5 equally sized datasets– Keep in primary space– Separate volumes– Also used for:

• View, temp table, and nested table expression materializations

• Non-correlated in-lists

Application Considerations– Avoid ORDER by, Group By, Distinct– Avoid sorting VARCHARs– Only select required columns

Page 23: DB2 Under the Hood: An OS/390 Performance Primer

Physical Design

DB2 Catalog/DirectoryPhysical Objects– Tablespace– Index

Page 24: DB2 Under the Hood: An OS/390 Performance Primer

Problem

A poorly designed/maintained catalog can result in:– Slow response time from catalog queries– Contention with other users

Page 25: DB2 Under the Hood: An OS/390 Performance Primer

The DB2 CatalogDesign Considerations– BP0 is isolated to the catalog only– Keep catalog and directory on separate

volumes• Do not put other DB2 objects on catalog volume

– Keep EXTENTS to a minimum• Use REORG or RECOVER to re-allocate

– Do not migrate catalog datasets (DFSMS)

Page 26: DB2 Under the Hood: An OS/390 Performance Primer

DB2 CatalogMaintenance–Eliminate redundant grants in AUTH

tables• Can be significant in older DB2 environments• Can cause significant performance impact

–Schedule regular maintenance• Treat Catalog like application

– RUNSTATS– REORG

•Reorg related directory tables at same time

– SYSDBASE + DBD01– SYSPLAN + SCT02– SYSPACKAGE + SPT01

Page 27: DB2 Under the Hood: An OS/390 Performance Primer

DB2 Catalog

To avoid contention:Limit DDL and Binds to off hoursCreate “canned” queries for catalog reports using VIEWSKeep RUNSTATS current

Page 28: DB2 Under the Hood: An OS/390 Performance Primer

Tablespace Design

What type of tablespace?Simple SegmentedPartitioned

Page 29: DB2 Under the Hood: An OS/390 Performance Primer

SimpleIn General avoid, use Segmented

Advantage• If “READ ONLY” and data from 2 tables is being

retrieved in a hierarchical order

– Data from tables can be co-mingled onto same pages

Disadvantages• Data from multiple tables on same page• Page/Table locks can lock data from multiple tables• Tablespace scans can be much slower if multiple tables

in TS• Utilities lock entire TS• Dropped table space not immediately available

Page 30: DB2 Under the Hood: An OS/390 Performance Primer

SegmentedBest choice for most applicationsAdvantage

• TS scans only scan segments assigned to table• Multiple tables data is not co-mingled

– Data pages organized into segments (4-64)– Table locks do not affect other tables

• Dropped table or mass delete space immediately available

– Only space map updated– No REORG required

• Less logging for mass delete

Disadvantage• LOAD REPLACE, RECOVER, and COPY must be for

entire tablespace

Page 31: DB2 Under the Hood: An OS/390 Performance Primer

Segmented

Choosing SEGSIZE

For efficient sequential prefetch on small tables, choose a segsize = #pages in largest table

Pages Segsize<28 4-28

>28<128 32>128 64

Page 32: DB2 Under the Hood: An OS/390 Performance Primer

PartitionedBest choice for very large tables or when Parallelism requiredAdvantages

• Spread data across multiple devices and bufferpools

• Partition independence– Utilities more manageable– Higher availability

• I/O Parallelism– Prefetch data from multiple partitions

concurrently• Query Parallelism

– Partitions can be spread across SYSPLEX members

Page 33: DB2 Under the Hood: An OS/390 Performance Primer

Partitioned

Disadvantage• Fixed # of partitions

– Table must be dropped to add/remove partitions (changing in V8)

• TS Scans less efficient than segmented• More open datasets

Page 34: DB2 Under the Hood: An OS/390 Performance Primer

Index considerations

Separate bufferpools from tablespacesAvoid updated columns– Especially for partitioning keys

Have thorough knowledge of SQL– Composite key IX’s can sometimes be more

efficient than single column keys– Use Asc/Desc to avoid sorting

Page 35: DB2 Under the Hood: An OS/390 Performance Primer

Space Management

Efficient DASD UtilizationCompressionObject Maintenance

Page 36: DB2 Under the Hood: An OS/390 Performance Primer

Efficient DASD Utilization

Allocate DB2 datasets to use only primary space– Excessive extents can cause inefficient I/O

Determine best page size for application– Data sharing

• 8K or 16K page size can reduce overhead in coupling facility

Use HSM to manage datasets– Move infrequently accessed datasets to slower devices

Page 37: DB2 Under the Hood: An OS/390 Performance Primer

Compression

Use COMPRESS when applicable– More rows/page minimizes I/O

• Higher BP hit ratios• Fewer Getpage requests

– Always use hardware compression • Significantly less overhead than

EDITPROC/FIELPROC– Less DASD– Use DSN1COMP to check compression rate

Page 38: DB2 Under the Hood: An OS/390 Performance Primer

CompressionConsiderations–For heavily updated data

• Increase PCTFREE to avoid increases in:–Synchronous reads–Lock requests–Getpage requests

–Decoding is much cheaper than encoding

–Overhead for TS scans can be higher–Cheaper for IX scans

Page 39: DB2 Under the Hood: An OS/390 Performance Primer

Maintenance

Proper maintenance is critical for optimal performance– REORG– RUNSTATS– Real-Time Statistics

Page 40: DB2 Under the Hood: An OS/390 Performance Primer

Reorg

What causes fragmentation?– Insert/Update

• Check PCTFREE and FREEPAGE– VARCHAR fields being updated

Page 41: DB2 Under the Hood: An OS/390 Performance Primer

Monitoring for REORGsWhen to Reorg a tablespace:– CLUSTER RATIO < 95%

• SYSINDEXES– CLUSTERATIO < 95%

• SYSINDEXPART– FAROFFPOS > 10% of CARD

– Excessive row relocation• SYSTABLEPART

– NEARINDREF+FARINDREF > 10% of CARD

– Excessive extents (>50)– Excessive drop space

• Simple TS only– PERCDROP > 10%

– LOB tablespaces• SYSLOBSTATS

– ORGRATIO > 2

Page 42: DB2 Under the Hood: An OS/390 Performance Primer

Monitoring for REORGs

When to REORG an Index–Excessive distance between LEAF

pages• SYSINDEXPART

–LEAFDIST > 200» Can cause Pre-fetch to be disabled» Should be monitored for growth

–LEAFFAR > 10% of NLEAF (SYSINDEXES)

–Excessive extents (>50)

Page 43: DB2 Under the Hood: An OS/390 Performance Primer

RUNSTATS

Accurate statistics are a critical factor for performance monitoring and tuning

• RUNSTATS provides statistical information for:

1.Optimization of SQL2.Monitoring status of objects

Page 44: DB2 Under the Hood: An OS/390 Performance Primer

RUNSTATSWhen to run RUNSTATS:

After LOAD, REORG, and REBUILD IXAfter creating new indexAfter heavy insert, update, delete activity

Performance Tip:Only run RUNSTATS against partitions which have changed.Consider using the SAMPLE option for column statistics to reduce processor costs• Be sure to check access paths when using

SAMPLE option

Page 45: DB2 Under the Hood: An OS/390 Performance Primer

Monitoring RUNSTATSREBIND after RUNSTATS?

New index createdCLUSTERRATIOF changes <> 80%Changes more than 20%• Cardinality• NPAGES• NACTIVEF• NLEAF• Range of HIGH2KEY to LOW2KEY

Page 46: DB2 Under the Hood: An OS/390 Performance Primer

Real Time Stats

New for V7• Facility for automating the collection

of DB2 statistics• Stored procedure DSNACCOR

1. Recommends when to REORG, Copy, or run RUNSTATS

2. Identifies TS and IX’s that have exceeded their dataset extents

3. Identifies objects in restricted state4. Stores data in new stats database DSNRTSDB5. Application must be built around DSNACCOR to

return information

Page 47: DB2 Under the Hood: An OS/390 Performance Primer

Real Time StatsCreate stats database– DDL in SDSNSAMP(DSNTESS)

Set collection interval– Install panel DSNTIPO “Real TIME STATS”– DSNZPARM = STATSINT– Default interval = 30 Minutes– Data sharing environment has 1 interval per member

Start statistics database– START DATABASE(DSNRTSDB)

Page 48: DB2 Under the Hood: An OS/390 Performance Primer

Application DesignApplication prepSQL Design considerationsOptimization HintsBind considerations

Efficient application design is the single most important aspect of an efficiently performing subsystem

Page 49: DB2 Under the Hood: An OS/390 Performance Primer

Program PreparationCheck Object ValidityCheck authorityCompute filter factorsChoose access pathPrefetch Y/N

ApplicationCode

Precompile

ExecutableLoad

Module

DBRM Bind

Optimizer

DB2Catalog

Planor

Package

LinkEdit

Compile

DSNDB01SKCTSKPT

Page 50: DB2 Under the Hood: An OS/390 Performance Primer

Optimization TipsOrder predicates from most to least restrictiveAvoid sorts– ASC/DESC indexes can help

avoid excessive sorting

Avoid UNION clause– CASE expression more

efficient

AND MOST IMPORTANTLY…..

Make sure statistics are accurateUse stage 1 vs. stage 2 predicatesOnly select required columns– Avoid SELECT *

Keep predicates as restrictive as possible– Minimize # rows

returned– Minimize program

filtering and let DB2 do the work EXPLAIN!!!!EXPLAIN!!!!

Page 51: DB2 Under the Hood: An OS/390 Performance Primer

Optimization Hints

Allows for user specified access path– Useful for maintaining access paths:

• across releases• After Rebinds

– Should be used cautiously

Page 52: DB2 Under the Hood: An OS/390 Performance Primer

Using HintsSave access path info for all critical queries before using HINTSPlan_Table must be in correct 49 column formatDSNZPARM, Optimization Hints = YesAdd QUERYNO clause to SQLUpdate Plan_Table – Specify name in OPTHINT for desired access path– Static -REBIND PLAN(XYZ) EXPLAIN YES

OPTHINT(‘MYACCESS’)– Dynamic – Set Current Optimization Hint = ‘MYACCESS’

Page 53: DB2 Under the Hood: An OS/390 Performance Primer

Bind ConsiderationsACQUIRE (ALLOCATE)/ RELEASE (DEALLOCATE)

• Best for long running applications• Good for batch processes

Advantage• Helps prevent deadlocking

Disadvantage• Reduces concurrency• Can lock all partitions of TS if LOCKPART YES• N/A for BIND PACKAGE• Can cause EDM pool overflow

Page 54: DB2 Under the Hood: An OS/390 Performance Primer

Bind ConsiderationsACQUIRE(USE)/RELEASE(DEALLOCATE)

• Best choice for most applications

Advantage• Locks are taken only as needed• Least restrictive locks used• Locks released when plan terminates

Disadvantage• Can increase frequency of deadlocks

Page 55: DB2 Under the Hood: An OS/390 Performance Primer

Bind ConsiderationsACQUIRE(USE)/RELEASE(COMMIT)

• Best for maximum concurrency

Advantages• Table/TS locks taken only when needed• Least restrictive lock selected• All locks released at COMMIT

– Unless CURSOR WITH HOLD

Disadvantage• Excessive overhead for frequent COMMITS• Increased frequency of deadlocks

Page 56: DB2 Under the Hood: An OS/390 Performance Primer

SummaryBuild a strategy for how you will monitor/tune your DB2 environment– Try to identify most critical applications and begin

focusing on those– Set realistic performance expectations– Tune, monitor, tune, monitor…

Page 57: DB2 Under the Hood: An OS/390 Performance Primer

THANK YOU FOR LISTENING!

For more information:WWW.Quest.Com/DB2