1 / 80

ASE 105: The MDA Tables - Finding Out What Goes On Inside ASE

ASE 105: The MDA Tables - Finding Out What Goes On Inside ASE. Rob Verschoor Consultant, Sypron B.V. rob@sypron.nl Peter Dorfman Senior Staff Software Engineer Sybase, Inc. peter.dorfman@sybase.com. About us. About Rob consultant for ASE & Replication Server worked with ASE since 1989

wilona
Download Presentation

ASE 105: The MDA Tables - Finding Out What Goes On Inside ASE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASE 105: The MDA Tables - Finding Out What Goes On Inside ASE Rob Verschoor Consultant, Sypron B.V. rob@sypron.nl Peter Dorfman Senior Staff Software Engineer Sybase, Inc. peter.dorfman@sybase.com

  2. About us About Rob • consultant for ASE & Replication Server • worked with ASE since 1989 • based in The Netherlands www.sypron.nl rob@sypron.nl Published three books about Sybase: “The Complete Sybase Replication Server Quick Reference Guide” (new) "The Complete Sybase ASE Quick Reference Guide” (3rd edition, new) "Tips, Tricks & Recipes for Sybase ASE"

  3. About us About Peter • 11+ years at Sybase ASE Engineering • Designed and developed system management, monitoring and diagnostic tools for the ASE • Leads the design and development of system management features for the ASE and other Sybase database products peter.dorfman@sybase.com

  4. Topics • Quick introduction to MDA tables • Possible applications of MDA tables • What’s that application doing? • Diagnosing bottlenecks • Identifying unused indexes • Identifying ‘hot’ tables • Historical MDA tables • Archiving historical MDA table data • Performance impact of MDA tables • Counter wrap • Analyzing stored procedure activity • Miscellaneous topics

  5. Quick introduction to MDA tables • MDA tables were introduced in ASE 12.5.0.3 • MDA = Monitoring and Diagnostic Access • also called “monitoring tables” • 35 proxy tables in ‘master’ database • monSysSQLText, monObjectActivity, monCachedObject (etc.) • can be accessed with regular SQL statements • when queried, tables are created on-the-fly from memory structures • no data is stored in master database • Must be installed: ‘installmontables’ script • No license needed: included in ASE base product • Only small performance impact on ASE (<5%)

  6. Quick introduction to MDA tables • MDA tables provide access to low-level monitoring data • resource usage in ASE per table/query/entire server • current activity in ASE per spid/query/procedure/table • recent activity: recently completed statements, with the resources they required • Some examples of practically relevant information: • amount of memory occupied in the data cache by each table or index • most frequently used tables/procedures • top-N queries for CPU, I/O, elapsed time,... • find unused indexes • SQL text of currently executing/recently executed statements • automatically kill user processes that have been idle for more than X minutes • provide server status information even when tempdb is full

  7. Interesting Facts about MDA Tables • MDA table data does not take up disk space • Data is generated on-the-fly when an MDA table is queried • Exception: Historical table data is stored in ASE memory • Queries on MDA tables cause a second connection to the server • sysprocesses.program_name = OmniServer-# • # is the SPID for the process that ran query on MDA table • E.g., OmniServer-56 • Some MDA table data is shared with sp_sysmon and Monitor Server • These columns will be cleared if sp_sysmon clears counters

  8. Quick introduction to MDA tables • For more MDA basics, and a brief discussion of all tables: • see Rob’s presentation from Techwave 2003 (www.sypron.nl/mda) • In this presentation: • we want to go one step further than just the basics • look at practical applications of MDA tables • things that are useful for you as a DBA

  9. Possible applications of MDA tables

  10. What’s that application doing? • Does this sound familiar? • a third-party ‘black box’ application runs on your ASE server • you have the feeling it sometime slows down the entire server... • … but you don’t know which queries it is sending to ASE • Classic solutions: • use “cmdtext” auditing to intercept the application’s T-SQL commands • use traceflag 11202 (writes all incoming client language to the errorlog) • use third-party tools to find T-SQL commands by intercepting network packets • dbcc sqltext() • …but all these methods have significant limitations or drawbacks

  11. What’s that application doing? • Solution: MDA tables monProcessSQLText & monSysSQLText • monProcessSQLText: currently executing SQL • monSysSQLText: recently executed SQL, now completed • Historical table • Lets you “look back” in time • By copying rows regularly into an ‘archive’ table, complete history can be preserved

  12. What’s that application doing? • Also handy for RepServer DBAs: • Quick way to figure out exactly which SQL is executed against your replicate DB • Especially handy when developing/debugging custom function strings • You can look for specific statements only: select SQLText from master..monSysSQLText where SQLText like “%MyTable%”

  13. Diagnosing bottlenecks • Performance tuning is all about finding bottlenecks • There’s no point in optimizing something that isn’t a bottleneck • Historically, it’s been difficult to diagnose bottlenecks in ASE • sp_sysmon provides some info about some aspects of resource usage... • … but interpretation is still difficult • … and sort-of requires having eliminated application-level bottlenecks first • MDA tables offer a new angle on bottlenecks: wait event info • MDA tables: monProcessWaits, monSysWaits • Contain wait times for ~300 different internal wait events (monWaitEventInfo) • monSysWaits: for entire ASE server • monProcessWaits: for currently active spids • Wait times are cumulative and universally increasing

  14. Diagnosing bottlenecks • Here’s the idea: • When something is a bottleneck, someone in ASE is waiting for it • By looking at the distribution of wait times during an interval, a bottleneck might be identified • One extreme: the server is completely quiet • All spids are waiting for input from the network • Other extreme: the server is perfectly, fully utilised • spids are mostly being scheduled around to do real work • When a bottleneck exists: • You’d expect to see wait time peaks for certain events

  15. Diagnosing bottlenecks • Tool: stored procedure ‘sp_mda_wait’ • Samples current wait time counters • Waits for a certain interval • Samples wait time counters again • Calculates and reports differences (delta values) sp_mda_wait [ spid ] [, ‘hh:mm:ss’ ] [, top_N ] • Defaults: • spid = NULL : entire server • interval: 10 seconds • top_N = 20 • Procedure can be downloaded from www.sypron.nl/mda

  16. Diagnosing bottlenecks Example: A session is performing continuous insert/delete cycles • The top wait events for this specific spid: WaitSecs NrWaits WaitEvent WaitEventID -------- ------- ----------------------------------- ----------- 8 140 waiting for disk write to complete 51 1 140 waiting for disk write to complete 55 0 140 waiting on run queue after yield 214 0 3 wait for buffer read to complete 29

  17. Diagnosing bottlenecks Example: A session is performing continuous insert/delete cycles • The top wait events for the entire ASE server: WaitSecs NrWaits WaitEvent -------- ------- --------------------------------------------- 79 6 hk: pause for some time 60 1 xact coord: pause during idle loop 53 1 checkpoint process idle loop 10 3 waiting while no network read or write is req 10 3 waiting for incoming network data 10 1 waiting for date or time in waitfor command 9 55 waiting for disk write to complete 1 44 waiting for disk write to complete 1 22 wait for buffer write to complete 0 187 waiting on run queue after sleep 0 62 waiting on run queue after yield 0 24 waiting for CTLIB event to complete

  18. Diagnosing bottlenecks Example: A session is performing continuous insert/delete cycles 9 55 waiting for disk write to complete 1 44 waiting for disk write to complete 1 22 wait for buffer write to complete Conclusion: • The bottleneck for this particular spid is disk writes • This is not a bottleneck for the server as a whole

  19. Diagnosing bottlenecks Example: A session is performing continuous select count(*) on a small table • The top wait events for this specific spid, and for the entire server: WaitSecs NrWaits WaitEvent -------- ------- ------------------------------------ 0 26 waiting for network send to complete WaitSecs NrWaits WaitEvent -------- ------- ------------------------------------------------- 314 18 waiting on run queue after yield 221 2519 waiting on run queue after sleep 132 1222 waiting while no network read or write is required 122 24 waiting for CTLIB event to complete 120 2 xact coord: pause during idle loop 79 6 hk: pause for some time 77 9 waiting for incoming network data

  20. Diagnosing bottlenecks Example: A session is performing continuous select count(*) on a small table Conclusion: • the bottleneck for this particular spid is sending the query results to the client • this is not a bottleneck for the server as a whole

  21. Diagnosing bottlenecks Example: No session is doing anything at all • The top wait events for an idle spid, and for the entire server are all waiting for incoming client queries WaitSecs NrWaits WaitEvent -------- ------- ------------------------------------ 10 0 waiting for incoming network data WaitSecs NrWaits WaitEvent -------- ------- -------------------------------------------------- 10 3 waiting while no network read or write is required 10 3 waiting for incoming network data 10 2 hk: pause for some time 10 1 waiting for date or time in waitfor command 0 39 waiting on run queue after sleep 0 24 waiting for CTLIB event to complete 0 8 waiting on run queue after yield

  22. Monitoring Index Utilization • Have you ever wanted to see • Which indexes are never used? • How frequently they are used? • How many inserts, deletes, updates, physical or logical I/O they incur? • monOpenObjectActivity table provides: • Table usage count • Index usage count • Last used dates • Physical, logical I/O • Row-level insert/delete/update counts • Lock wait counts for tables and indexes • NOTE: Statistics are reset when server is booted or object descriptor is reused in memory.

  23. Monitoring Index Utilization monOpenObjectActivity • Table and • Index Usage • Counts • Dates select "Database" = db_name(DBID), "Table" = object_name(ObjectID, DBID), IndID = IndexID, UsedCount, LastUsedDate, OptSelectCount, LastOptSelectDate from master..monOpenObjectActivity order by UsedCount

  24. Monitoring Table Usage monOpenObjectActivity • Per Table • Inserts • Deletes • Updates • Lock Waits select "Database" = db_name(DBID), "Table" = object_name(ObjectID, DBID), IndexID, RowsInserted, RowsDeleted, RowsUpdated, LockWaits from monOpenObjectActivity order by RowsInserted desc

  25. Identifying ‘hot’ tables • It’s interesting to know which tables and indexes are most frequently used select * into #t from master..monOpenObjectActivity go select TableName = object_name(ObjectID, DBID), IndexID, LogicalReads, PhysicalReads, Operations, LockWaits from #t order by 1, 2 go

  26. Identifying ‘hot’ tables TableName IndexID LogReads PhysReads Operations LockWaits ------------------------------ ------- -------- --------- ---------- --------- #t___________00000280002095330 0 11517 0 3460 0 #t2__________00000220014256057 0 5 0 5 0 cust_tab 0 12315 0 17 2 cust_tab 2 239 0 0 0 products_tb 0 282294 9043 609 97 products_tb 2 36450 0 0 0

  27. Understanding and Using Historical Tables

  28. Using Historical Tables • Which MDA tables are “historical” tables? • What are Historical Tables? • How do they work? • What is the correct size to configure them? • Archiving historical table data • Tips on using historical tables

  29. Which Tables are Historical Tables? • monSysSQLText • Records every SQL command executed on the server • monSysPlanText • Records the Query Plan for every SQL command executed on the server • monSysStatement • Reports the statistics for every statement within every query, batch, stored procedure, trigger, etc. executed on the server • monErrorLog • Records every row written to the server errorlog • monDeadLock • Records information on every deadlock that occurs on the server

  30. What are Historical Tables? • The historical MDA tables contain a record of “events” within the ASE • E.g., SQL submitted for a query, a statement executed within a batch, error message added to the errorlog • The data for these tables is stored in memory in fixed-sized arrays • Size is configurable using sp_configure • Data in Historical tables is transient • The arrays are managed as “ring buffers”: After the last entry in the array is written the first entry will be overwritten • Historical tables are “stateful.” • The ASE remembers which records a process has already seen • Subsequent queries on same table will return only new records • Why are they stateful? • This allows applications to accurately collect or “drain” the rows in these tables without finding duplicates.

  31. Row 1 Row 2 Row 3 Row 4 Row 5 Row 6 Row 7 Row 8 Queries on Historical Tables • The ASE maintains the connection’s currency in the MDA table • Currency is reset for each new connection “Select * from monSysSQLText” 8:22 AM: rows 1 – 4 Are inserted… 8:24 AM User 1: First query returns rows 1 - 4. 8:27 AM User 2: Never queried table before. Will see all rows. 8:30 AM User 1: Second query will return only rows added since last query (5 – 8). 8:26 AM: rows 5 - 8 Are inserted…

  32. Setting the Size of Historical Tables • These sp_configure parameters determine the number of rows in the historical tables – values are per-engine • errorlog pipe max messages • plan text pipe max messages • sql text pipe max messages • statement pipe max messages • deadlock pipe max messages • The value of the parameter is the number of rows per engine • Correct size depends on • Rate at which rows are written to table • Frequency with which queries will be run against the table • For example: • 2 engines • 5000 rows per minute per engine • Select * from monSysStatement every 5 minutes • Statement pipe max messages should be greater than or equal to 25000 • Result set size??? (50000 rows!) • Errorlog and deadlock pipes are usually much smaller than plan text, sql text and statement pipes Rate x Frequency = Size E.g.: 5000/min x 5 min = 25000 Reasonable size on busy system?? Could be >> 100000

  33. Memory Used by Historical Tables The following sizes are approximate: • monSysStatement • 90 bytes/row • monSysSQLText • 273 bytes/row • 255 bytes SQL Text per row • monErrorLog • 542 bytes/row • monDeadLock • 517 bytes/row • monSysPlanText • 194 bytes/row • Also note the max SQL text monitored configuration option • Allocates memory per process (the only MDA-related config option that’s static) • Determines maximum size of a SQL batch to capture • Does not effect size of SQL Text Pipe rows

  34. Tips on Using Historical Tables • Do not use in subqueries or joins • Save contents of tables to an archive table or database for analysis • When collecting long-term data, archive data on a regular basis and size tables to avoid data loss • How do you know whether the table for the buffer has wrapped? • If # of rows returned == size of buffer * # of engines • In other words, if you get the entire size of the buffer, some rows were probably lost • Currently, it is not possible to determine how many rows were lost

  35. Tips on Using Historical Tables • Quick way of removing all contents of a history table: exec(“select * into #t from master..monSysSQLText”) • Resets process’s currency in the historical table pipe • Handy when: • you’re not interested in the history • you want to do a quick test • you’ve configured “sql text pipe max messages” to 2000 • See how it works? • select…into #t saves you from waiting until 2000 lines have been flushed to your window • exec() drops #t automatically, so you don’t have to

  36. Archiving Historical Table Data

  37. Archiving Historical Table Data • Because data in historical tables is transient • Because repeated queries on historical tables will not return the same rows • Even in subqueries or joins! • Data from historical tables should be moved to permanent or temporary archive storage for analysis • Example: select * into #tempStatement from master..monSysStatement insert #tempStatement select * from master..monSysStatement

  38. Archiving Historical Table Data • For a ‘complete’ picture of what happened inside ASE: ‘regularly’ copy historical MDA tables to permanent tables • If copied too infrequently: data is pushed out of the pipe before it was retrieved • If copied too frequently (e.g. every second): cause additional workload on the ASE server

  39. Archiving Historical Table Data • A possible approach: a ‘collector’ stored proc which frequently extracts data from the MDA tables • ‘sp_mda_collect‘ • uses a separate database to collect the historical data in permanent tables • the permanent tables have the same layout as the historical MDA tables • added a composite unique index with ignore_dup_key on key columns (SPID, KPID, etc.) to filter out duplicates (in case the proc needs to be restarted…)

  40. Archiving Historical Table Data • sp_mda_collect • sp_mda_collect ‘start’ [, ‘hh:mm:ss’ ] -- runs in a loop (default interval = 30 sec.) • sp_mda_collect ‘stop’ -- run from a different session, stops the original procedure • sp_mda_collect ‘status’ -- displays #rows saved in archive tables • Procedure can be downloaded from www.sypron.nl/mda

  41. Enterprise Monitoring Repository and Center • To access MDA tables from a remote server • Create the MDA proxy tables on a central server • Map MDA proxy tables to each monitored server • Reduces load on monitored ASE servers • Provides central source of monitoring data for your enterprise • Allows easy archiving of enterprise data to permanent storage in database on repository server

  42. Creating an Enterprise Monitoring Center • Create monitoring database on central server • Copy and edit installmontables script • Two options: • Create separate monitoring database for each monitored server • Add server name to MDA table names to create unique table names for each server within a single database • Set the use database command to use the correct database • Change the “loopback” server name to the remote server name of the monitored server in your central server

  43. Modifying installmontables Script • Creating MDA proxy tables in a separate database for • each monitored server … … use monitor_svrtest1 go … … create existing table monProcedureCache ( Requests int, Loads int, Writes int, Stalls int, ) external procedure at “svrtest1...$monProcedureCache" go Use a separate database for each Monitored server Proxy table points to monitored server

  44. Modifying installmontables Script • Creating MDA proxy tables in a single database for • all monitored server … … use monitordb go … … create existing table monProcedureCache_svrtest1 ( Requests int, Loads int, Writes int, Stalls int, ) external procedure at “svrtest1...$monProcedureCache" go Database in which all proxy tables Will be created Unique table name constructed by a Appending server name Proxy table points to monitored server

  45. Enterprise Repository: Some Options • Use Rob’s sp_mda_collect stored procedure to collect data from all monitored servers into a central repository database • Create views in your proxy database that add server name or data-time stamp to monitoring data • Use this to store data from multiple server in a single permanent repository table • Create a union view to monitor errorlogs across enterprise create view enterprise_errorlog as select Server = ‘SVROPS', SPID, KPID, FamilyID, EngineNumber, ErrorNumber, Severity, State, Time, ErrorMessage from monitor_SVROPS1..monErrorLog UNION select Server = ‘SVRDEV1', SPID, KPID, FamilyID, EngineNumber, ErrorNumber, Severity, State, Time, ErrorMessage from monitor_SVRDEV1..monErrorLog

  46. Enterprise Errorlog Example 1> select * from enterprise_errorlog where Severity >= 16 2> go Server SPID KPID FamilyID EngineNumber ErrorNumber Severity State Time ErrorMessage ---------- --------- ---------------- ------------- -------- SVROPS1 768 1358430508 768 0 1608 18 4 Jul 28 2004 2:39PM A client process exited abnormally, or a network error was encountered. Unless other errors occurred, continue processing normally.

  47. Enterprise Monitoring Views: Considerations • Queries using UNION in view will fail if any member server is not available • Error 11216 may occur due to broken network connection between local and remote server • Consider creating a stored procedure to iterate over all remote servers • Store data in a temporary table • Catch query failures on unavailable servers and continue processing

  48. Performance Impact of MDA Tables

  49. Performance Impact of MDA Tables • Two questions • Impact of data collection? • Impact of querying MDA tables? • General performance impact: 5% or less • Depends on a number of factors • Configuration of server (e.g., number of engines, memory size, processor speed) • Load on server • Configuration of Monitoring parameters • Different monitoring configuration settings have different performance impacts • Fully enabling all options will have greatest impact

  50. Performance Impact: Configuration Settings • Lowest impact: • Enable monitoring with no other options • Tables enabled: monEngine, monDataCache, monProcedureCache, monOpenDatabases, monSysWorkerThread, monNetworkIO, monLocks, monCachePool, monIOQueue, monDeviceIO, monProcessWorkerThread, monProcessNetIO • Wait Event Timing • Plan Text, SQL Text, ErrorLog, DeadlLock • Greatest impact: • Per Object Statistics • monOpenObjectActivity, monProcessObject, monProcessActivity • Statement Historical table and Process Statements • monSysStatement, monProcessStatement • statement pipe active • statement statistics active

More Related