Monday, November 2, 2009

6.5 Oracle and CPU Resources



[ Team LiB ]






6.5 Oracle and CPU Resources



The
Oracle database shares the CPU(s) with all other software running on
the server. If there is a shortage of CPU power, reducing Oracle or
non-Oracle CPU consumption will improve the performance of all
processes running on the server.



If all the CPUs in a machine are busy, the processes line up and wait
for a turn to use the CPU. This is called a run queue because
processes are waiting to run on a CPU. The busier the CPUs get, the
longer processes can spend in this queue. A process in the queue
isn't doing any work, so as the run queue gets
longer, response times degrade.






You can use the standard
monitoring tools (and Enterprise Manager with Oracle Database 10g)
for your particular operating system to check the CPU utilization for
that machine.





Tuning CPU usage is
essentially an exercise in tuning individual tasks: it reduces the
number of commands required to accomplish the tasks and/or reduces
the overall number of tasks to be performed. You can do this tuning
through workload balancing, SQL tuning, or improved application
design. This type of tuning requires insight into what these tasks
are and how they're being executed.



As mentioned earlier, an in-depth discussion of all the various
tuning points for an Oracle database is beyond the scope of this
book. However, there is a set of common tasks that typically result
in excess CPU consumption. Some of the usual suspects to examine if
you encounter a CPU resource shortage on your database server include
the following:




Bad SQL



Poorly written SQL is the number one cause of performance problems.
An Oracle database attempts to optimally execute the SQL it receives
from clients. If the SQL contained in the client applications and
sent to the database is written so that the best optimization plan
Oracle can identify is still inefficient, Oracle will consume more
resources than necessary to execute the SQL. Tuning SQL can be a
complex and time-consuming process because it requires an in-depth
understanding of how Oracle works and what the application is trying
to do. Initial examinations can reveal flaws in the underlying
database design, leading to changes in table structures, additional
indexes, and so on. Changing the SQL requires retesting and a
subsequent redeployment of the application�until Oracle
Database 10g.



Oracle Database 10g comes with a SQL Tuning
Advisor, which can not only recognize poorly written SQL, but also
create an optimizer plan to circumvent the problem and replace the
standard optimization plan with the improved plan. With this
capability, you can improve the performance of poorly written SQL
without changing any code in the application.




Excessive parsing



As we discussed in Section 6.4.2.1, Oracle must parse every SQL statement
before it is processed. Parsing is very CPU-intensive, involving a
lot of data dictionary lookups to check that all the tables and
columns referenced are valid. Complex algorithms and calculations
estimate the costs of the various optimizer plans possible for the
statement to select the optimal plan. If your application
isn't using bind variables (discussed in Chapter 8),
the database will have to parse every statement it receives. This
excessive and unnecessary parsing is one of the leading causes of
performance degradation. Another common cause is a shared pool
that's too small, as discussed previously in Section 6.4.1.2. Keep in
mind that you can avoid the creation of execution plans by using
stored outlines, as described in Chapter 4. And, as of
Oracle9i, you also have the ability to edit the
hints that make up a stored outline.




Database workload



If your application is well designed and your database is operating
at optimal efficiency, you may experience a shortage of CPU resources
for the simple reason that your server doesn't have
enough CPU power to perform all the work it's being
asked to do. This shortage may be due to the workload for one
database (if the machine is a dedicated database server) or to the
combined workload of multiple databases running on the server.
Underestimating the amount of CPU resources required is a chronic
problem in capacity planning. Unfortunately, accurate estimates of
the CPU resources required for a certain level of activity demands
detailed insight into the amount of CPU power each transaction will
consume and how many transactions per minute or second the system
will process, both at peak and average workloads. Most organizations
don't have the time or resources for the system
analysis and prototyping required to answer these questions. This is
perhaps why CPU shortages are so common, and why the equally common
solution is to simply add more CPUs to the machine until the problem
goes away. Real Application Clusters and the grid (described mainly
in Chapter 14) are attempts to at least make adding
more CPU horsepower easier.




Non-database workload



Not all organizations have the
luxury of dedicating an entire machine to an Oracle database to
ensure that all CPU resources are available for that database. Use
operating system utilities to identify the top CPU consumers on the
machine. You may find that non-Oracle processes are consuming the
bulk of the CPU resources and adversely impacting database
performance.









    [ Team LiB ]



    No comments: