dbts2012 unconference wttrw_yazekatsu_publish

Post on 07-Jul-2015

1.112 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Welcome to the Real World ‘Real’means simply electrical signals on a computer

Oracle Corporation Japan

Yohei AZEKATSU

日本オラクル株式会社

畔勝洋平

blog:

http://d.hatena.ne.jp/yohei-a/

twitter: yoheia

検証環境

本日は、ちょっと変わった視点から

Oracle Database を見てみたいと思います

“We’re just ordinary people who apply the scientific

method to the things we can observe and measure”

出典:Oracle Core: Essential Internals for DBAs and Developers

Author: Jonathan Lewis

Technical reviewer: Tanel Poder

Oracle Database のアーキテクチャ

出典:Oracle Database Concepts 11g Release 2 (11.2) Part Number E25789-01

Oracle Database の世界へ

$ sqlplus neo/follow_the_white_rabbit

SQL*Plus: Release 11.2.0.2.0 Production on Tue Oct 16 09:56:00 2012

Copyright (c) 1982, 2010, Oracle. All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

SQL> create table agent(id number(10),name char(10));

Table created.

SQL> begin

for i in 1..10000000 loop

insert into agent(id, name) values(i, 'smith');

end loop;

end;

/ 2 3 4 5 6

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL>

SQL> set autotrace on

SQL> alter session set events '10046 trace name context forever, level 12';

Session altered.

SQL> select count(1) from agent;

COUNT(1)

----------

1000000

Execution Plan

----------------------------------------------------------

Plan hash value: 2571700340

--------------------------------------------------------------------

| Id | Operation | Name | Rows | Cost (%CPU)| Time |

--------------------------------------------------------------------

| 0 | SELECT STATEMENT | | 1 | 789 (1)| 00:00:10 |

| 1 | SORT AGGREGATE | | 1 | | |

| 2 | TABLE ACCESS FULL| AGENT | 873K| 789 (1)| 00:00:10 |

--------------------------------------------------------------------

$ tkprof orcl_ora_3331.trc orcl_ora_3331_tkprof.txt

$ less orcl_ora_3331_tkprof.txt

SQL ID: guxtdnm3w68gr Plan Hash: 2571700340

select count(1)

from

agent

Elapsed times include waiting on following events:

Event waited on Times Max. Wait Total Waited

---------------------------------------- Waited ---------- ------------

SQL*Net message to client 2 0.00 0.00

Disk file operations I/O 1 0.00 0.00

asynch descriptor resize 2 0.00 0.00

direct path read 97 0.00 0.03

SQL*Net message from client 2 0.00 0.00

待機イベントとは?

待機。待つ。

誰が何を待つのか?

サーバープロセスが

1. OSカーネル

2. Oracle Database の他のプロセス

を待つ

サーバープロセス

HDD

システムコール

割込みハンドラ

NIC

Oracle Database

OSカーネル

ハードウェア

OSカーネルに処理を依頼して終わるのを待つ

他のプロセスを待つ サーバープロセスバックグラウンドプロセス

暇なのでOSカーネルが起こしてくれるのを待つ

ネットワーク通信でデータが届いてOSカーネル

が起こしてくれるのを待つ

乱暴に言うと、”direct path read” はOSカーネルがディスクからデータの読み出しを待つこと

サーバープロセス

HDD

システムコール

割込みハンドラ

NIC

Oracle Database

OSカーネル

ハードウェア

direct path readdb file scattered readdb file sequential read

enqueuelatch, mutexlog file sync サーバープロセス

バックグラウンドプロセス

ITシステムの開発プロジェクトで、要件定義、設計、開発、テストなどの工程で工数を管理するのと同じように、 Oracle Database は何にどれだけ時間を使ったか記録している

「推測するな、計測せよ」by ロバート・C・パイク

出典:Cプログラミングに関する覚え書き(Notes on Programming in C)

「汝の時間を知れ」「成果をあげる者は仕事からスタートしない。時間からス

タートする」

by P.F.ドラッカー

出典:経営者の条件(The Effective Executive)

外の世界から見てみる

strace コマンドでサーバープロセスから発行されたシステムコールを調べる

$ strace -tt -o strace.log -p 3331

$ ls -l /proc/3331/fd

...

lrwx------ 1 oracle oracle ... 257 users01.dbf

lrwx------ 1 oracle oracle ... 258 temp01.dbf

$ grep 'direct path' orcl_ora_3331.trc|head -5

WAIT #5597196: nam='direct path read' ela= 233 ...tim=1350521557206427

WAIT #5597196: nam='direct path read' ela= 211 ...tim=1350521557206820

WAIT #5597196: nam='direct path read' ela= 632 ...tim=1350521557208596

WAIT #5597196: nam='direct path read' ela= 225 ...tim=1350521557210469

WAIT #5597196: nam='direct path read' ela= 203 ...tim=1350521557213599

$ grep 'pread64(257' strace.log|head -5

17:52:37.206294 pread64(257, ..., 40960, 26632192) = 40960

17:52:37.206677 pread64(257, ..., 65536, 26738688) = 65536

17:52:37.208032 pread64(257, ..., 122880, 26812416) = 122880

17:52:37.210311 pread64(257, ..., 122880, 182657024) = 122880

17:52:37.213464 pread64(257, ..., 122880, 182788096) = 122880

$ grep 'direct path read' orcl_ora_3331.trc|wc -l

97

$ grep 'pread64(257' strace.log|wc -l

97

サーバープロセス

HDD

システムコール

割込みハンドラ

NIC

Oracle Database

OSカーネル

ハードウェア

direct path readdb file scattered readdb file sequential read

enqueuelatch, mutexlog file sync サーバープロセス

バックグラウンドプロセス

pread64()

システムコールとは?

「システムコール」とは「カーネルに仕事を依頼する方法」を指す。

OSではプログラムを安全に実行するために、プロセッサの提供する機能を使用して「特権モードで動作するカーネル」と、「非特権モードで動作するそれ以外のプログラム」というように「カーネル」と「それ以外のプログラム」をそれぞれ実行する世界を分けている。

出典:http://www.atmarkit.co.jp/flinux/rensai/systemcall/01/02.html

カーネル空間

ユーザー空間

アプリケーション

メモリシステムコールを発行するとアプリケーションの実行状態等の情報がレジスタからメモリに退避され、カーネルのコードがロードされて(コンテキストスイッチ)実行される。

ハードウェア

システムコール

システムコールのおかげで、ディスクI/O、ネットワーク通信などハードウェアの制御が必要な処理を、ハードウェアを意識せずに安全に行うことができる

HDD NIC

カーネル空間

ユーザー空間

アプリケーション

メモリ

ハードウェア

HDD NIC

glibc

sys_pread64

VFS

ファイルシステム

汎用ブロック層

I/Oスケジューラ

デバイスドライバ

上から順番にCPUで命令が実行される

システムコールの先を捕まえる

# crash

crash> set scroll off

crash> repeat bt -l 3331

crash コマンドでカーネルのコールスタックを見る

#0 [e2694a6c] schedule at c061d348

/usr/src/debug/kernel-2.6.18/linux-2.6.18.i686/kernel/sched.c: 2056

#1 [e2694ae4] io_schedule at c061d9f9

/usr/src/debug/kernel-2.6.18/linux-2.6.18.i686/kernel/sched.c: 4879

#2 [e2694af0] sync_buffer at c04788c6

/usr/src/debug/kernel-2.6.18/linux-2.6.18.i686/fs/buffer.c: 67

#3 [e2694af4] __wait_on_bit at c061dbd2

/usr/src/debug/kernel-2.6.18/linux-2.6.18.i686/kernel/wait.c: 169

#4 [e2694b0c] out_of_line_wait_on_bit at c061dc57

/usr/src/debug/kernel-2.6.18/linux-2.6.18.i686/kernel/wait.c: 182

#5 [e2694b44] __wait_on_buffer at c0478843

include/linux/wait.h: 434

#6 [e2694b50] __bread at c04799d6

include/linux/buffer_head.h: 318

#7 [e2694b58] ext3_get_branch at f8882927

#8 [e2694b78] ext3_get_blocks_handle at f8882ba4

#9 [e2694c34] ext3_get_block at f888369b

#10 [e2694c6c] do_mpage_readpage at c0495a48

...

#20 [e2694f8c] vfs_read at c0476536

/usr/src/debug/kernel-2.6.18/linux-2.6.18.i686/fs/read_write.c: 264

#21 [e2694fa4] sys_pread64 at c0476a4f

/usr/src/debug/kernel-2.6.18/linux-2.6.18.i686/fs/read_write.c: 393

#22 [e2694fb8] system_call at c0404f10

VFS

ファイルシステム

sys_pread64

pread64

全てはCPU命令

crash> set 3331

PID: 3511 TASK: f58c3550 CPU: 0 COMMAND: "oracle"

#0 [e70b4e90] schedule at c061d348

#1 [e70b4f08] pipe_wait at c0481408

#2 [e70b4f28] pipe_readv at c0481b16

#3 [e70b4f74] pipe_read at c0481ba2

#4 [e70b4f84] vfs_read at c0476536

#5 [e70b4f9c] sys_read at c0476981

#6 [e70b4fb8] system_call at c0404f10

EAX: ffffffda EBX: 00000009 ECX: 117efa5e EDX: 00002010

DS: 007b ESI: 117e6c28 ES: 007b EDI: bf923454

SS: 007b ESP: bf923414 EBP: bf923434

CS: 0073 EIP: 00c05402 ERR: 00000003 EFLAGS: 00000246

crash> dis e70b4fb8 10

dis: WARNING: e70b4fb8: no associated kernel symbol found

0xe70b4fb8: pop %ss

0xe70b4fb9: dec %edi

0xe70b4fba: inc %eax

0xe70b4fbb: rorb $0x0,(%ecx)

0xe70b4fbe: add %al,(%eax)

0xe70b4fc0: pop %esi

0xe70b4fc1: cli

0xe70b4fc2: jle 0xe70b4fd5

0xe70b4fc4: adc %ah,(%eax)

0xe70b4fc6: add %al,(%eax)

ニーモニック、アセンブラコード

コンピュータが実行可能な機械語(マシン語)のプログラムを、人間が理解・記述しやすいように簡略化した英単語や記号の組み合わせに置き換えたもの

Free your mind

ご清聴ありがとうございました

最新書籍情報

Amazonベストセラー商品ランキング

コンピューターサイエンス部門

第1位(10/16 17:30頃)

あの「絵で見てわかる」シリーズの

小田圭二監修

日本オラクルのコンサルタント陣が執筆

(私も書かせていただきました)

絵で見てわかるITインフラの仕組み翔泳社

価格:¥ 2,499

ITインフラにおける、普遍的な概念や仕組みを絵を使って説明しています。インフラエンジニア向けの本ですが、アプリケーションを設計・開発しているエンジニアやプログラマの方にも役に立つ本ではないかと思います。

好評につき増刷決定!

カバーを裏返すとシステムの全貌がわかる解剖図

top related