Amplification analysis of double buffering class time calculation problem

Source: Internet
Author: User
amplification Analysis of double buffering class time calculation problem

@ (OS)

An OS uses double buffering to transfer data on disk. The time it takes to transfer data from disk to the buffer is T1, and the time it takes to transfer data from the buffer to the user area is T2 (assuming T2 is much smaller than T1,T3). The amount of time that the CPU takes to process the data is T3, and the total time used for the system is to repeat N times:

(n−1) Xmax (T1,T3) +t1+t2+t3. (n-1) \times MAX (T1,T3) +t1+t2+t3.

Analysis: For a double-buffered class problem, the time is Max (T1,T2+T3) max (T1,T2+T3), because T2 is much smaller than T1,T3, so kick out directly. Get Max (T1,T3) max (T1,T3)

That is, the time to process is determined by the two, who is the main contradiction.

This kind of problem can be analyzed and understood by oneself, not to remember a formula to run so fast.

We magnify the problem by assuming that the T1 is very, very large. So the process is, first through the T1 (very long and long time), finally the data to the buffer zone 1, in the buffer 1 of the comrades really wait enough, rushed to the user area (time T2,tiny tiny time), CPU more anxious, and so on for a long while finally waiting for data. Don't hesitate to deal with it immediately, time T3. Then why, start a long waiting round.
That is, the data through the T1 time to the buffer 1, immediately proceed to send data to buffer 2, which and buffer 1 of the students to send data to the user area at the same time, but t2+t3 far less than T1, so, just send the past data, they have finished processing, the second piece of data is not in place. Assuming a total of n data, the previous n-1 data will depend on when it can be sent to the buffer. Io is not lazy, keep working, send out buffer 1, send buffer 2, but it is too slow ah. Be aware that disk IO is hundreds of thousands of to millions slower than the CPU. So the former N-1 data center focus on T1,T2+T3 only a small point. The last nth data is transmitted to the buffer, time T1, after T2 sent to the user area, and then after T3CPU processing. So the last data is the complete t1+t2+t3. The front n-1 is (n-1) T1. The total time is (n-1) T1 + t1+t2+t3.

Another view: T3 Infinity. This may only exist theoretically, and it is unlikely that the CPU will be able to process data longer than IO. But also do not rule out to do is a huge complex operation, such as recursive, not cache dynamic planning, this pit CPU algorithm, of course T3 may be greater than T1. We assume that the input data in the CPU to do such a huge time-consuming operation, as if Infinity General. When the first data is sent from the disk to the buffer time T1, when it is sent to the user area T2,cpu T3 (long, long time) when processing is finished. When the CPU is processed, IO also starts synchronously, passes T1 to buffer 2, and then passes T2 to the user area. But this is a look, the CPU is still in the effort to calculate, not the end, had to wait. From the second start to Nth, will be the first two steps to complete quickly, waiting for the CPU to finish processing. Therefore, the total time is t1+t2+t3+ (n-1) T3.

Compare two data: (n-1) T1 + t1+t2+t3 (T1 very Large) t1+t2+t3+ (n-1) T3 (T3 very Large)

To extract a public expression is:

(n−1) Xmax (T1,T3) +t1+t2+t3. (n-1) \times MAX (T1,T3) +t1+t2+t3.

This is actually quite a space for thinking, exaggeration will be easier to understand.

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.