{"id":1432,"date":"2008-09-01T12:00:00","date_gmt":"2008-09-01T12:00:00","guid":{"rendered":"http:\/\/orcldoug.com\/blog\/?p=1432"},"modified":"2008-09-01T12:00:00","modified_gmt":"2008-09-01T12:00:00","slug":"time-matters-db-cpu","status":"publish","type":"post","link":"http:\/\/orcldoug.com\/blog\/2008\/09\/01\/time-matters-db-cpu\/","title":{"rendered":"Time Matters &#8211; DB CPU"},"content":{"rendered":"<p>In <a href=\"http:\/\/18.133.199.212\/?p=1429#c6611\">his comment<\/a> on the last post, John Beresniewicz mentioned the following property of DB CPU :-<\/p>\n<p>&#8220;<em>&#8230; &#8216;DB time&#8217;<br \/>\nfully contains &#8216;DB CPU&#8217; and both are measured values (which means<br \/>\nin particular that &#8216;DB CPU&#8217; is not inflated by runq time)<\/em>&#8220;<\/p>\n<p>I&#8217;d like to talk about the end of that sentence in particular. About a year and a half ago, I wrote <a href=\"\/px_profiles.pdf\">a paper<\/a> (that&#8217;s a PDF link) about building response time profiles for sessions that use Parallel Execution. One of the problems I highlighted in that paper was that PX jobs are prone to overload the available CPU resources simply because of the number of PX slave processes that are running concurrently. It&#8217;s mentioned first in the section on &#8220;<em>More Lost Time<\/em>&#8221; on page 4 but most of the rest of the paper goes on to discuss this particular problem. I wasn&#8217;t very successful coming up with any solutions beyond my usual approach of combining Oracle and O\/S tools.<\/p>\n<p>Essentially, as the queue of runnable processes that are waiting to execute on a CPU grows (I&#8217;ll just refer to it as the run queue from now on), the Oracle server connection processes appear to lose time because they&#8217;re unable to get on to a CPU in order to record the end time of an event. In the Response Time profilers I&#8217;ve seen, this time is recorded as unaccounted-for and it&#8217;s what JB&#8217;s referring to when he talks about runq time. Actually, time spent in the run queue is not the only cause of unaccounted-for time but it&#8217;s the one I&#8217;ll focus on here. (Here&#8217;s another plug for <a href=\"http:\/\/oreilly.com\/catalog\/9780596005276\/\">Cary and Jeff&#8217;s book<\/a> &#8211; other reasons are discussed in chapter 7 on Oracle Kernel Timings.)<\/p>\n<p>As JB stated, DB CPU does <em>not<\/em> include this time spent waiting in the run queue but the <a href=\"http:\/\/www.oracle.com\/technology\/products\/manageability\/database\/pdf\/twp03\/PPT_active_session_history.pdf\">ASH<\/a> samples for the session are aware that the server connection process is on the CPU <em>or<\/em> in the run queue. As a consequence, you can see apparently contradictory graphs in the various OEM (DB Control or Grid Control) Performance pages. Although I&#8217;ve tried this with the PX tests and confirmed the same behaviour, I&#8217;m going to use <a href=\"http:\/\/www.dominicgiles.com\/swingbench.html\">Swingbench<\/a> for the examples here to continue the approach so far and so that you can try them out yourself if you want. (I might post PX examples later.)<\/p>\n<p>Swingbench is supplied with several example applications, one of which is the Sales History (SH) application which uses the SH example schema supplied with recent versions of Oracle. The key attribute of this test for my purpose is that it&#8217;s read only and CPU intensive, so that the limited I\/O bandwidth on a home PC isn&#8217;t the bottleneck.<\/p>\n<p>I ran 8 concurrent sessions of the SH application for a total duration of 5 minutes with no delay between transactions, which was pretty unrealistic but I was only interested in over-loading the single dual-core CPU in the PC. Soon after the test started, this was how the database instance&#8217;s home page looked.<\/p>\n<p><!-- s9ymdb:173 --><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"180\" src=\"\/serendipity\/uploads\/DBCPU1.png.pagespeed.ce.tBWmVDNyke.png\" style=\"border: 0px none ; padding-left: 5px; padding-right: 5px\" width=\"660\"\/><\/p>\n<p>CPU is at 100% and there are about 7 sessions active in the database on average, just under 2 of which are running on the CPU, while the rest are waiting. That looks about right. Now, if we look at the performance page at the end of the test, the results are quite different.<\/p>\n<p><!-- s9ymdb:175 --><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"180\" src=\"https:\/\/i0.wp.com\/18.133.199.212\/wp-content\/uploads\/recovered\/DBCPU3.png?resize=660%2C180\" style=\"border: 0px none ; padding-left: 5px; padding-right: 5px\" width=\"660\" data-recalc-dims=\"1\" \/><\/p>\n<p>It looks like there were only ever about 2 sessions active on average! However, there are a couple of hints as to what&#8217;s going on. If we look at the graph above as well as the Average Active Sessions graph, we can see that the Host&#8217;s run queue is far in excess of the two available CPU cores.<\/p>\n<p><!-- s9ymdb:176 --><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"340\" src=\"https:\/\/i0.wp.com\/18.133.199.212\/wp-content\/uploads\/recovered\/DBCPU4.png?resize=660%2C340\" style=\"border: 0px none ; padding-left: 5px; padding-right: 5px\" width=\"660\" data-recalc-dims=\"1\" \/><\/p>\n<p>Things become even more interesting if we look at the Top Activity screen for the same period.<\/p>\n<p><!-- s9ymdb:174 --><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"260\" src=\"https:\/\/i0.wp.com\/18.133.199.212\/wp-content\/uploads\/recovered\/DBCPU2.png?resize=660%2C260\" style=\"border: 0px none ; padding-left: 5px; padding-right: 5px\" width=\"660\" data-recalc-dims=\"1\" \/><\/p>\n<p>In that view, the sessions waiting in the run queue <span style=\"font-style: italic\">are<\/span> shown, so there&#8217;s an average of about 7 active sessions during the test. Take a good look at the difference in the key text for the two graphs as well. The Average Active Sessions graph on the Performance Home page shows &#8216;CPU Used&#8217;, whereas the Top Activity page shows &#8216;CPU&#8217;. It&#8217;s a small but significant and appropriate difference. The first graph shows you the average number of sessions that are actually using CPU and is related to DB CPU in the Time Model Stats, but the Top Activity screen is really showing &#8216;CPU + Wait for CPU&#8217;, which is the event you&#8217;ll see throughout an ASH report covering the same period. e.g.<\/p>\n<blockquote><p>Top Sessions<\/p>\n<ul>\n<li class=\"awr\">&#8216;# Samples Active&#8217; shows the number of ASH samples in which the session<br \/>\n      was found waiting for that particular event. The percentage shown<br \/>\n      in this column is calculated with respect to wall clock time<br \/>\n      and not total database activity.\n<\/li>\n<li class=\"awr\">&#8216;XIDs&#8217; shows the number of distinct transaction IDs sampled in ASH<br \/>\n      when the session was waiting for that particular event\n<\/li>\n<li class=\"awr\">For sessions running Parallel Queries, this section will NOT aggregate<br \/>\n      the PQ slave activity into the session issuing the PQ. Refer to<br \/>\n      the &#8216;Top Sessions running PQs&#8217; section for such statistics.\n<\/li>\n<\/ul>\n<\/blockquote>\n<blockquote>\n<table border=\"1\">\n<tbody>\n<tr>\n<th class=\"awrbg\">Sid, Serial#<\/th>\n<th class=\"awrbg\">% Activity<\/th>\n<th class=\"awrbg\">Event<\/th>\n<th class=\"awrbg\">% Event<\/th>\n<th class=\"awrbg\">User<\/th>\n<th class=\"awrbg\">Program<\/th>\n<th class=\"awrbg\"># Samples Active<\/th>\n<th class=\"awrbg\">XIDs<\/th>\n<\/tr>\n<tr>\n<td align=\"right\" class=\"awrc\">136, 2716<\/td>\n<td align=\"right\" class=\"awrc\">12.75<\/td>\n<td class=\"awrc\">CPU + Wait for CPU<\/td>\n<td align=\"right\" class=\"awrc\">12.16<\/td>\n<td class=\"awrc\">SH<\/td>\n<td class=\"awrc\">java.exe<\/td>\n<td align=\"right\" class=\"awrc\">227\/300 [ 76%]<\/td>\n<td align=\"right\" class=\"awrc\">0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" class=\"awrnc\">137,  120<\/td>\n<td align=\"right\" class=\"awrnc\">12.64<\/td>\n<td class=\"awrnc\">CPU + Wait for CPU<\/td>\n<td align=\"right\" class=\"awrnc\">12.32<\/td>\n<td class=\"awrnc\">SH<\/td>\n<td class=\"awrnc\">java.exe<\/td>\n<td align=\"right\" class=\"awrnc\">230\/300 [ 77%]<\/td>\n<td align=\"right\" class=\"awrnc\">0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" class=\"awrc\">140,  164<\/td>\n<td align=\"right\" class=\"awrc\">12.59<\/td>\n<td class=\"awrc\">CPU + Wait for CPU<\/td>\n<td align=\"right\" class=\"awrc\">12.00<\/td>\n<td class=\"awrc\">SH<\/td>\n<td class=\"awrc\">java.exe<\/td>\n<td align=\"right\" class=\"awrc\">224\/300 [ 75%]<\/td>\n<td align=\"right\" class=\"awrc\">0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" class=\"awrnc\">144,  240<\/td>\n<td align=\"right\" class=\"awrnc\">12.53<\/td>\n<td class=\"awrnc\">CPU + Wait for CPU<\/td>\n<td align=\"right\" class=\"awrnc\">11.94<\/td>\n<td class=\"awrnc\">SH<\/td>\n<td class=\"awrnc\">java.exe<\/td>\n<td align=\"right\" class=\"awrnc\">223\/300 [ 74%]<\/td>\n<td align=\"right\" class=\"awrnc\">0<\/td>\n<\/tr>\n<tr>\n<td align=\"right\" class=\"awrc\">133,   29<\/td>\n<td align=\"right\" class=\"awrc\">12.37<\/td>\n<td class=\"awrc\">CPU + Wait for CPU<\/td>\n<td align=\"right\" class=\"awrc\">11.62<\/td>\n<td class=\"awrc\">SH<\/td>\n<td class=\"awrc\">java.exe<\/td>\n<td align=\"right\" class=\"awrc\">217\/300 [ 72%]<\/td>\n<td align=\"right\" class=\"awrc\">0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/blockquote>\n<p>The more I think about this, the more I think that there&#8217;s probably a Rule Of Thumb here (I&#8217;m joking, really, but maybe it&#8217;s something I&#8217;ll look for during further tests). Maybe when DB Time is much bigger than the sum of the wait times on various timed events plus CPU time, it&#8217;s indicative of CPU overload? Then again, maybe it&#8217;s just easier to check the process states and run queue? &#128521;<\/p>\n<p>Finally, I couldn&#8217;t resist checking what ADDM makes of all this, specially for <a href=\"http:\/\/www.cidrdb.org\/cidr2005\/papers\/P07.pdf\">Graham Wood<\/a> (that&#8217;s another PDF link). Well, in this case, ADDM is smart enough to work out what&#8217;s going on.<\/p>\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DETAILED ADDM REPORT FOR TASK 'TASK_46' WITH ID 46\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 --------------------------------------------------\n \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Analysis Period: 28-AUG-2008 from 23:22:54 to 23:27:56\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Database ID\/Instance: 1533705496\/1\n\u00a0\u00a0\u00a0\u00a0\u00a0 Database\/Instance Names: TEST1020\/TEST1020\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Host Name: DESKTOP\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Database Version: 10.2.0.4.0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Snapshot Range: from 26 to 27\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Database Time: 2006 seconds\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Average Database Load: 6.6 active sessions\n \n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n \n \nFINDING 1: 100% impact (2006 seconds)\n-------------------------------------\nHost CPU was a bottleneck and the instance was consuming 98% of the host CPU. \nAll wait times will be inflated by wait for CPU.\n \n\u00a0\u00a0 RECOMMENDATION 1: Host Configuration, 100% benefit (2006 seconds)\n\u00a0\u00a0\u00a0\u00a0\u00a0 ACTION: Consider adding more CPUs to the host or adding instances \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 serving the database on other hosts.\n\u00a0\u00a0\u00a0\u00a0\u00a0 ACTION: Also consider using Oracle Database Resource Manager to \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prioritize the workload from various consumer groups.\n \n\u00a0\u00a0 ADDITIONAL INFORMATION:\n\u00a0\u00a0\u00a0\u00a0\u00a0 Host CPU consumption was 99%.\u00a0 CPU runqueue statistics are not available \n\u00a0\u00a0\u00a0\u00a0\u00a0 from the host's OS. This disables ADDM's ability to estimate the impact \n\u00a0\u00a0\u00a0\u00a0\u00a0 of this finding.\u00a0 The instance spent significant time on CPU. However, \n\u00a0\u00a0\u00a0\u00a0\u00a0 there were no predominant SQL statements responsible for the CPU load.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In his comment on the last post, John Beresniewicz mentioned the following property of DB CPU :- &#8220;&#8230; &#8216;DB time&#8217; fully contains &#8216;DB CPU&#8217; and both are measured values (which means in particular that &#8216;DB CPU&#8217; is not inflated by runq time)&#8220; I&#8217;d like to talk about the end of that sentence in particular. About&hellip; <a class=\"more-link\" href=\"http:\/\/orcldoug.com\/blog\/2008\/09\/01\/time-matters-db-cpu\/\">Continue reading <span class=\"screen-reader-text\">Time Matters &#8211; DB CPU<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1432","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":1429,"url":"http:\/\/orcldoug.com\/blog\/2008\/08\/20\/time-matters-db-time\/","url_meta":{"origin":1432,"position":0},"title":"Time Matters &#8211; DB Time","date":"August 20, 2008","format":false,"excerpt":"[In retrospect, the title of that first blog post might have suited the subject, but doesn't translate too well for subsequent related blog posts. That was a lack of planning or foresight on my part. These blog posts are tumbling out of my head in a fairly incoherent way. Maybe\u2026","rel":"","context":"With 13 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":835,"url":"http:\/\/orcldoug.com\/blog\/2006\/03\/14\/px-and-the-magic-of-2\/","url_meta":{"origin":1432,"position":1},"title":"PX and &#8220;the Magic of 2&#8221;","date":"March 14, 2006","format":false,"excerpt":"Now that I've had time to sit back and relax and absorb things a little, I thought I should fix a couple of outright bugs in the recent PX paper (Later update - link to the paper) and revisit the conclusions before moving on to testing different aspects. First, the\u2026","rel":"","context":"With 2 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1428,"url":"http:\/\/orcldoug.com\/blog\/2008\/08\/14\/time-matters-an-infinite-capacity-for-waiting\/","url_meta":{"origin":1432,"position":2},"title":"Time Matters &#8211; An Infinite Capacity for Waiting*","date":"August 14, 2008","format":false,"excerpt":"When I was teaching the 10g Performance class at my last customer site, I remarked that the total number of seconds you see in the \"Top 5 Timed Events\" section of a Statspack or AWR report will often be greater than the total number of seconds between the snapshot intervals.\u2026","rel":"","context":"With 6 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1156,"url":"http:\/\/orcldoug.com\/blog\/2006\/12\/07\/a-more-complex-statspack-example-part-2\/","url_meta":{"origin":1432,"position":3},"title":"A More Complex Statspack Example &#8211; Part 2","date":"December 7, 2006","format":false,"excerpt":"So far we're barely into the comparison of the Statspack reports from the two different test environments and they look quite different already.Next up, the Instance Efficiency Percentages. I have to confess that I rarely find these very useful because the numbers are always near 100% on most databases I\u2026","rel":"","context":"With 13 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":854,"url":"http:\/\/orcldoug.com\/blog\/2006\/02\/27\/something-for-v2\/","url_meta":{"origin":1432,"position":4},"title":"Something for V2","date":"February 27, 2006","format":false,"excerpt":"This is mainly for anyone who has read the early versions of the Hotsos 'How Many Slaves' paper. It won't make as much sense if you haven't.I was doing some more work on multi-user tests at the weekend. I reduced the size of the tables to eliminate disk i\/o (as\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1321,"url":"http:\/\/orcldoug.com\/blog\/2007\/09\/24\/11g-and-direct-path-reads\/","url_meta":{"origin":1432,"position":5},"title":"11g and direct path reads","date":"September 24, 2007","format":false,"excerpt":"Curioser and curioser ....I've been thinking about this on and off today and I really can't understand the behaviour I'm seeing. In fact, it's a good job it was a busy day or it might have sent me round the twist \ud83d\ude09 I've been playing around a little tonight, trying\u2026","rel":"","context":"With 27 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/posts\/1432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/comments?post=1432"}],"version-history":[{"count":0,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/posts\/1432\/revisions"}],"wp:attachment":[{"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/media?parent=1432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/categories?post=1432"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/orcldoug.com\/blog\/wp-json\/wp\/v2\/tags?post=1432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}