Professional Documents
Culture Documents
Practice 27
Practice Target
In this practice, you will perform the following:
• Diagnose CPU-bound issue from external sources
In this section of the practice, you will simulate a CPU stress from external process and use AWR
reports to troubleshoot it.
1. In the hosting PC, open a command prompt window and start Swingbench.
D:
cd D:\swingbench\winbin
set PATH=D:\oracle\product\12.1.0\client_1\jdk\jre\bin;%PATH%
swingbench.bat
2. In Swingbench, open the oltp.xml configuration file then Start Benchmark button.
3. Start Putty and connect to srv1 as oracle, invoke SQL*Plus and login to ORADB as sysdba. In the
rest of this practice, this session will be referred to as admin window.
sqlplus / as sysdba
set sqlprompt "ADMIN> "
4. Open another Putty session. Connect to srv1 as root, then run the following command to
simulate a load on the CPU from external process for 5 minutes. This Putty window will be
referred to as the testing window in the remaining part of the practice.
The command applies a CPU stress on the machine for 5 minutes.
stress --cpu 20 --timeout 300s
5. In the admin window, run the following script to create two AWR snapshots in 5 minutes.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
JOB_NAME => 'CREATE_2_AWR_SNAPSHOTS',
JOB_TYPE => 'PLSQL_BLOCK',
JOB_ACTION => 'BEGIN DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT(); END;',
START_DATE => SYSDATE,
REPEAT_INTERVAL => 'FREQ=MINUTELY;INTERVAL=5', /* every 5 minutes */
END_DATE => SYSDATE + (1/24/60*6),
AUTO_DROP => TRUE,
ENABLED => TRUE,
COMMENTS => 'create an AWR snapshots: now and after 5 minutes');
END;
/
7. In the admin window, retrieve list of the most recent AWR snapshots and make sure two
snapshots have been created in the last 5 minutes.
@ $SD/awr_today_snapshots.sql
8. Produce an AWR report for the snapshots that you manually created earlier. Give the produced
report the name awr_ext_cpu.html
@ ?/rdbms/admin/awrrpt.sql
10. In the hosting PC, open the produced report with your favorite browser. Observe the following in
the listed sections in the report:
• Report header:
- maximum CPU time for the report period is 2 (# of CPU) x 5 minutes = 600 seconds
• Host CPU:
- Load average is greater than two times the number of CPUs. This is an indication that the
CPU could be a bottleneck.
- Total consumption from the CPU power = %User+%System+%WIO
- They represent high percentage of the 100%
- As the DB CPU was a low percentage, this means that the most CPU consumption was from
external process. But there is a slight possibility that the difference in CPU consumption was
taken from background process (although this is very rare). To confirm, we go to the Time
Model section.
Note: The '% Total CPU' is the 'total CPU time' (in Time Model section)/Maximum CPU time
Note: In Time Model section, do not be confused by the column '% of Total CPU Time'. That is
not the percentage of the DB CPU from the maximum CPU time. It is the percentage of the DB
CPU from the total database CP consumption. It is calculated by the following formula:
Note: Although we could detect CPU-bound issue caused by external source from AWR reports,
usually they are detected by monitoring the CPU consumption from OS level. We will cover monitoring
CPU form OS level later in the course.
Scenario 2
In this section of the practice, you will simulate a CPU-bound situation from the database and use
AWR reports to troubleshoot it.
11. In the testing Putty window, change the current user to oracle, then run the following script to
kick off 4 SQL*Plus sessions that apply load on the CPU for 4 minutes. Do not wait for the script
to finish. Go to the next step.
su - oracle
$SD/apply_soe_cpu.sh 4 240
12. In the admin window, run the following code to create two AWR snapshots in 5 minutes.
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
JOB_NAME => 'CREATE_2_AWR_SNAPSHOTS',
JOB_TYPE => 'PLSQL_BLOCK',
JOB_ACTION => 'BEGIN DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT(); END;',
START_DATE => SYSDATE,
REPEAT_INTERVAL => 'FREQ=MINUTELY;INTERVAL=5', /* every 5 minutes */
END_DATE => SYSDATE + (1/24/60*6),
AUTO_DROP => TRUE,
ENABLED => TRUE,
COMMENTS => 'create an AWR snapshots: now and after 5 minutes');
END;
/
15. Produce an AWR report for the create snapshots. Give the produced report the name
awr_db_cpu.html
@ ?/rdbms/admin/awrrpt.sql
17. In the hosting PC, open the produced report with your favorite browser.
18. In the hosting PC, open the produced report with your favorite browser. Observe the following in
the listed sections in the report:
• Report header:
- maximum CPU time for the report period is 2 (# of CPU) x 5 minutes = 600 seconds
• ADDM Findings:
- 'CPU Usage' is one of the ADDM findings.
• Host CPU:
- Total consumption from the CPU power = %User+%System+%WIO
- They represent high percentage which means the CPU has heavily consumed
• Instance CPU:
- %Busy CPU is very high. This means that the most CPU consumption was from the
database side.
Note: “%Busy CPU” = Total Database CPU time / CPU Busy Time
Cleanup
19. (optional) Close the browser window and delete the files:
host rm /media/sf_extdisk/awr_ext_cpu.html
host rm /media/sf_extdisk/awr_db_cpu.html
Summary
• AWR reports can be used to detect CPU-bound issues from external sources and from within the
database.
• If a CPU issue is caused by external sources, AWR cannot help on detecting the process which
was responsible for hammering the CPU.