SlideShare a Scribd company logo
1 of 28
Jametong@童家旺
work@alipay (2010.8-)
work@alibaba(2005.5-2010.8)
work@浙江移动台州公司 (2003.12-2005.5)
Blog @ http://www.dbthink.com/
mail@ jametong@gmail.com
Weibo @ Jametong
什么是优化?
响应时间 Vs 吞吐量
性能与可伸缩性(Performance Vs Scalability)
Instrument & metrics
需要了解的一点硬件知识
常见案例分析
引用资料
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
不访问不必要的数据
 使用B*Tree/hash等方法定位必要的数据
 使用column Store或分表的方式将数据分开存储

合理的利用硬件来提升访问效率
 使用缓存消除对数据的重复访问
 使用批量处理来减少交互次数(磁盘、网络)
 使用新硬件来降低后端的延时,提高效率

提高系统的吞吐量
 对工作单元进行细化,减少串行操作
 优化硬件配置,提高整体的TCO与硬件利用率
 合理的拆分(水平、垂直拆分)以提高系统的整体吞吐能力
性能
衡量完成特定仸务的速度或效率


响应时间
衡量系统与用户交互式多久能够收到响应


吞吐量
衡量系统在单位时间里可以完成的任务量
Response Time = Service Time + Queue Time




     经典的响应时间曲线.到达率为1.55trx/s,响应时间为
     3ms/Trx,服务时间为2ms/Trx,排队时间为1ms/trx
450

400

350

300
                                                             线性扩展
250                                                          Amdahl扩展(f=0.3)
                                                             Amdahl扩展(f=0.2)
200
                                                             Amdahl扩展(f=0.1)
150                                                          USL扩展(0.1,0.1)
                                                             USL扩展(0.1,0.2)
100

 50

  0
      0   2   4   6   8   10   12   14   16   18   20   22
Amdahl's law
 使用多处理器进行 并行处理能够提升的性能的
 比例受限于程序中需要串行处理的比例
USL Scalability
 使用多处理器进行 并行处理能够提升的性能的
 比例不仅受限于程序中需要串行处理的比
 例, 还受限于进程之间的并发系数.
What gets measured gets
managed.
 Peter Drucker (彼得. 德鲁克 )



Don't guess, get the data
 Anonymous
从杭州北京(花费了6个半小时)
从杭州北京(花费了6个半小时)
 13:00 – 13:15 从公司下楼到淘宝(15分钟)

 13:30 – 13:50 从淘宝出发到上出租车(20分钟)

 14:00 - 15:00 在出租车上,从淘宝<->机场(60分钟)

 15:10 - 15:20 拿机票(10分钟)

 15:25 - 15:50 安检(25分钟)

 16:00 – 17:00 在机场候机(60分钟)

 17:00 - 18:20 飞机上,杭州北京(80分钟)

 18:20 - 18:40 到出租车上车点(20分钟)

 18:40 - 18:55 等待出租车(15分钟)

 18:55 - 19:50 机场到酒店(55分钟)
Metrics
  v$sys_time_model & v$sess_time_model
  v$sysstat & v$sesstat
  v$system_event & v$session_event
  v$session_wait & v$event_histogram


Instrument
  Extended 10046 trace
vmstat & iostat & netstat & tcprstat &
sar
strace & oprofile & systemtap
aspersa & latencytop & top
[oracle@mytest ~]$ ps -ef | grep dbw
oracle 8323         1 0 2010 ?          00:42:29 ora_dbw0_mytest
[oracle@mytest ~]$ strace -c -p 8323
Process 8323 attached - interrupt to quit
Process 8323 detached
% time      seconds usecs/call        calls errors syscall
------ ----------- ----------- --------- --------- -------------
 98.39 0.007194              37      195           pwrite
  1.61 0.000118              0      644          times
  0.00 0.000000              0        1         read
  0.00 0.000000              0        1         open
  0.00 0.000000              0        1         close
  0.00 0.000000              0       10          getrusage
  0.00 0.000000              0       11       11 semtimedop
------ ----------- ----------- --------- --------- -------------
100.00 0.007312                      863       11 total
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
传统磁盘的IO特性
Nand Flash本身的IO特性
  Read 25μs
  Write(program) 250 μs
  Erase 2000 μs
Intel 320 SSD
  Read 75 μs
  Write 90 μs
Fusion-IO
  Read : 68μs
  Write: 15μs
Storage通道的处理延时
  10GbE的Latency : 10-50 μs
  Fabric Channel 的latency:20-50 μs
  InfiniBand 的Latency :1-3 μs
优化传统B*Tree 优化数据访问
 如何更好的设计索引
使用Write Optimized B-Tree优化数据访问
 Stratified B-trees (Acunu)
 LSM tree(BigTable,Cassandra,LevelDB)
 Fractal Tree Indexes(TokuDB)
使用基于Hash的算法访问数据
 Oracle Hash Cluster,BDB,Bitcask
模拟场景
 表中有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);
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
场景介绍
 表VeryBigTable含有30个列
 表的记录数为50,000,000条
 平均每个用户为300条左右
 其中有2个列属于详细描述字段,平均长度为2k
 其它的列的总长度平均为250个字节
 此表上的查询有两种模式
     列出表中的主要信息(每次20条,不包含详细信息,90%的查询)
     查看记录的详细信息(10%的查询)
 保存在Oracle数据库中,默认block size(8k)
要求
 对此业务进行优化
 分析数据,说服开发部门实施此优化
性能分析
每块记录数
 8192 * 0.80(1) / 250 = 25.5 (主表)
 8192 * 0.80 / 2000 = 3.27(详情表)
 8192 * 0.80 / ( 2000 + 250 ) = 2.91
访问的逻辑IO(内存块访问)
 List的查询代价
 改进后=( 300/25.5 ) * y + 4 + x = 4 + x + 11.8y = 42 + 73 + 11.8 * 1.54 = 28.7
 改进前=( 300/2.91 ) * y + 4 + x = 4 + x + 103.y = 4 + 7 + 103 * 1.5 = 165.5
访问涉及到的物理读(磁盘块访问)
 List的查询代价(逻辑IO * ( 1 – 命中率 ))
 改进后=28.7 * ( 1 – 0.855) = 4.305
 改进前=165.5 * ( 1 – 0.85 ) = 24.825
访问时间(ms)
 改进后=逻辑IO时间+物理IO时间= 28.7 * 0.016 + 4.305 * 77 = 30.422ms
 改进前=逻辑IO时间+物理IO时间= 165.5 * 0.01 + 24.825 * 7 = 175.43ms
使用场景
 缓存的一致性维护问题
 数据的具体读写比
 变更频率
 业务对一致性的要求
 使用何种缓存方式.
注意事项
 考虑缓存的刷新策略
 考虑缓存的数据延迟对业务的影响
 考虑缓存失效时,系统的支撑能力
 参考缓存工具: MemCached, Tair, Redis
elapsed time    elapsed time
16
14
12
10
 8
 6
 4
 2
 0




         Logical Reads     Logical Reads
120000
100000
 80000
 60000
 40000
 20000
     0
在有批量需求的情况下,尽可能提供批量处理
接口,如memcached的multiget,或者
cassandra的getslice,针对RDBMS,可以使
用批量接口(如Oracle的Array Interface).
不要设置过大的批次大小
 这需要与对应的程序heap 空间
 设置过大可能会导致程序出现OOM错误
 网络send/receive_buffer大小
 (/proc/sys/net/core/wmem|rmem_max|def
 ault)
Five minute rule?
 Price / Performance Break Point?
一台机器配置的代价
 机架成本
 电力成本(机器电力?Cooling?)
 CPU license成本(Oracle?Veritas ?)
 机器成本?
 使用PCI-E SSD?
 使用HBA?InfiniBand?交换机?
 多使用内存?多使用磁盘?
 单机故障对业务的影响代价?
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 冯大辉/胡怡文/童家旺
Q&A

More Related Content

What's hot

基于Innodb开发的最佳实践
基于Innodb开发的最佳实践基于Innodb开发的最佳实践
基于Innodb开发的最佳实践wubx
 
技术交流 支付二代信息安全及其代收付实现
技术交流 支付二代信息安全及其代收付实现技术交流 支付二代信息安全及其代收付实现
技术交流 支付二代信息安全及其代收付实现Banned Li
 
淘宝前台系统优化实践“吞吐量优化”-Qcon2011
淘宝前台系统优化实践“吞吐量优化”-Qcon2011淘宝前台系统优化实践“吞吐量优化”-Qcon2011
淘宝前台系统优化实践“吞吐量优化”-Qcon2011Yiwei Ma
 
卷積神經網路(Python+TensorFlow+Keras)
卷積神經網路(Python+TensorFlow+Keras)卷積神經網路(Python+TensorFlow+Keras)
卷積神經網路(Python+TensorFlow+Keras)Fuzhou University
 
人工智慧09_神經網路(TensorFlow+Keras)
人工智慧09_神經網路(TensorFlow+Keras)人工智慧09_神經網路(TensorFlow+Keras)
人工智慧09_神經網路(TensorFlow+Keras)Fuzhou University
 
Mongo db技术分享
Mongo db技术分享Mongo db技术分享
Mongo db技术分享晓锋 陈
 
Mysql 高级优化之 逻辑处理
Mysql 高级优化之 逻辑处理Mysql 高级优化之 逻辑处理
Mysql 高级优化之 逻辑处理nigel889
 

What's hot (8)

基于Innodb开发的最佳实践
基于Innodb开发的最佳实践基于Innodb开发的最佳实践
基于Innodb开发的最佳实践
 
技术交流 支付二代信息安全及其代收付实现
技术交流 支付二代信息安全及其代收付实现技术交流 支付二代信息安全及其代收付实现
技术交流 支付二代信息安全及其代收付实现
 
淘宝前台系统优化实践“吞吐量优化”-Qcon2011
淘宝前台系统优化实践“吞吐量优化”-Qcon2011淘宝前台系统优化实践“吞吐量优化”-Qcon2011
淘宝前台系统优化实践“吞吐量优化”-Qcon2011
 
Glider
GliderGlider
Glider
 
卷積神經網路(Python+TensorFlow+Keras)
卷積神經網路(Python+TensorFlow+Keras)卷積神經網路(Python+TensorFlow+Keras)
卷積神經網路(Python+TensorFlow+Keras)
 
人工智慧09_神經網路(TensorFlow+Keras)
人工智慧09_神經網路(TensorFlow+Keras)人工智慧09_神經網路(TensorFlow+Keras)
人工智慧09_神經網路(TensorFlow+Keras)
 
Mongo db技术分享
Mongo db技术分享Mongo db技术分享
Mongo db技术分享
 
Mysql 高级优化之 逻辑处理
Mysql 高级优化之 逻辑处理Mysql 高级优化之 逻辑处理
Mysql 高级优化之 逻辑处理
 

Viewers also liked

Evaluating ha alternatives my sql tutorial2
Evaluating ha alternatives my sql tutorial2Evaluating ha alternatives my sql tutorial2
Evaluating ha alternatives my sql tutorial2james tong
 
Migrating from MySQL to PostgreSQL
Migrating from MySQL to PostgreSQLMigrating from MySQL to PostgreSQL
Migrating from MySQL to PostgreSQLjames tong
 
Understanding performance through_measurement
Understanding performance through_measurementUnderstanding performance through_measurement
Understanding performance through_measurementjames tong
 
The right read optimization is actually write optimization
The right read optimization is actually write optimizationThe right read optimization is actually write optimization
The right read optimization is actually write optimizationjames tong
 
My sql ssd-mysqluc-2012
My sql ssd-mysqluc-2012My sql ssd-mysqluc-2012
My sql ssd-mysqluc-2012james tong
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVMVaclav Pech
 
挖财的互联网金融技术实践与探索@upyun opentalk
挖财的互联网金融技术实践与探索@upyun opentalk挖财的互联网金融技术实践与探索@upyun opentalk
挖财的互联网金融技术实践与探索@upyun opentalkFuqiang Wang
 
Understanding the Disruptor
Understanding the DisruptorUnderstanding the Disruptor
Understanding the DisruptorTrisha Gee
 
米聊服务器技术选型与架构
米聊服务器技术选型与架构米聊服务器技术选型与架构
米聊服务器技术选型与架构Jinping Qu
 
Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Fuqiang Wang
 
Scala funbyexample
Scala funbyexampleScala funbyexample
Scala funbyexampleFuqiang Wang
 
More Than Java Concurrency
More Than Java ConcurrencyMore Than Java Concurrency
More Than Java ConcurrencyFuqiang Wang
 
Architecture patterns and practices
Architecture patterns and practicesArchitecture patterns and practices
Architecture patterns and practicesFuqiang Wang
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-partsFuqiang Wang
 
HBase@taobao for 技术沙龙
HBase@taobao for 技术沙龙HBase@taobao for 技术沙龙
HBase@taobao for 技术沙龙bluedavy lin
 
了解集群
了解集群了解集群
了解集群Feng Yu
 

Viewers also liked (20)

Evaluating ha alternatives my sql tutorial2
Evaluating ha alternatives my sql tutorial2Evaluating ha alternatives my sql tutorial2
Evaluating ha alternatives my sql tutorial2
 
Migrating from MySQL to PostgreSQL
Migrating from MySQL to PostgreSQLMigrating from MySQL to PostgreSQL
Migrating from MySQL to PostgreSQL
 
Understanding performance through_measurement
Understanding performance through_measurementUnderstanding performance through_measurement
Understanding performance through_measurement
 
The right read optimization is actually write optimization
The right read optimization is actually write optimizationThe right read optimization is actually write optimization
The right read optimization is actually write optimization
 
My sql ssd-mysqluc-2012
My sql ssd-mysqluc-2012My sql ssd-mysqluc-2012
My sql ssd-mysqluc-2012
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Martial arts
Martial artsMartial arts
Martial arts
 
挖财的互联网金融技术实践与探索@upyun opentalk
挖财的互联网金融技术实践与探索@upyun opentalk挖财的互联网金融技术实践与探索@upyun opentalk
挖财的互联网金融技术实践与探索@upyun opentalk
 
Understanding the Disruptor
Understanding the DisruptorUnderstanding the Disruptor
Understanding the Disruptor
 
米聊服务器技术选型与架构
米聊服务器技术选型与架构米聊服务器技术选型与架构
米聊服务器技术选型与架构
 
Continuations in scala (incomplete version)
Continuations in scala (incomplete version)Continuations in scala (incomplete version)
Continuations in scala (incomplete version)
 
Scala funbyexample
Scala funbyexampleScala funbyexample
Scala funbyexample
 
More Than Java Concurrency
More Than Java ConcurrencyMore Than Java Concurrency
More Than Java Concurrency
 
DAE
DAEDAE
DAE
 
Architecture patterns and practices
Architecture patterns and practicesArchitecture patterns and practices
Architecture patterns and practices
 
Kafka简介
Kafka简介Kafka简介
Kafka简介
 
Scala the-good-parts
Scala the-good-partsScala the-good-parts
Scala the-good-parts
 
HBase@taobao for 技术沙龙
HBase@taobao for 技术沙龙HBase@taobao for 技术沙龙
HBase@taobao for 技术沙龙
 
Taming Java Agents
Taming Java AgentsTaming Java Agents
Taming Java Agents
 
了解集群
了解集群了解集群
了解集群
 

Similar to 我对后端优化的一点想法 (2012)

阿里巴巴 叶正盛 数据库性能量化
阿里巴巴 叶正盛 数据库性能量化阿里巴巴 叶正盛 数据库性能量化
阿里巴巴 叶正盛 数据库性能量化colderboy17
 
阿里巴巴 叶正盛 数据库性能量化
阿里巴巴 叶正盛 数据库性能量化阿里巴巴 叶正盛 数据库性能量化
阿里巴巴 叶正盛 数据库性能量化guiyingshenxia
 
Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南HonestQiao
 
Baidu LSP and DISQL for Log Analysis
Baidu LSP and DISQL for Log AnalysisBaidu LSP and DISQL for Log Analysis
Baidu LSP and DISQL for Log AnalysisXiaoming Chen
 
Osc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresqlOsc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresqlOpenSourceCamp
 
Sql调优clustering factor影响数据删除速度一例
Sql调优clustering factor影响数据删除速度一例Sql调优clustering factor影响数据删除速度一例
Sql调优clustering factor影响数据删除速度一例maclean liu
 
Performance Data Analyze
Performance Data AnalyzePerformance Data Analyze
Performance Data Analyzeanysql
 
淘宝前端优化
淘宝前端优化淘宝前端优化
淘宝前端优化锐 张
 
数据库性能诊断的七种武器
数据库性能诊断的七种武器数据库性能诊断的七种武器
数据库性能诊断的七种武器Leyi (Kamus) Zhang
 
MongoDB for C# developer
MongoDB for C# developerMongoDB for C# developer
MongoDB for C# developerdianming.song
 
基于嵌入式系统的Avs P10编码系统设计
基于嵌入式系统的Avs P10编码系统设计基于嵌入式系统的Avs P10编码系统设计
基于嵌入式系统的Avs P10编码系统设计Hengyi
 
Mysql fast share
Mysql fast shareMysql fast share
Mysql fast sharerfyiamcool
 
Elastic Stack 最新动态
Elastic Stack 最新动态Elastic Stack 最新动态
Elastic Stack 最新动态Elasticsearch
 
Sql Server 高级技巧系列之三整体优化
Sql Server 高级技巧系列之三整体优化Sql Server 高级技巧系列之三整体优化
Sql Server 高级技巧系列之三整体优化向 翔
 
MySQL新技术探索与实践
MySQL新技术探索与实践MySQL新技术探索与实践
MySQL新技术探索与实践Lixun Peng
 
Oracle中比对2张表之间数据是否一致的几种方法
Oracle中比对2张表之间数据是否一致的几种方法Oracle中比对2张表之间数据是否一致的几种方法
Oracle中比对2张表之间数据是否一致的几种方法maclean liu
 
Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構
Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構
Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構Etu Solution
 
Altibase管理培训 安装篇
Altibase管理培训 安装篇Altibase管理培训 安装篇
Altibase管理培训 安装篇小新 制造
 
腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化topgeek
 
Mysql handlersocket
Mysql handlersocketMysql handlersocket
Mysql handlersocketpwesh
 

Similar to 我对后端优化的一点想法 (2012) (20)

阿里巴巴 叶正盛 数据库性能量化
阿里巴巴 叶正盛 数据库性能量化阿里巴巴 叶正盛 数据库性能量化
阿里巴巴 叶正盛 数据库性能量化
 
阿里巴巴 叶正盛 数据库性能量化
阿里巴巴 叶正盛 数据库性能量化阿里巴巴 叶正盛 数据库性能量化
阿里巴巴 叶正盛 数据库性能量化
 
Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南
 
Baidu LSP and DISQL for Log Analysis
Baidu LSP and DISQL for Log AnalysisBaidu LSP and DISQL for Log Analysis
Baidu LSP and DISQL for Log Analysis
 
Osc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresqlOsc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresql
 
Sql调优clustering factor影响数据删除速度一例
Sql调优clustering factor影响数据删除速度一例Sql调优clustering factor影响数据删除速度一例
Sql调优clustering factor影响数据删除速度一例
 
Performance Data Analyze
Performance Data AnalyzePerformance Data Analyze
Performance Data Analyze
 
淘宝前端优化
淘宝前端优化淘宝前端优化
淘宝前端优化
 
数据库性能诊断的七种武器
数据库性能诊断的七种武器数据库性能诊断的七种武器
数据库性能诊断的七种武器
 
MongoDB for C# developer
MongoDB for C# developerMongoDB for C# developer
MongoDB for C# developer
 
基于嵌入式系统的Avs P10编码系统设计
基于嵌入式系统的Avs P10编码系统设计基于嵌入式系统的Avs P10编码系统设计
基于嵌入式系统的Avs P10编码系统设计
 
Mysql fast share
Mysql fast shareMysql fast share
Mysql fast share
 
Elastic Stack 最新动态
Elastic Stack 最新动态Elastic Stack 最新动态
Elastic Stack 最新动态
 
Sql Server 高级技巧系列之三整体优化
Sql Server 高级技巧系列之三整体优化Sql Server 高级技巧系列之三整体优化
Sql Server 高级技巧系列之三整体优化
 
MySQL新技术探索与实践
MySQL新技术探索与实践MySQL新技术探索与实践
MySQL新技术探索与实践
 
Oracle中比对2张表之间数据是否一致的几种方法
Oracle中比对2张表之间数据是否一致的几种方法Oracle中比对2张表之间数据是否一致的几种方法
Oracle中比对2张表之间数据是否一致的几种方法
 
Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構
Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構
Track A-3 Enterprise Data Lake in Action - 搭建「活」的企業 Big Data 生態架構
 
Altibase管理培训 安装篇
Altibase管理培训 安装篇Altibase管理培训 安装篇
Altibase管理培训 安装篇
 
腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化腾讯大讲堂06 qq邮箱性能优化
腾讯大讲堂06 qq邮箱性能优化
 
Mysql handlersocket
Mysql handlersocketMysql handlersocket
Mysql handlersocket
 

More from james tong

数据库系统设计漫谈
数据库系统设计漫谈数据库系统设计漫谈
数据库系统设计漫谈james tong
 
Oracle 性能优化
Oracle 性能优化Oracle 性能优化
Oracle 性能优化james tong
 
Cap 理论与实践
Cap 理论与实践Cap 理论与实践
Cap 理论与实践james tong
 
Scalable system operations presentation
Scalable system operations presentationScalable system operations presentation
Scalable system operations presentationjames tong
 
Benchmarks, performance, scalability, and capacity what s behind the numbers...
Benchmarks, performance, scalability, and capacity  what s behind the numbers...Benchmarks, performance, scalability, and capacity  what s behind the numbers...
Benchmarks, performance, scalability, and capacity what s behind the numbers...james tong
 
Stability patterns presentation
Stability patterns presentationStability patterns presentation
Stability patterns presentationjames tong
 
Troubleshooting mysql-tutorial
Troubleshooting mysql-tutorialTroubleshooting mysql-tutorial
Troubleshooting mysql-tutorialjames tong
 
设计可扩展的Oracle应用
设计可扩展的Oracle应用设计可扩展的Oracle应用
设计可扩展的Oracle应用james tong
 
Enqueue Lock介绍.ppt
Enqueue Lock介绍.pptEnqueue Lock介绍.ppt
Enqueue Lock介绍.pptjames tong
 
Oracle数据库体系结构简介.ppt
Oracle数据库体系结构简介.pptOracle数据库体系结构简介.ppt
Oracle数据库体系结构简介.pptjames tong
 
Cassandra简介.ppt
Cassandra简介.pptCassandra简介.ppt
Cassandra简介.pptjames tong
 

More from james tong (11)

数据库系统设计漫谈
数据库系统设计漫谈数据库系统设计漫谈
数据库系统设计漫谈
 
Oracle 性能优化
Oracle 性能优化Oracle 性能优化
Oracle 性能优化
 
Cap 理论与实践
Cap 理论与实践Cap 理论与实践
Cap 理论与实践
 
Scalable system operations presentation
Scalable system operations presentationScalable system operations presentation
Scalable system operations presentation
 
Benchmarks, performance, scalability, and capacity what s behind the numbers...
Benchmarks, performance, scalability, and capacity  what s behind the numbers...Benchmarks, performance, scalability, and capacity  what s behind the numbers...
Benchmarks, performance, scalability, and capacity what s behind the numbers...
 
Stability patterns presentation
Stability patterns presentationStability patterns presentation
Stability patterns presentation
 
Troubleshooting mysql-tutorial
Troubleshooting mysql-tutorialTroubleshooting mysql-tutorial
Troubleshooting mysql-tutorial
 
设计可扩展的Oracle应用
设计可扩展的Oracle应用设计可扩展的Oracle应用
设计可扩展的Oracle应用
 
Enqueue Lock介绍.ppt
Enqueue Lock介绍.pptEnqueue Lock介绍.ppt
Enqueue Lock介绍.ppt
 
Oracle数据库体系结构简介.ppt
Oracle数据库体系结构简介.pptOracle数据库体系结构简介.ppt
Oracle数据库体系结构简介.ppt
 
Cassandra简介.ppt
Cassandra简介.pptCassandra简介.ppt
Cassandra简介.ppt
 

我对后端优化的一点想法 (2012)

  • 1.
  • 3. 什么是优化? 响应时间 Vs 吞吐量 性能与可伸缩性(Performance Vs Scalability) Instrument & metrics 需要了解的一点硬件知识 常见案例分析 引用资料
  • 4. 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
  • 5. 不访问不必要的数据 使用B*Tree/hash等方法定位必要的数据 使用column Store或分表的方式将数据分开存储 合理的利用硬件来提升访问效率 使用缓存消除对数据的重复访问 使用批量处理来减少交互次数(磁盘、网络) 使用新硬件来降低后端的延时,提高效率 提高系统的吞吐量 对工作单元进行细化,减少串行操作 优化硬件配置,提高整体的TCO与硬件利用率 合理的拆分(水平、垂直拆分)以提高系统的整体吞吐能力
  • 7. Response Time = Service Time + Queue Time 经典的响应时间曲线.到达率为1.55trx/s,响应时间为 3ms/Trx,服务时间为2ms/Trx,排队时间为1ms/trx
  • 8. 450 400 350 300 线性扩展 250 Amdahl扩展(f=0.3) Amdahl扩展(f=0.2) 200 Amdahl扩展(f=0.1) 150 USL扩展(0.1,0.1) USL扩展(0.1,0.2) 100 50 0 0 2 4 6 8 10 12 14 16 18 20 22
  • 9. Amdahl's law 使用多处理器进行 并行处理能够提升的性能的 比例受限于程序中需要串行处理的比例 USL Scalability 使用多处理器进行 并行处理能够提升的性能的 比例不仅受限于程序中需要串行处理的比 例, 还受限于进程之间的并发系数.
  • 10. What gets measured gets managed. Peter Drucker (彼得. 德鲁克 ) Don't guess, get the data Anonymous
  • 12. 从杭州北京(花费了6个半小时) 13:00 – 13:15 从公司下楼到淘宝(15分钟) 13:30 – 13:50 从淘宝出发到上出租车(20分钟) 14:00 - 15:00 在出租车上,从淘宝<->机场(60分钟) 15:10 - 15:20 拿机票(10分钟) 15:25 - 15:50 安检(25分钟) 16:00 – 17:00 在机场候机(60分钟) 17:00 - 18:20 飞机上,杭州北京(80分钟) 18:20 - 18:40 到出租车上车点(20分钟) 18:40 - 18:55 等待出租车(15分钟) 18:55 - 19:50 机场到酒店(55分钟)
  • 13. Metrics v$sys_time_model & v$sess_time_model v$sysstat & v$sesstat v$system_event & v$session_event v$session_wait & v$event_histogram Instrument Extended 10046 trace
  • 14. vmstat & iostat & netstat & tcprstat & sar strace & oprofile & systemtap aspersa & latencytop & top [oracle@mytest ~]$ ps -ef | grep dbw oracle 8323 1 0 2010 ? 00:42:29 ora_dbw0_mytest [oracle@mytest ~]$ strace -c -p 8323 Process 8323 attached - interrupt to quit Process 8323 detached % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ------------- 98.39 0.007194 37 195 pwrite 1.61 0.000118 0 644 times 0.00 0.000000 0 1 read 0.00 0.000000 0 1 open 0.00 0.000000 0 1 close 0.00 0.000000 0 10 getrusage 0.00 0.000000 0 11 11 semtimedop ------ ----------- ----------- --------- --------- ------------- 100.00 0.007312 863 11 total
  • 15. 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
  • 16. 传统磁盘的IO特性 Nand Flash本身的IO特性 Read 25μs Write(program) 250 μs Erase 2000 μs Intel 320 SSD Read 75 μs Write 90 μs Fusion-IO Read : 68μs Write: 15μs Storage通道的处理延时 10GbE的Latency : 10-50 μs Fabric Channel 的latency:20-50 μs InfiniBand 的Latency :1-3 μs
  • 17.
  • 18. 优化传统B*Tree 优化数据访问 如何更好的设计索引 使用Write Optimized B-Tree优化数据访问 Stratified B-trees (Acunu) LSM tree(BigTable,Cassandra,LevelDB) Fractal Tree Indexes(TokuDB) 使用基于Hash的算法访问数据 Oracle Hash Cluster,BDB,Bitcask
  • 19. 模拟场景 表中有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);
  • 20. 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
  • 21. 场景介绍 表VeryBigTable含有30个列 表的记录数为50,000,000条 平均每个用户为300条左右 其中有2个列属于详细描述字段,平均长度为2k 其它的列的总长度平均为250个字节 此表上的查询有两种模式 列出表中的主要信息(每次20条,不包含详细信息,90%的查询) 查看记录的详细信息(10%的查询) 保存在Oracle数据库中,默认block size(8k) 要求 对此业务进行优化 分析数据,说服开发部门实施此优化
  • 22. 性能分析 每块记录数 8192 * 0.80(1) / 250 = 25.5 (主表) 8192 * 0.80 / 2000 = 3.27(详情表) 8192 * 0.80 / ( 2000 + 250 ) = 2.91 访问的逻辑IO(内存块访问) List的查询代价 改进后=( 300/25.5 ) * y + 4 + x = 4 + x + 11.8y = 42 + 73 + 11.8 * 1.54 = 28.7 改进前=( 300/2.91 ) * y + 4 + x = 4 + x + 103.y = 4 + 7 + 103 * 1.5 = 165.5 访问涉及到的物理读(磁盘块访问) List的查询代价(逻辑IO * ( 1 – 命中率 )) 改进后=28.7 * ( 1 – 0.855) = 4.305 改进前=165.5 * ( 1 – 0.85 ) = 24.825 访问时间(ms) 改进后=逻辑IO时间+物理IO时间= 28.7 * 0.016 + 4.305 * 77 = 30.422ms 改进前=逻辑IO时间+物理IO时间= 165.5 * 0.01 + 24.825 * 7 = 175.43ms
  • 23. 使用场景 缓存的一致性维护问题 数据的具体读写比 变更频率 业务对一致性的要求 使用何种缓存方式. 注意事项 考虑缓存的刷新策略 考虑缓存的数据延迟对业务的影响 考虑缓存失效时,系统的支撑能力 参考缓存工具: MemCached, Tair, Redis
  • 24. elapsed time elapsed time 16 14 12 10 8 6 4 2 0 Logical Reads Logical Reads 120000 100000 80000 60000 40000 20000 0
  • 26. Five minute rule? Price / Performance Break Point? 一台机器配置的代价 机架成本 电力成本(机器电力?Cooling?) CPU license成本(Oracle?Veritas ?) 机器成本? 使用PCI-E SSD? 使用HBA?InfiniBand?交换机? 多使用内存?多使用磁盘? 单机故障对业务的影响代价?
  • 27. 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 冯大辉/胡怡文/童家旺
  • 28. Q&A