Compute-intensive vs IO-intensive

A second consideration for multitasking is the type of task. We can divide tasks into compute-intensive and IO-intensive.

Computation-intensive tasks are characterized by a large amount of computation and CPU resource consumption, such as calculating the pi ratio, decoding video in high-definition, etc., all of which depend on the computing power of the CPU. Although this kind of computing-intensive task can also be completed by multitasking, the more tasks, the more time spent in task switching, and the lower the efficiency of the CPU to perform tasks. The number of simultaneous tasks should be equal to the number of CPU cores.

Computation-intensive tasks mainly consume CPU resources, so the efficiency of the code is very important. Scripting languages ​​like Python are inefficient and completely unsuitable for computationally intensive tasks. For computationally intensive tasks, it is best to write in C.

The second type of task is IO-intensive. Tasks involving network and disk IO are all IO-intensive tasks. This type of task is characterized by low CPU consumption and most of the time of the task is waiting for the IO operation to complete (because The speed of IO is much lower than the speed of CPU and memory). For IO-intensive tasks, the more tasks, the higher the CPU efficiency, but there is a limit. Most common tasks are IO-intensive tasks, such as web applications.

During the execution of IO-intensive tasks, 99% of the time is spent on IO, and very little time is spent on the CPU. Therefore, it is completely impossible to replace the extremely slow scripting language such as Python with the extremely fast C language. Improve operational efficiency. For IO-intensive tasks, the most suitable language is the language with the highest development efficiency (the least amount of code), the scripting language is the first choice, and the C language is the worst.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326339592&siteId=291194637