5. DTCC2011
The fastest way to do something is
don„t do it
Anonymous
Two ways to improve performance, do
it less or do it faster
Anonymous
Performance is all about code path
From Cary Millsap
http://carymillsap.blogspot.com/2010/09/my-otn-interview-at-
oow2010-which-hasnt.html
8. DTCC2011
Response Time = Service Time + Queue Time
经典的响应时间曲线.到达率为1.55trx/s,响应时间为
3ms/Trx,服务时间为2ms/Trx,排队时间为1ms/trx
图片引用自:《Forecasting Oracle Performance》, Chapter 2 P44,figure 2-1
14. DTCC2011
L1 cache reference 0.5 ns(1GHz CPU)
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns (7200rpm SATA)
Read 1 MB sequentially from disk 20,000,000 ns
Send packet CA->Netherlands->CA 150,000,000 ns
引用自: Peter Norvig: http://norvig.com/21-days.html,Jeff Dean: dean-keynote-ladis2009.pdf
15. DTCC2011
7200 RPM SATA 15000 rpm SAS
基本处理延时 基本处理延时
Seek Time = 9.5ms (1) Seek Time = 4ms (1)
Rotation Time = 4.2ms Rotation Time = 2ms
一次IO随机读取8KB数据的延时 一次IO随机读取8KB数据的延时
Transfer Time = 8KB / ( 3Gb/s) = 21 μs Transfer Time = 8KB / ( 3Gb/s) = 21 μs
Total Time = ST + RT + ETT + ITT = 13.72ms Total Time = ST + RT + TT = 6.021ms
一次IO随机读取1MB数据的延时 一次IO随机读取1MB数据的延时
Transfer Time = 1MB / ( 3Gb/s) = 2.69ms Transfer Time = 1MB / ( 3Gb/s) = 2.688ms
Total Time = ST + RT + TT = 16.41 ms Total Time = ST + RT + TT = 8.709 ms
一次IO顺序读取1MB数据的延时 一次IO顺序读取1MB数据的延时
Transfer Time = 1MB / ( 3Gb/s) = 2.69ms Transfer Time = 1MB / ( 3Gb/s) = 2.688ms
Total Time = RT + TT = 6.91 ms Total Time = RT + TT = 4.709 ms
256
128
64 SATA 7200RPM(8K)(随机)
32 SATA 7200RPM(1M)(随机)
16 SATA 7200RPM(1M)(顺序)
8 SAS 15000RPM(8K)(随机)
4 SAS 15000RPM(1M)(随机)
2 SAS 15000RPM(1M)(顺序)
1
0.5 延时(ms) IOPS(次 吞吐量(MB)
数)
1.来自Seagate介绍
16. DTCC2011
索引键的选择性(唯一性)
索引键的顺序
索引对应基础数据的更新
频度
等值检索 Vs 范围检索
导致索引失效的场景
Index Access Vs Index
Filter Vs Table Filter
Richard Foote的Blog http://richardfoote.wordpress.com/ 不
Tapio Lahdenmaki 的书《Relational Database Index Design and the Optimizers》
17. DTCC2011
模拟场景
表中有5个字段(id, status, type, gmt_create, content)
主要基于三个字段的组合进行查询
字段status, type总共有30个组合(status 5个值,type 6个值)
每天有10000条记录,时间随机分布(共60天的数据)
执行的查询,分页取第一个20条记录
select id,status,type,gmt_create,content from ( select
id,status,type,gmt_create,content,rownum rn
from ( select id,status,type,gmt_create,content from james_t
where status = '00' and type = '05' and gmt_create >= trunc(sysdate) and
gmt_create < trunc(sysdate+1)
order by gmt_create desc ) where rownum <= 20 ) where rn >= 0;
分别创建三种丌同的索引进行测试
create index james_t_idx on james_t(status, type, gmt_create);
create index james_t_idx on james_t (status, gmt_create);
create index james_t_idx on james_t (gmt_create, status, type);
18. DTCC2011
index columns description Logical Reads
status, type, gmt_create index access 24
gmt_create, status, type index access + index filter 27
status, gmt_create index access + table filter 130
no index full table scan 53470
Logical Reads Logical Reads
full table scan 53470
index access + table filter 130
index access + index filter 27
index access 24
1 5 25 125 625 3125 15625 78125
28. DTCC2011
Optimizing Oracle Performance
By Cary Millsap, Jeff Holt
Forecasting Oracle Performance
By Craig Shallahamer
Guerrilla Capacity Planning
By Neil J. Gunther
Relational Database Index Design and the Optimizers
By Tapio Lahdenmaki
Think Clearly About Performance
By Cary Millsap
http://www.method-r.com/downloads/doc_details/44-thinking-clearly-
about-performance
TroubleShooting Oracle Performance
By Christian Antognini
性能诊断艺术
Translated By 冯大辉/胡怡文/童家旺