What are QPS, TPS, RT, throughput?

1. QPS, query per second

QPS: Queries Per Second means "query rate per second", which is the number of queries that a server can respond to per second, and is a measure of how much traffic a specific query server can handle within a specified time. In the Internet, the performance of a machine as a domain name system server is often measured by the query rate per second.

2. TPS, transactions per second

TPS: is the abbreviation of TransactionsPerSecond, which is the number of transactions per second. It is the unit of measurement for software test results. A transaction is a process in which a client sends a request to the server and the server responds. The client starts timing when sending a request, and ends timing after receiving a response from the server to calculate the time used and the number of completed transactions. QPS vs TPS: QPS is basically similar to TPS, but the difference is that one visit to a page forms a TPS; but one page request may generate multiple requests to the server, and these requests from the server can be counted as " QPS". For example, accessing a page will request the server twice, and one access will generate a "T" and 2 "Q"s.

3. RT, response time

Response time: the total time it takes to execute a request from the beginning to the end when the response data is received, that is, the time from when the client initiates the request to when the server receives the response result. Response time RT (Response-time) is one of the most important indicators of a system, and its value directly reflects the speed of the system.

Fourth, the number of concurrent

The number of concurrency refers to the number of requests that the system can handle at the same time, which also reflects the load capacity of the system.

Five, throughput

The throughput (pressure bearing capacity) of the system is closely related to the CPU consumption of the request, external interfaces, IO, and so on. The higher the CPU consumption of a single request, the slower the external system interface and IO speed, the lower the system throughput, and vice versa. Several important parameters of system throughput: QPS (TPS), concurrent number, response time.

  1. QPS (TPS): (Query Per Second) the number of requests/transactions per second

  2. Concurrency: The number of requests/transactions processed by the system at the same time

  3. Response time: Generally take the average response time

After understanding the meaning of the above three elements, you can calculate the relationship between them:

  • QPS (TPS) = concurrent number / average response time

  • Concurrency = QPS * average response time

Six, practical examples

我们通过一个实例来把上面几个概念串起来理解。按二八定律来看,如果每天 80% 的访问集中在 20% 的时间里,这 20% 时间就叫做峰值时间。

  • 公式:( 总PV数 * 80% ) / ( 每天秒数 * 20% ) = 峰值时间每秒请求数(QPS)

  • 机器:峰值时间每秒QPS / 单台机器的QPS = 需要的机器

1、每天300w PV 的在单台机器上,这台机器需要多少QPS?
( 3000000 * 0.8 ) / (86400 * 0.2 ) = 139 (QPS)

2、如果一台机器的QPS是58,需要几台机器来支持?
139 / 58 = 3

七、最佳线程数、QPS、RT

1、单线程QPS公式:QPS=1000ms/RT
对同一个系统而言,支持的线程数越多,QPS越高。假设一个RT是80ms,则可以很容易的计算出QPS,QPS = 1000/80 = 12.5
多线程场景,如果把服务端的线程数提升到2,那么整个系统的QPS则为 2*(1000/80) = 25, 可见QPS随着线程的增加而线性增长,那QPS上不去就加线程呗,听起来很有道理,公司也说的通,但是往往现实并非如此。

2、QPS和RT的真实关系

我们想象的QPS、RT关系如下

img

实际的QPS、RT关系如下

img

3、最佳线程数量
刚好消耗完服务器的瓶颈资源的临界线程数,公式如下
最佳线程数量=((线程等待时间+线程cpu时间)/线程cpu时间)* cpu数量
特性:

  • 在达到最佳线程数的时候,线程数量继续递增,则QPS不变,而响应时间变长,持续递增线程数量,则QPS开始下降。

  • 每个系统都有其最佳线程数量,但是不同状态下,最佳线程数量是会变化的。

  • 瓶颈资源可以是CPU,可以是内存,可以是锁资源,IO资源:超过最佳线程数-导致资源的竞争,超过最佳线程数-响应时间递增。


Guess you like

Origin blog.51cto.com/14949262/2539705