Unit 5 Queuing Theory

Unit 5 Queuing Theory

排队理论 排队理论是基于利特尔定律的
本章是理论与实践相结合的
从第五章开始是分水岭,第五章之前的都是监控,第五章开始都是调优
通过检测的数据利用理论来计算得出需要调优的方向与目标,最后用调优的方法去改善性能的状况
所有的调优都用队列技术,排队技术来解决问题
 
1.
Objectives:
Upon completion of this unit ,you should be able to:
         .understand key terminology for performance tuning
         .apply queuing theory to performance issues
         .understand asymptotic complexity
译文:
         理解调优的关键术语
         使用排队理论来解决性能问题
         理解渐进复杂性
说明:队列技术不是计算机领域的定理,1961年由john little创立
利特尔定律
2.
Introduction to queuing theory
.little’s Law provides the foundation
         .mathematically proven by john little in 1961
.benefits
         .Enables an engineering approach to performance management
         .quantitatively estimeate future performance of the system
         .interpret relevant output of monitoring utilities.
         .validate correctness of measured values and software instrumentation
译文:
好处:
         使用工程的的方法来进行性能管理
         定量估计未来的系统性能
         解释有关监控工具的输出
         验证软件测试的正确性
3.
Little’s Law
Key term
         .Queue length: average number of requests waiting in the system.
         .Arrival rate: the rate at which requests enter a system
         .Wait time: average time to satisfy a request
                   Also known as wall clock,latency,response time,or residence time
         L=A*W
所有后面的公式都是围绕这个公式提出来的;
译文:
利特尔定律
队列长度:在system中等待请求的平均数量,单位req
到达率:请求进入系统的速率,req/s
等待时间:也被称为延迟,响应时间,停留时间, s
解释:
As a result of little’s Law , wait time may be longer than the observation period because it reflects the amount of time that all requests spent waiting in the queue for a resource. If more requests arrive during the obvervation period than the resource can process, the queue will grow in size and the wait time will increase.
译文:
Wait time(等待时间) 可能比observation period(观察时间) 时间更长,因为wait time取决于所有在队列中等待请求的时间,如果在observation period 有更多的请求到达的话,队列长度会增长,wait time也会增长;
The arrival rate is the rate at which work enters a system: A=arrivals/observation period
译文:
到达率是速率,到达率=到达的请求数/观察时间
在观察时间的内到达请求的速率
Software instrumentation consists of various hooks or utilizes that enable users to measure performance .
4.
Queue length
.requests are buffered in memory
         .L may be a read-write tunable or a read-only measurement
         .Class-based queuing is based on prioritized queues
                   Example:execute reads before writes(why?)
                   Algorithms must prevent starvation
.Considerations
         .shorter queue lengths optimize(conserve) memory
         .longer queue lengths enable efficient re-sorting for important requests
译文:
队列长度L
请求被缓存在内存中
短的队列长度可以优化内存
较长的队列能够对重要的请求进行重新排序
读比写更优先执行,算法必须防止饥饿
Find /proc /sys –type f –writable –ls
Find /proc /sys –type –readable \! –writable –ls
5.
译文:
当到达率处于一个稳定的状态A
运用数学的理论进行分析
6.
等待时间wait time 包括:
Queue time :队列时间
Service time: 服务时间
L=AW
L =A(Q+S)
7.
译文:
进一步了解等待时间
服务时间又包括:
         System time:内核的时间
         User time : 用户层,应用程序所用时间
系统的稳定才是王道
L=AW=A(Q+S)=A(Q+Ssys+Suser)
8.
Finding hot spots in code
Summarize system calls and follow forks
         Strace –fc elinks –dump http://server1.example.com/pub
Summarize system and library calls and follow forks
         Ltrace –Sfc elinks –dump http://server1.example.com/pub
Benefits
         Granular profile of system vs.user mode time
         Identify where applications spend their time
         Compare similar applications
判断某个脚本执行过程中什么动作执行的次数最多,那些动作执行的时间最长,查找代码中的热点
跟踪elinks命令的执行过程!
 
Yum –y install strace
跟踪命令的执行过程
好处:
         比较两个程序的性能差异
9.
译文:
4Mbps 每秒传输4M 比特,不是字节
100Mbps=100MB/8S=MB/S
带宽,吞吐量,开销
10.
Arrival rate vs completion rate
Key terms
         Arrival rate(A):rate at which work is requested.(eg..packets/s)
         Completion rate(C):rate at which work is performance(eg..packets/s)
         Observation period:discrete time spent observing resources(eg..1s)
Steady state:condition in which A=C
译文:
到达率,完成率,观察时间
理想状态是到达率等于完成率
11.
整个系统的吞吐量取决于系统最慢的部分;
12.
预测资源的瓶颈
The utilization law 利用率
Utilization = service time * arrival rate
13.
进一步理解:
Dd if=/dev/zero of=/tmp/bigfile bs=1M count=1044
在执行以上命令的同时使用iostat命令查看
r/s      w/s        rsec/s     wsec/s      avgrq-sz       avgqu-sz  await    svctm   %util
0.00  86.87  0.00         86892.93  1000.28    150.81    1621.94 11.65    101.21
2.97 80. 20    23.76 82122.77 987.71     141.03    1601.71 11.93   99. 21
分析:
注意单位
L1=A*W=(0.00+86.87)requests/s * 1621.94msec * 1 sec/1000mesc = 140.90requets
L2=A*W=(2.97+80. 20)requests/s *  1601.71msec * 1 sec/1000msec =133. 21requests
一个扇区是512B
Xdisk=(0+86892.93)sectors/s * 512B/1 sector * 1KiB/1024B*1MiB/1024KiB = 42.43MiB/s
磁盘的吞吐量
利用率U=S*A=服务时间*达到率
U=(0+86.87)requests/s * 11.65ms/request * 1s/1000ms=1.01
 
课后题:
Disk reporting:
290reads/s     0write/s   average service time 3.36ms
What do you tell your boss?
U=A*S=(290+0)requests/s* 3.36ms = 0.9744

你可能感兴趣的:(Theory,Queuing)