Application of estimation and little law

Source: Internet
Author: User

The estimated data mainly depends on the data and common sense available, and sometimes includes practice, not just theory. It is often used as a subproblem in a big problem. Proper estimation can save the time and cost of accurate calculation. In the computer field, the so-called common sense content is very broad, such as the transmission speed of the hard disk, the number of instructions that the CPU can execute per second, the size of various data structures, or even the number of words entered per minute. Some data can be found from various types of data, but it is inevitable that only memory is missing. If there is a systematic knowledge structure established after learning, this makes it easy to organize these common sense. In addition, it can be inspired by the accumulation of experience and some interview questions. Here we will perform a collection and update at any time.

The little law goes deep into the details of the law on which estimation depends: the total cost equals the cost of each part and multiplied by the total number of parts. It is very useful in some computer system calculations.

 

  Computer estimation problems:

1. The speed of reading and writing hard disk files is small: Can it exceed 10 Mb/s? (A sub-question about the server that I was asked during an interview)

Analysis: Based on previous file copying experience, the read/write speed is much faster than this value for scenarios where not multiple small files are scattered. Therefore, we have made a positive answer.

 

2. determine the number of times an empty loop for (I = 0; I <n; I ++) is executed in one second N, make it half of the total number of instructions executed by the CPU in one second (the first chapter of the beauty of programming)

Analysis: first, empty loops are converted into assembly commands:

loop:mov dx iinc dxmov i dxcmp i njl loop

There are five commands in total. Assume that the CPU used is a single core of 2 to 4 GHz, that is, 2 to 4G clock cycles per second. (common sense) the modern CPU executes more than two codes per clock cycle, then an empty loop (2 400 000 000*2)/5 = 960 000 000 times can be executed in one second.

(Optimization for reducing the order of magnitude to improve accuracy is not discussed)

 

3. Can struct node {int I; struct node * p} Mount such nodes into a computer with MB of memory? (Programming Pearl 7.2 performance estimation)

Analysis: to simplify the discussion, assuming that the int and pointer on the 32-bit machine are both 32-bit, And the 8B is shared, the direct calculation result is only 16 Mb, the author of "programming Pearl" usually has MB of idle computers, which seems to be enough. However, when malloc () is used to allocate space for nodes, it will take up extra space (cause: the mechanism of malloc, Linux's malloc () has a minimum size allocated each time, less than this value will also be allocated so much; struct alignment), this value is 40B on the author's computer, resulting in a total of 96 MB space, in fact, is not enough.

 

4. actual consumed time of calculation: Is the running time of a single SQRT () calculated accurately using for (I = 0; I <n; I ++) fa = SQRT (10.0? (Programming Pearl 7.2 performance estimation)

The actual single operation time may be much slower, because SQRT () may save the most recent parameter as the starting value.

(More to be supplemented ......)

 

  Common estimation rules:

1. "72 rule": Invest in y year at an annual rate of R %. If R * Y = 72, the investment will almost double.

If t = (1 + R/100) y and R is replaced with 72/y, that is, t = (1 + 72/(100y) y, we will find that the T value is near 2, which complies with this rule.

Application: assume that an exponential program needs 10 s to solve the n = 40 problem, and the running time of N increases by 12% every time it increases by 1. Then, according to the 72 Law, each increase of N is 6, the running time is doubled. Furthermore, each time N increases by 60, the running time is 1000 times of the original time (an approximate number of 210 ).

 

2. (memory knowledge) π second is a century.

Note: There are 3.155*107 seconds in a year, and the product of π is equivalent to the value of 3.14 and X 10-9 in.

 

3. Little law: the average number of objects in the queue is the product of the entry rate and the average residence time.

Note: The obvious rule is that the total overhead is equal to the number of units multiplied by each overhead, while the litte law describes a dynamic system. If you want to understand the proof of law, you need knowledge about the random process and queuing theory.

Application: the response time formula of a multi-user system. It considers the time Z for N users to log on to the response time r system. Each user cycle is the user's thinking and system response, that is, Z + R; the total number of jobs is N. For a time point, the average load is N, the average response time is Z + R, and the throughput is X (number of jobs processed per time unit ), according to Little's law, n = x * (Z + r), then we can solve r = N/X-Z.

Example 1: A computer system, including disks, processors, operating systems, and 20 terminals with 20 seconds of thinking, its disk processes 100 data requests for each job, and the disk can process 25 requests per second. How much is the system's throughput and response time?

A: throughput is calculated directly. The value is 25/100 = 0.25 jobs/second, and the response time is r = 20/0. 25-20 = 60 seconds. This is the exact solution under the stream balance.

Example 2: (programming) (continued), exercise 7.8) Assume that a job is executed for 20 seconds on a machine, and the machine may execute 10 jobs at a time, your job is the last one of the 100 pending jobs, which is executed in the first-in-first-out mode. How long does it take to wait until the execution of the job ends?

A: Two queuing systems should be considered: the waiting for execution task queue and the computer system itself. According to Little's law, the output rate of the second system task is X = L/R, L = 10 tasks, r = 20 seconds, and therefore x = 0.5 tasks/second. This is also the task arrival rate of the second system. Therefore, when the last task is completed in the first 99 tasks after 198 seconds, the total execution time is 218 seconds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.