DBMS Performance Tuning
DBMS Architecture GCF SCF PSF OPF QEF RDF QSF ADF SXF GWF DMF Shared Memory locks log buffers Recovery Server Work Areas Databases log file
DBMS Servers Manages client access to databases Comprises functionality specific facilities By default one per installation Multi-threaded process Has system threads and user threads Configurable
Agenda Disk Location layout CPU Threads Memory Caches
Disk Locations Tables Pages
Locations Names by which Ingres points to a disk area At installation default locations are set up for Database Journal Dump Checkpoint Work Use locations to spread disk IO
Locations A database can be extended to use extra database and work locations A table Can be spread across locations Spread across too many locations may degrade performance Need to understand disk set up for WAN SAN Raid
Locations Alternative locations can be created through Accessdb SQL statements Extenddb To use a location a table must be Relocated Reorganized System catalogs are always in the database home location
Tables Single location verses multiple locations Page size Compressed verses non-compressed Indexing Table structure
Partitioned Tables Queries can scan relevant partitions Can make use of Parallel Query Table partitions can be in different locations A partition can be in multiple locations A table can be partitioned by a distribution HASH List Range Automatic
Example Create table employee ( emp_no integer not null not default, emp_name char(32) not null not default, dept_no integer) with partition = ( (list on dept_no partition p1 values (1, 2), partition p2 values (3, 4), partition p3 values (DEFAULT)) subpartition (hash on emp_no 16 partitions) ); modify employee to btree unique on dept_no, emp_no;
Pages Page size = DMF cache size used Functionality verses performance Lock level Table Page Row
CPU User threads Internal Threads Other things
User threads Number of concurrent connections SQL sent Data returned
Internal threads Dead Process Detector thread Force Abort thread Group Commit thread Consistency Point(CP) thread Event thread WriteBehind(WB) thread (for each configured cache) Replicator Queue Manager thread Terminator thread Parallel Query threads Parallel Sort threads Log writer threads
Parallel Query Partitioning not required for parallel query Partitioning enables more parallelism Partition compatible joins in parallel threads
Parallel Query opf_pq_dop Defines the maximum number of exchange nodes that can be compiled into a query plan 0 or 1 prevents the generation of parallel plans Any other positive value enables them Default 8 Maximum 32
Parallel Query opf_pq_partthread Undocumented and not in config.dat Defines the maximum number of threads per exchange node Default 2 Testing show that more than 6 adds no value
Parallel Query opf_pq_threshold Defines the cost threshold that a query plan must exceed before a parallel plan is generated The cost estimate is the sum of the C and D numbers at the top of the query plan Default 1000
Parallel Query Set [No]Parallel <nn> Controls the generation of parallel query plans Can be used to override opf_pq_dop nn indicates the degree of parallelism The number of exchange nodes in a plan Default 4 Maximum 32
Parallel Sort psort_rows Sets the threshold in rows for doing a parallel sort Sorts of fewer than psort_rows rows will not consider a parallel sort The default is 10000 rows
Parallel Sort psort_nthreads Controls the number of threads used when parallel sorting The default is 2 threads A machine with many CPU's and large sorts may benefit from more worker threads Too many threads Will not help sorting May be slower due to contention
Log Writer threads 1 is not enough Start with 4 or 5 Monitor wait-for-logwriter in logstat Minimize wait-for-logwriter Check log disk if more than 20 configured Consider change to log buffer size
Memory On 32 bit maximum of 4 gigabytes On 64 bit lots more available DBMS Workspace DBMS Resource Logging Locking
DBMS Workspace For example: opf_memory psf_memory qef_qep_mem rdf_memory stack_size Memory Allocated in chunks up to the workspace limit Not obvious how much a session is using
DBMS Workspace For large installations Default configuration creates large workspaces Larger does not mean faster Smaller does not mean less resource usage If queries work Do not change Workspace Parameters If some queries take too long Look at the SQL before changing Parameters, tables structures or indexes
DBMS Resource For example: dmf parameters qsf_memory qef_sort_mem rdf_max_tbls For large installations Default configuration may set parameters too small Larger may mean faster Smaller may mean flushing
DMF Defaults are too small Minimum of 1000 pages for single page caches Larger cache may give gains Massive caches may have decreasing benefit Increase and test 2006 is better than previous releases Tune intelligently - use the tools IMA DM420 Monitor Cache Statistics
DMF: Single page buffers Tune caches for Users Transaction throughput Table usage Allow enough pages so that FHDR's, FMAP's, btree root and index pages do not get flushed Consider using a separate cache for session tables Session tables can be large Session tables can be numerous Session tables do get written to disk if the DMF cache is required
DMF: CBF - dbms.cache.8k.derived Derived DBMS Cache Parameters for 8k Name Value Units Protected dmf_cache_size 42000 data pages yes dmf_free_limit 1312 data pages no dmf_group_count 4500 group buffers no dmf_memory 638976000 bytes no dmf_modify_limit 31500 data pages no dmf_wb_end 12600 data pages no Tuned cache in stages: default was 15000 inadaquate
DMF: Single page buffers : DM420 before =====Thu Aug 2 04:37:16 2007 ==========! Buffer Cache Configuration ( 8K) -------------------------! 8 Buffer count:78000 Bucket count:77999 Group count:4500 Size:! Free count: 8099 Limit:498 Modify count:7911 Limit:13300! Free group count: 4875 Modify group count: 125! Fixed count: 0 Group fixed count: 0! WB start limit: 7500 WB end limit: 5500! WB flushes: 324, Agents cloned: 433! Agents active: 0, Agent hwm: 6! WB pages flushed: 0, WB groups flushed: 0! Summary Statistics ( 8K) ---------------------------------------------------------! GWAIT GSYNC FREEWAIT GW PAGES GW I/O! 0 0 0 2130293 892740! FIX CALLS HITS CHECK REFRESH READ TOSS! 746321221 534464098 4831709 3 859937 82289377
DMF: Single page buffers : DM420 after =====Thu Aug 2 04:37:16 2007 ==========! Buffer Cache Configuration ( 8K) -------------------------! 8 Buffer count:78000 Bucket count:77999 Group count:4500 Size:! Free count: 38751 Limit:1312 Modify count:3249 Limit:31500! Free group count: 4286 Modify group count: 214! Fixed count: 0 Group fixed count: 0! WB start limit: 21000 WB end limit: 12600! WB flushes: 120, Agents cloned: 334! Agents active: 0, Agent hwm: 6! WB pages flushed: 0, WB groups flushed: 0! Summary Statistics ( 8K) ---------------------------------------------------------! GWAIT GSYNC FREEWAIT GW PAGES GW I/O! 0 0 0 220821 79740! FIX CALLS HITS CHECK REFRESH READ TOSS! 656525242 643102876 3341709 3 355997 75279473
DMF: Single page buffers : DM420 before Stats for FHDR pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 1192214 98421 1 0 23354 573440 snip! Stats for FMAP pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 1032639 99626 1 0 23222 593242 snip! Stats for ROOT pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 173121327 122332111 0 0 12438 9196 snip! Stats for INDEX pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 10987543 10542532 0 0 7037 79599 snip! Stats for LEAF pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 364864202 309868363 0 0 128483 3443724
DMF: Single page buffers : DM420 after Stats for FHDR pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 1004114 398096 1 0 14374 603510 snip! Stats for FMAP pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 1005639 399626 1 0 14375 603541 snip! Stats for ROOT pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 186263140 186247369 0 0 12128 10129 snip! Stats for INDEX pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 11613185 11597531 0 0 7037 80979 snip! Stats for LEAF pages:! FIX CALLS HITS CHECK REFRESH READ TOSS! 277170152 276704306 0 0 148883 2413774
DMF: Group buffers Tune buffers for queries Tune queries to keep group buffer usage to a minimum Switch on Gather Write Setting Group Buffers to zero does not result in no group buffers
QSF Query Storage Facility Global memory area Used for storing query objects Used to pass information between facilities Monitor using Trace points IMA QS501 QS512
Logging Log buffers Number Size logstat statistics to tune log parameters Log Waits: Free Buffer Split Buffer Buffer utilization profile All logwriters busy Max write queue length Max write queue count
Logging Log buffers Number - default 35 (recom. 200) Size - default 4K (recom. 8K) logstat statistics to tune log parameters Log Waits: Free Buffer Split Buffer Buffer utilization profile All logwriters busy Max write queue length Max write queue count
Logging Log buffers Number - default 35 (recom. 200) Size - default 4K (recom. 8K) logstat statistics to tune log parameters Log Waits: Free Buffer Split Buffer Buffer utilization profile All logwriters busy Max write queue length < Number of buffers Max write queue count
Logging ----Current log file header----------------------------------------------------- Block size: 8192 Block count: 62500 Partitions: 1 Buffer count: 200 CP interval: 5120 Logfull interval: 56250 Abort interval: 45000 Last Transaction Id: 0000455B4B0FBE8F Begin: <1163633519:37587:2448> CP: <1163633519:42735:5956> End: <1163633519:43170:1224> Percentage of log file in use or reserved: 8 Log file blocks reserved by recovery system: 0 Archive Window: <1163633519,42725,5956>..<1163633519,43170,1224> Previous CP: <1163633519,37587,2448> Status: ONLINE,ECPDONE Active Log(s): II_LOG_FILE
Logging ====Fri May 11 01:42:50 2007 Logging System Summary====== Database add 1068 Database removes 1014 Transaction begins 5979858(6M) Transaction ends 5979559 Log read i/o's 126345 Log write i/o's 126835 Log writes 1209002 Log forces 2807 Log waits 10313 Log split waits 0 Log free waits 0 Log stall waits 8 Log BCP waits 8 Logfull stall waits 0 Log group commit 8337 Log group count 8379 Check commit timer 2326 Timer write 2326 Timer write, time 2 Timer write, idle 2324 Inconsistent db 0 Kbytes written 175777 ii_log_file read 126345 ii_dual_log read 0 write complete 126837 dual write complete 0 All logwriters busy 1369 Max write queue len 85 Max write queue cnt 1 ----Buffer utilization profile--------------------------------------------------------------- <10% ********* 10-19% *************** 20-29% ********************** 30-39% ** 40-49% *** 50-59% ** 60-69% * 70-79% * 80-89% * >90% *********
Logging ====Thu Aug 2 04:37:16 2007 Logging System Summary====== Database add 7558 Database removes 7396 Transaction begins 23557021(23M) Transaction ends 23556713 Log read i/o's 511846 Log write i/o's 515768 Log writes 4435689 Log forces 11185 Log waits 45831 Log split waits 0 Log free waits 0 Log stall waits 32 Log BCP waits 32 Logfull stall waits 0 Log group commit 26852 Log group count 27024 Check commit timer 7782 Timer write 7782 Timer write, time 0 Timer write, idle 7782 Inconsistent db 0 Kbytes written 654183 ii_log_file read 511846 ii_dual_log read 0 write complete 515767 dual write complete 0 All logwriters busy 1001 Max write queue len 99 Max write queue cnt 1 ----Buffer utilization profile-------------------------------------------------- <10% ************* 10-19% ***************** 20-29% *************** 30-39% ***** 40-49% **** 50-59% ** 60-69% * 70-79% * 80-89% * >90% *******
Locking Large installations can generate huge Lock limits Resource limits Result in large lock/log shared memory segments lockstat statistics to tune lock parameters High-water marks for: Lock lists Locks Resources Max locks per transaction
Locking =====Fri May 11 01:42:50 2007 Locking System Summary================= Total Locks 757500 Total Resources 505000 Locks per transaction 3000 Lock hash table 100999 Locks in use 956 Resource hash table 10099 Resources in use 902 Total lock lists 530 Lock lists in use 83 =====Fri May 11 01:42:50 2007 Locking System Statistics============== Create lock list 5980545 Release lock list 5980386 Request lock 107257541 Re-request lock 21338874 Convert lock 257715 Release lock 104970761 Escalate 467 Lock wait 80 Convert wait 0 Convert Deadlock 0 Deadlock Wakeups 21 Max dlk queue len 1 Deadlock Search 21 Deadlock 0 Cancel 0 Convert Search 0 Allocate CB 111698597 Deallocate CB 213755494 LBK Highwater 3 LLB Highwater 95 SBK Highwater 3 LKB Highwater 6019 RBK Highwater 9 RSB Highwater 5975 Max Local dlk srch 0 Dlk locks examined 21 Max rsrc chain len 22 Max lock chain len 21 Max locks per txn 3001 Callback Wakeups 0 Callbacks Invoked 0 Callbacks Ignored 0
Locking =====Thu Aug 2 04:37:16 2007 Locking System Summary================= Total Locks 180000 Total Resources 120000 Locks per transaction 10000 Lock hash table 23993 Locks in use 1047 Resource hash table 23993 Resources in use 968 Total lock lists 2160 Lock lists in use 102 =====Thu Aug 2 04:37:16 2007 Locking System Statistics============== Create lock list 23566093 Release lock list 3565717 Request lock 260246455 Re-request lock 58993453 Convert lock 3696830 Release lock 252073614 Escalate 652 Lock wait 196 Convert wait 5 Convert Deadlock 0 Deadlock Wakeups 122 Max dlk queue len 4 Deadlock Search 130 Deadlock 1 Cancel 1 Convert Search 0 Allocate CB 280445255 Deallocate CB 525058377 LBK Highwater 3 LLB Highwater 119 SBK Highwater 3 LKB Highwater 12787 RBK Highwater 10 RSB Highwater 12733 Max Local dlk srch 2 Dlk locks examined 150 Max rsrc chain len 48 Max lock chain len 47 Max locks per txn 5175 Callback Wakeups 0 Callbacks Invoked 0 Callbacks Ignored 0
A few words about tuning Have a plan Tune with care Know the performance baseline Change one thing at a time Measure the change Understand parameter interactions Monitor important E_* E_DMA00D_TOO_MANY_LOG_LOCKS
A few words about tuning Have a plan Tune with care Know the performance baseline Change one thing at a time Measure the change Understand parameter interactions Monitor important E_* errors. E_DMA00D_TOO_MANY_LOG_LOCKS E_DM004B_LOCK_QUOTA_EXCEEDED E_DM9041_LK_ESCALATE_TABLEMaximum number of locks for transaction exceeded. Escalating to table-level lock on table iiprotect in database mydb
A few more words about tuning Tuning is not difficult Monitoring is a continuous process Be pro-active Health checks can save on Hardware costs Non-stressed installations run for longer
Summary Tune with care Have a plan Go on a training course Ask an expert
Questions & Answers
DBMS Performance Tuning