{"id":1988,"date":"2018-06-03T17:29:32","date_gmt":"2018-06-03T17:29:32","guid":{"rendered":"http:\/\/nenadnoveljic.com\/blog\/?p=1988"},"modified":"2018-06-03T17:29:32","modified_gmt":"2018-06-03T17:29:32","slug":"negative-unaccounted-for-pitfalls","status":"publish","type":"post","link":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/","title":{"rendered":"Negative Unaccounted-for (2) &#8211; Pitfalls"},"content":{"rendered":"<p>In my <a href=\"http:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for\/\">previous blog post<\/a> I described boundary conditions that cause negative unaccounted-for time. The main point is &#8211; the CPU time consumed by the code instrumented with a wait event is double counted. To begin with, it&#8217;s contained in the CPU time of its parent database call. And then, it&#8217;s entailed in the wait event duration. The negative duration of this CPU time is unaccounted-for.<\/p>\n<p>Although I&#8217;ve been was focusing only on SQL extended trace so far, there are more performance diagnostic features where you shouldn&#8217;t take the reported elapsed and CPU times at face value. In fact, I&#8217;d like to make you aware of a few pitfalls related to the negative unaccounted-for in SQL Monitor and ASH.<\/p>\n<p>In doing so, I&#8217;m using synchronous IO on ZFS for demonstration purposes. On top of that, I&#8217;ve now configured the file system cache, that is ZFS ARC, to make pread completely CPU-bound. The database release is 12.2.0.1.180116 on Solaris 11.3. <\/p>\n<h1>tkprof<\/h1>\n<p>As you can see in the tkprof output below, the sum of the CPU time (19.34s) and wait events duration (13.26s) exceeds the elapsed time (19.34s).<\/p>\n<pre><code>\r\ncall     count       cpu    elapsed       disk      query    current        rows\r\n------- ------  -------- ---------- ---------- ---------- ----------  ----------\r\nParse        1      0.02       0.02          0         63          0           0\r\nExecute      1      0.00       0.00          0          0          0           0\r\nFetch        1     19.34      19.34    3408598    3408626          0           1\r\n------- ------  -------- ---------- ---------- ---------- ----------  ----------\r\ntotal        3     <span style=\"color: #ff0000;\">19.36      19.36<\/span>    3408598    3408689          0           1\r\n\r\n...\r\n\r\nElapsed times include waiting on following events:\r\n  Event waited on                             Times   Max. Wait  Total Waited\r\n  ----------------------------------------   Waited  ----------  ------------\r\n  SQL*Net message to client                       2        0.00          0.00\r\n  SQL*Net message from client                     1        0.00          0.00\r\n  PGA memory operation                            2        0.00          0.00\r\n  direct path read                            26669        0.00         <span style=\"color: #ff0000;\">13.26<\/span>\r\n********************************************************************************<\/code><\/pre>\n<p>unaccounted-for can be calculated as follows:<\/p>\n<p>unaccounted-for = elapsed &#8211; cpu &#8211; total_waited = 19.36s &#8211; 19.36s &#8211; 13.26s = -13.26s<\/p>\n<p>In other words, the whole execution (19.34s) was on the CPU. Besides that, it took 13.26 s (entirely on the CPU) to execute the code instrumented by the wait event &#8220;direct path read&#8221;, which was double counted. <\/p>\n<p><b>In conclusion, in the case of a non-zero unaccounted-for, it&#8217;s wrong to think of elapsed time as the sum of the CPU time and wait event durations.<\/b><\/p>\n<p>By the way, sophisticated profilers, such as <a href=\"https:\/\/method-r.com\/software\/\">Method-R Profiler<\/a>, report the unaccounted-for.<\/p>\n<h1>SQL Monitor<\/h1>\n<p>Below is the excerpt from the corresponding SQL Monitor report:<\/p>\n<pre><code>...\r\nGlobal Information\r\n------------------------------\r\n...\r\nDuration            :  <span style=\"color: #ff0000;\">20s<\/span>\r\n...\r\nGlobal Stats\r\n=================================================================\r\n| Elapsed |   Cpu   |    IO    | Fetch | Buffer | Read  | Read  |\r\n| Time(s) | Time(s) | Waits(s) | Calls |  Gets  | Reqs  | Bytes |\r\n=================================================================\r\n|      <span style=\"color: #ff0000;\">33<\/span> |      19 |       13 |     1 |     3M | 26669 |  26GB |\r\n=================================================================\r\n...<\/code><\/pre>\n<p><b>Obviously, &#8220;Elapsed Time(s)&#8221; in the &#8220;Global Stats&#8221; section is calculated as the sum of &#8220;CPU Time(s)&#8221; and &#8220;IO Wait(s)&#8221; and therefore misleading. Use &#8220;Duration&#8221; in the &#8220;Global Information&#8221; instead.<\/b><\/p>\n<h1>ASH<\/h1>\n<p>With the following query we&#8217;ll verify how the samples are categorized in v$active_session_history:<\/p>\n<pre><code>column event format a18                                                                                                               \r\nselect session_state,event, count(*) \r\n  from v$active_session_history \r\n  where sql_id = '4hqv20rbt8dck' and\r\n    sql_exec_id = ( \r\n     select max(sql_exec_id) from v$active_session_history \r\n       where sql_id = '4hqv20rbt8dck'\r\n   )\r\n  group by event,session_state ;                                                                                                       \r\n\r\nSESSION EVENT                COUNT(*)\r\n------- ------------------ ----------\r\n<span style=\"color: #ff0000;\">WAITING direct path read           14<\/span>\r\nON CPU                              5<\/code><\/pre>\n<p>Expectedly, there isn&#8217;t double counting, as there&#8217;s just one sample per second whose session state can be either WAITING or ON CPU. It&#8217;s worth noting that the samples taken during the execution of the code instrumented by a wait event were categorized as WAITING, whether the process was on the CPU or not.<br \/>\n<b>Consequently, the CPU time based on v$active_session_history can&#8217;t be calculated correctly in the case of a negative unaccounted-for.<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Find out which information in SQL Monitor report and ASH becomes unreliable in the case of a negative unaccounted-for. <a href=\"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1988","post","type-post","status-publish","format-standard","hentry","category-oracle"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Negative Unaccounted-for (2) - Pitfalls - All-round Database Topics<\/title>\n<meta name=\"description\" content=\"Find out which information in SQL Monitor report and ASH becomes unreliable in the case of a negative unaccounted-for.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Negative Unaccounted-for (2) - Pitfalls - All-round Database Topics\" \/>\n<meta property=\"og:description\" content=\"Find out which information in SQL Monitor report and ASH becomes unreliable in the case of a negative unaccounted-for.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/\" \/>\n<meta property=\"og:site_name\" content=\"All-round Database Topics\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-03T17:29:32+00:00\" \/>\n<meta name=\"author\" content=\"Nenad Noveljic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@NenadNoveljic\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nenad Noveljic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/negative-unaccounted-for-pitfalls\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/negative-unaccounted-for-pitfalls\\\/\"},\"author\":{\"name\":\"Nenad Noveljic\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"headline\":\"Negative Unaccounted-for (2) &#8211; Pitfalls\",\"datePublished\":\"2018-06-03T17:29:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/negative-unaccounted-for-pitfalls\\\/\"},\"wordCount\":431,\"commentCount\":1,\"articleSection\":[\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/negative-unaccounted-for-pitfalls\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/negative-unaccounted-for-pitfalls\\\/\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/negative-unaccounted-for-pitfalls\\\/\",\"name\":\"Negative Unaccounted-for (2) - Pitfalls - All-round Database Topics\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\"},\"datePublished\":\"2018-06-03T17:29:32+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"description\":\"Find out which information in SQL Monitor report and ASH becomes unreliable in the case of a negative unaccounted-for.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/negative-unaccounted-for-pitfalls\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/negative-unaccounted-for-pitfalls\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/negative-unaccounted-for-pitfalls\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Negative Unaccounted-for (2) &#8211; Pitfalls\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\",\"name\":\"All-round Database Topics\",\"description\":\"Nenad Noveljic\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\",\"name\":\"Nenad Noveljic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"caption\":\"Nenad Noveljic\"},\"sameAs\":[\"nenad-noveljic-9b746a6\",\"https:\\\/\\\/x.com\\\/NenadNoveljic\"],\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/author\\\/nenad\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Negative Unaccounted-for (2) - Pitfalls - All-round Database Topics","description":"Find out which information in SQL Monitor report and ASH becomes unreliable in the case of a negative unaccounted-for.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/","og_locale":"en_US","og_type":"article","og_title":"Negative Unaccounted-for (2) - Pitfalls - All-round Database Topics","og_description":"Find out which information in SQL Monitor report and ASH becomes unreliable in the case of a negative unaccounted-for.","og_url":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/","og_site_name":"All-round Database Topics","article_published_time":"2018-06-03T17:29:32+00:00","author":"Nenad Noveljic","twitter_card":"summary_large_image","twitter_creator":"@NenadNoveljic","twitter_misc":{"Written by":"Nenad Noveljic","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/#article","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/"},"author":{"name":"Nenad Noveljic","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"headline":"Negative Unaccounted-for (2) &#8211; Pitfalls","datePublished":"2018-06-03T17:29:32+00:00","mainEntityOfPage":{"@id":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/"},"wordCount":431,"commentCount":1,"articleSection":["Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/","url":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/","name":"Negative Unaccounted-for (2) - Pitfalls - All-round Database Topics","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#website"},"datePublished":"2018-06-03T17:29:32+00:00","author":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"description":"Find out which information in SQL Monitor report and ASH becomes unreliable in the case of a negative unaccounted-for.","breadcrumb":{"@id":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nenadnoveljic.com\/blog\/negative-unaccounted-for-pitfalls\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nenadnoveljic.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Negative Unaccounted-for (2) &#8211; Pitfalls"}]},{"@type":"WebSite","@id":"https:\/\/nenadnoveljic.com\/blog\/#website","url":"https:\/\/nenadnoveljic.com\/blog\/","name":"All-round Database Topics","description":"Nenad Noveljic","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nenadnoveljic.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa","name":"Nenad Noveljic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","caption":"Nenad Noveljic"},"sameAs":["nenad-noveljic-9b746a6","https:\/\/x.com\/NenadNoveljic"],"url":"https:\/\/nenadnoveljic.com\/blog\/author\/nenad\/"}]}},"_links":{"self":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/1988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/comments?post=1988"}],"version-history":[{"count":1,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/1988\/revisions"}],"predecessor-version":[{"id":2007,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/1988\/revisions\/2007"}],"wp:attachment":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/media?parent=1988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/categories?post=1988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/tags?post=1988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}