• Aucun résultat trouvé

6-5. Identifying CPU and Memory Bottlenecks (ps)

Dans le document Oracle Database 11g (Page 196-200)

Problem

You want to quickly isolate which processes on the server are consuming the most CPU and memory resources.

Solution

The ps (process status) command is handy for quickly identifying top resource-consuming processes.

For example, this command displays the top ten CPU-consuming resources on the box:

$ ps -e -o pcpu,pid,user,tty,args | sort -n -k 1 -r | head Here is a partial listing of the output:

97.8 26902 oracle ? oracleO11R2 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) 0.5 27166 oracle ? ora_diag_O11R2

0.0 9 root ? [ksoftirqd/2]

In the prior output, the process named oracleO11R2 is consuming an inordinate amount of CPU resources on the server. The process name identifies this as an Oracle process associated with the O11R2 database.

Similarly, you can also display the top memory-consuming processes:

$ ps -e -o pmem,pid,user,tty,args | sort -n -k 1 -r | head

How It Works

The Linux/Unix ps command displays information about currently active processes on the server. The pcpu switch instructs the process status to report the CPU usage of each process. Similarly the pmem switch instructs ps to report on process memory usage. This gives you a quick and easy way to determine which processes are consuming the most resources.

When using multiple commands on one line (such as ps, sort, and head), it’s often desirable to associate the combination of commands with a shortcut (alias). Here’s an example of creating aliases:

$ alias topc='ps -e -o pcpu,pid,user,tty,args | sort -n -k 1 -r | head'

$ alias topm='ps -e -o pmem,pid,user,tty,args | sort -n -k 1 -r | head'

Now instead of typing in the long line of commands, you can use the alias—for example:

$ topc

Also consider establishing the aliases in a startup file (like .bashrc or .profile) so that the commands are automatically defined when you log on to the database server.

6-6. Identifying I/O Bottlenecks

Problem

You are experiencing performance problems and want to determine if the issues are related to slow disk I/O.

Solution

Use the iostat command with the -x (extended) option combined with the -d (device) option to generate I/O statistics. This next example displays extended device statistics every ten seconds:

$ iostat –xd 10

You need a fairly wide screen to view this output; here’s a partial listing:

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util

sda 0.01 3.31 0.11 0.31 5.32 28.97 2.66 14.49 83.13 0.06 138.44 1.89 0.08

This periodic extended output allows you to view in real time which devices are experiencing spikes in read and write activity. To exit from the previous iostat command, press Ctrl+C. The options and output may vary depending on your operating system. For example, on some Linux/Unix distributions, the iostat output may report the disk utilization as %b (percent busy).

When trying to determine whether device I/O is the bottleneck, here are some general guidelines when examining the iostat output:

• Look for devices with abnormally high blocks read or written per second.

• If any device is near 100% utilization, that’s a strong indicator I/O is a bottleneck.

How It Works

The iostat command can help you determine whether disk I/O is potentially a source of performance problems. Table 6-5 describes the columns displayed in the iostat output.

CHAPTER 6 ■ ANALYZING OPERATING SYSTEM PERFORMANCE

Table 6-5. Column Descriptions of iostat Disk I/O Output Column Description

Device Device or partition name

tps I/O transfers per second to the device Blk_read/s Blocks per second read from the device Blk_wrtn/s Blocks written per second to the device Blk_read Number of blocks read

Blk_wrtn Number of blocks written

rrqm/s Number of read requests merged per second that were queued to device wrqm/s Number of write requests merged per second that were queued to device r/s Read requests per second

w/s Write requests per second rsec/s Sectors read per second wsec/s Sectors written per second rkB/s Kilobytes read per second wkB/s Kilobytes written per second avgrq-sz Average size of requests in sectors avgqu-sz Average queue length of requests

await Average time in milliseconds for I/O requests sent to the device to be served svctm Average service time in milliseconds

%util Percentage of CPU time during which I/O requests were issued to the device. Near 100%

indicates device saturation

You can also instruct iostat to display reports at a specified interval. The first report displayed will report averages since the last server reboot; each subsequent report shows statistics since the previously generated snapshot. The following example displays a device statistic report every three seconds:

$ iostat -d 3

You can also specify a finite number of reports that you want generated. This is useful for gathering metrics to be analyzed over a period of time. This example instructs iostat to report every 2 seconds for a total of 15 reports:

$ iostat 2 15

When working with locally attached disks, the output of the iostat command will clearly show where the I/O is occurring. However, it is not that clear-cut in environments that use external arrays for storage. What you are presented with at the file system layer is some sort of a virtual disk that might also have been configured by a volume manager. In virtualized storage environments, you’ll have to work with your system administrator or storage administrator to determine exactly which disks are experiencing high I/O activity.

Once you have determined that you have a disk I/O contention issue, then you can use utilities such as AWR (if licensed), Statspack (no license required), or the V$ views to determine if your database is I/O stressed. For example, the AWR report contains an I/O statistics section with the following subsections:

• IOStat by Function summary

• IOStat by Filetype summary

• IOStat by Function/Filetype summary

• Tablespace IO Stats

• File IO Stats

You can also directly query data dictionary views such as V$SQL to determine which SQL statements are using excessive I/O—for example:

SELECT * FROM (SELECT

parsing_schema_name ,direct_writes

,SUBSTR(sql_text,1,75) ,disk_reads

FROM v$sql

ORDER BY disk_reads DESC) WHERE rownum < 20;

To determine which sessions are currently waiting for I/O resources, query V$SESSION:

SELECT username ,program ,machine ,sql_id FROM v$session

WHERE event LIKE 'db file%read';

CHAPTER 6 ■ ANALYZING OPERATING SYSTEM PERFORMANCE

To view objects that are waiting for I/O resources, run a query such as this:

SELECT object_name ,object_type ,owner

FROM v$session a ,dba_objects b

WHERE a.event LIKE 'db file%read'

AND b.data_object_id = a.row_wait_obj#;

Once you have identified queries (using the prior queries in this section), then consider the following factors, which can cause a SQL statement to consume inordinate amounts of I/O:

• Poorly written SQL

• Improper indexing

• Improper use of parallelism (which can cause excessive full table scans)

You’ll have to examine each query and try to determine if one of the prior items is the cause of poor performance as it relates to I/O.

6-7. Identifying Network-Intensive Processes

Problem

You’re investigating performance issues on a database server. As part of your investigation, you want to determine if there are network bottlenecks on the system.

Solution

Use the netstat (network statistics) command to display network traffic. Perhaps the most useful way to view netstat output is with the -ptc options. These options display the process ID and TCP connections, and they continuously update the output:

$ netstat -ptc

Press Ctrl+C to exit the previous command. Here’s a partial listing of the output:

(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 rmug.com:62386 rmug.com:1521 ESTABLISHED 22864/ora_pmon_RMDB tcp 0 0 rmug.com:53930 rmug.com:1521 ESTABLISHED 6091/sqlplus tcp 0 0 rmug.com:1521 rmug.com:53930 ESTABLISHED 6093/oracleRMDB1 tcp 0 0 rmug.com:1521 rmug.com:62386 ESTABLISHED 10718/tnslsnr

Dans le document Oracle Database 11g (Page 196-200)