dbts2012 unconference wttrw_yazekatsu_publish

41
Welcome to the Real World ‘Real’means simply electrical signals on a computer Oracle Corporation Japan Yohei AZEKATSU

Upload: yohei-azekatsu

Post on 07-Jul-2015

1.112 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dbts2012 unconference wttrw_yazekatsu_publish

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

Oracle Corporation Japan

Yohei AZEKATSU

Page 2: Dbts2012 unconference wttrw_yazekatsu_publish

日本オラクル株式会社

畔勝洋平

blog:

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

twitter: yoheia

Page 3: Dbts2012 unconference wttrw_yazekatsu_publish

検証環境

Page 4: Dbts2012 unconference wttrw_yazekatsu_publish

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

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

Page 5: Dbts2012 unconference wttrw_yazekatsu_publish

“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

Page 6: Dbts2012 unconference wttrw_yazekatsu_publish

Oracle Database のアーキテクチャ

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

Page 7: Dbts2012 unconference wttrw_yazekatsu_publish

Oracle Database の世界へ

Page 8: Dbts2012 unconference wttrw_yazekatsu_publish

$ 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>

Page 9: Dbts2012 unconference wttrw_yazekatsu_publish

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>

Page 10: Dbts2012 unconference wttrw_yazekatsu_publish

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 |

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

Page 11: Dbts2012 unconference wttrw_yazekatsu_publish

$ 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

Page 12: Dbts2012 unconference wttrw_yazekatsu_publish

待機イベントとは?

Page 13: Dbts2012 unconference wttrw_yazekatsu_publish

待機。待つ。

誰が何を待つのか?

Page 14: Dbts2012 unconference wttrw_yazekatsu_publish

サーバープロセスが

1. OSカーネル

2. Oracle Database の他のプロセス

を待つ

Page 15: Dbts2012 unconference wttrw_yazekatsu_publish

サーバープロセス

HDD

システムコール

割込みハンドラ

NIC

Oracle Database

OSカーネル

ハードウェア

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

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

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

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

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

Page 16: Dbts2012 unconference wttrw_yazekatsu_publish

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

Page 17: Dbts2012 unconference wttrw_yazekatsu_publish

サーバープロセス

HDD

システムコール

割込みハンドラ

NIC

Oracle Database

OSカーネル

ハードウェア

direct path readdb file scattered readdb file sequential read

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

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

Page 18: Dbts2012 unconference wttrw_yazekatsu_publish

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

Page 19: Dbts2012 unconference wttrw_yazekatsu_publish

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

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

Page 20: Dbts2012 unconference wttrw_yazekatsu_publish

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

タートする」

by P.F.ドラッカー

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

Page 21: Dbts2012 unconference wttrw_yazekatsu_publish

外の世界から見てみる

Page 22: Dbts2012 unconference wttrw_yazekatsu_publish

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

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

Page 23: Dbts2012 unconference wttrw_yazekatsu_publish

$ 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

Page 24: Dbts2012 unconference wttrw_yazekatsu_publish

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

97

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

97

Page 25: Dbts2012 unconference wttrw_yazekatsu_publish

サーバープロセス

HDD

システムコール

割込みハンドラ

NIC

Oracle Database

OSカーネル

ハードウェア

direct path readdb file scattered readdb file sequential read

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

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

pread64()

Page 26: Dbts2012 unconference wttrw_yazekatsu_publish

システムコールとは?

Page 27: Dbts2012 unconference wttrw_yazekatsu_publish

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

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

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

Page 28: Dbts2012 unconference wttrw_yazekatsu_publish

カーネル空間

ユーザー空間

アプリケーション

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

ハードウェア

システムコール

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

HDD NIC

Page 29: Dbts2012 unconference wttrw_yazekatsu_publish

カーネル空間

ユーザー空間

アプリケーション

メモリ

ハードウェア

HDD NIC

glibc

sys_pread64

VFS

ファイルシステム

汎用ブロック層

I/Oスケジューラ

デバイスドライバ

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

Page 30: Dbts2012 unconference wttrw_yazekatsu_publish

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

Page 31: Dbts2012 unconference wttrw_yazekatsu_publish

# crash

crash> set scroll off

crash> repeat bt -l 3331

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

Page 32: Dbts2012 unconference wttrw_yazekatsu_publish

#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

Page 33: Dbts2012 unconference wttrw_yazekatsu_publish

全てはCPU命令

Page 34: Dbts2012 unconference wttrw_yazekatsu_publish

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)

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

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

Page 35: Dbts2012 unconference wttrw_yazekatsu_publish

Free your mind

Page 36: Dbts2012 unconference wttrw_yazekatsu_publish

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

Page 37: Dbts2012 unconference wttrw_yazekatsu_publish

最新書籍情報

Page 38: Dbts2012 unconference wttrw_yazekatsu_publish

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

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

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

Page 39: Dbts2012 unconference wttrw_yazekatsu_publish

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

小田圭二監修

Page 40: Dbts2012 unconference wttrw_yazekatsu_publish

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

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

Page 41: Dbts2012 unconference wttrw_yazekatsu_publish

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

価格:¥ 2,499

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

好評につき増刷決定!

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