Understanding DB2 Bufferpool Tuning 2005 Final
Understanding DB2 Bufferpool Tuning 2005 Final
Agenda Buffer pool overview Buffer pool management Collecting performance metrics Evaluating performance metrics
Physical vs. logical IO Asynchronous vs. synchronous IO Page cleaner tuning
Q&A
Introduction Q: With so many tuning areas to focus on why should we pay special attention to the buffer pool? A: DB2 uses the buffer pool to offset the performance disparity between CPU and disk, so they are vital for optimizing transaction throughput. From the 8.2 Admin Guide: Performance (emphasis mine):
Because most data manipulation takes place in buffer pools, configuring buffer pools is the single most important tuning area.
Client Application
Prefetchers
External Storage
Listener
Coordinator
Subagents
Buffer Pool
Page Cleaners
Logger
Log
Tuning Goals
Recovery vs. Performance
Recovery wants everything on disk Database manager wants everything in memory Which goal is more important largely depends on data Which combination works best for both goals
High hit ratio means logical reads usually successful, avoiding disk access Normally want to maximize asynchronous I/O to minimize waits
Prefetch
Prefetchers try to ensure that agents doing tablespace scans never wait for disk I/O Agents send asynchronous read-ahead request to common prefetch queue Prefetchers service the request by bringing the requested pages into the buffer pool Should result in logical read, drive hit rate up Two types:
List prefetch, efficiently reads a set of non-consecutive data pages Sequential prefetch, reads consecutive pages
Page Cleaners
Two main goals
Ensure that agents reading a page into the buffer pool never need to first flush a dirty page to disk to free up a slot Speed recovery time by reducing # log files needed
Configuration parameters
num_iocleaners number of page cleaners for a database chngpgs_thresh percentage of changed pages at which the page cleaners will be started, if not currently active
Client Application
Prefetchers
External Storage
Listener
Coordinator
Subagents
Buffer Pool
Page Cleaners
Logger
Log
1 GB BLOB
1 GB BP
Disk
Memory Usage
Version 8 makes DB2 easier to manage by using database global memory (DATABASE_MEMORY) instead of database heap (DBHEAP) Prevents resizing of DBHEAP with bufferpool resizing
CREATE BUFFERPOOL bufferpool_name SIZE number of pages [IMMEDIATE | DEFERRED] [PAGESIZE integer [K]] [[NOT] EXTENDED STORAGE | NUMBLOCKPAGES number of pages [BLOCKSIZE number of pages]] [ALL DBPARTITIONNUMS | DATABASE PARTITION GROUP db_partition_group_name [,]] [EXCEPT ON DBPARTITIONNUM[S] (db_partition_number1 [TO db_partition_number2] SIZE number of pages [,])]
Extended Storage
32-bit DB2 cant support creating buffer pools larger than 4G due to addressable storage limits Extended storage allows DB2 to flush dirty pages to memory rather than disk, so future access to the pages is much faster Requires NUM_ESTORE_SEGS and ESTORE_SEG_SIZE configuration parameters
CREATE BUFFERPOOL bufferpool_name SIZE number of pages [IMMEDIATE | DEFERRED] [PAGESIZE integer [K]] [[NOT] EXTENDED STORAGE | NUMBLOCKPAGES number of pages [BLOCKSIZE number of pages]] [ALL DBPARTITIONNUMS | DATABASE PARTITION GROUP db_partition_group_name [,]] [EXCEPT ON DBPARTITIONNUM[S] (db_partition_number1 [TO db_partition_number2] SIZE number of pages [,])]
CREATE BUFFERPOOL bufferpool_name SIZE number of pages [IMMEDIATE | DEFERRED] [PAGESIZE integer [K]] [[NOT] EXTENDED STORAGE | NUMBLOCKPAGES number of pages [BLOCKSIZE number of pages]] [ALL DBPARTITIONNUMS | DATABASE PARTITION GROUP db_partition_group_name [,]] [EXCEPT ON DBPARTITIONNUM[S] (db_partition_number1 [TO db_partition_number2] SIZE number of pages [,])]
Related Objects
CREATE TABLESPACE specifies which buffer pool to use Page sizes of buffer pool and tablespace must match valid values are 4, 8, 16, and 32 kilobytes CREATE BUFFERPOOL statement can specify partition group, to control partitions in which a given buffer pool is created
Take action
Resize buffer pools Define more page cleaners Break out tables with like workloads
Point in time representation of data Event based representation of data Less overhead (~5%) Need to reissue over time Monitor Switches need to be turned on to collect data Real time balance of application and database performance More overhead (~10-20%) Create it once and it runs until its told to stop Create takes care of everything
Collecting Performance Metrics Issuing a SNAPSHOT request Instance level (requires ATTACH)
For all active databases
GET SNAPSHOT FOR ALL BUFFERPOOLS
BUFFERPOOL and DATABASE snapshot calls are essential for tuning buffer pools
BUFFERPOOL Snapshot
Bufferpool name Database name Database path C:\DB2\NODE0000\SQL00005\ Input database alias Buffer pool data logical reads Buffer pool data physical reads Buffer pool data writes Buffer pool index logical reads Buffer pool index physical reads . . . Node number Tablespaces using bufferpool Alter bufferpool information: Pages left to remove Current size Post-alter size = BASEBP1 = BASEBALL = = = = = = = BASEBALL 300 3490 3050 67 34
= 0 = 4 = 0 = 1000 = 1000
DATABASE Snapshot
Database name Database path . . . Buffer pool data logical reads Buffer pool data physical reads Asynchronous pool data page reads Buffer pool data writes Asynchronous pool data page writes Buffer pool index logical reads Buffer pool index physical reads Asynchronous pool index page reads Buffer pool index writes Asynchronous pool index page writes Total buffer pool read time (ms) Total buffer pool write time (ms) Total elapsed asynchronous read time Total elapsed asynchronous write time Asynchronous read requests LSN Gap cleaner triggers Dirty page steal cleaner triggers Dirty page threshold cleaner triggers Time waited for prefetch (ms) = AUTO_PRD = C:\DB2\NODE0000\SQL00009\
= = = = = = = = = = = = = = = = = = =
165079 36264 10546 3991 3873 4014 558 332 26 26 8329 121852 5353 121292 1681 24 63 33 626
Evaluating Performance Metrics Logical IO vs. physical IO minimize number of times DB2 must access physical disks Key I/O Metrics: Overall hit rate Data hit rate Index hit rate Physical IO read rate
Low values = more physical IO High values = more logical IO 85 90% is a good starting point
Low values = more physical IO High values = more logical IO 85 90% is a good starting point
Low values = more physical IO High values = more logical IO 85 90% is a good starting point
Use:
GET SNAPSHOT FOR TABLESPACES ON database_name
Approach:
Evaluate prefetch ratio Know the workload Evaluate prefetcher configuration Use block I/O
Prefetch Ratio
async.pool .data.read s + async.pool .index.rea ds *100 PrefetchRa tio = bp.logical .reads + bp.index.l ogical.rea ds
Lower values = more synchronous Higher values = more asynchronous Are there enough defined?
Approach:
Evaluate workload and recovery goals Evaluate each metric against all others Modify parameters influencing page cleaner activity Enough page cleaners defined? More automated in V8.1.4 and above
Has an affect on recovery times Too small or too large could be detrimental to buffer pool performance Affected by SOFTMAX DB CONFIG parameter 0 if ALTERNATE_PAGE_CLEANING=ON
Above 40%, typically means buffer pool needs to be larger Could also mean SOFTMAX parameter is too high (not enough page turnover) 0 if ALTERNATE_PAGE_CLEANING=ON
Conclusion
Take action
http://www.quest.com/db2/