This is the 7th day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

cpu-intensive

CPU intensive refers to that the performance of the hard disk and memory of the system is much better than that of the CPU. In this case, when the SYSTEM is running, the I/O can be completed in a very short time. However, the CPU has many operations to process, so the CPU is heavily loaded.

CPU intensive means that the task requires a lot of computation without blocking and the CPU runs at full speed all the time. Cpu-intensive tasks can only be speeded up on a truly multi-core CPU (through multiple threads), whereas on a single-core CPU, no matter how many simulated multi-threads you run, the task cannot be speeded up because the CPU has only so much total computing power.

In the case of high CPU usage (for example, calculating PI, decoding video in HD, matrix calculation, etc.), the number of threads is usually set to the number of CPU cores. This situation usually occurs in the complex calculation and logical processing of some businesses. For example, some current machine learning and deep learning model training and reasoning tasks involve a lot of matrix operations.

IO intensive

IO intensive means that the CPU performance of the system is much better than that of hard disks and memory. In this case, the CPU is waiting for I/O (hard disk/memory) read and write operations. Therefore, the CPU load is not high.

Intensive programs typically reach their performance limits with low CPU usage. This is probably because the task itself requires a lot of I/O, and the logic of the program is not done very well to make full use of processor power.

CPU usage is low, there will be a large number of I/O operations in the program to occupy time, resulting in a lot of free time thread, usually need to open the CPU core several times the thread.

The calculation formula is: number of IO intensive core threads = number of CPU cores/(1- blocking coefficient).

When the CPU is idle during I/O operations, enable other threads to continue using the CPU to increase THE CPU usage. For example: database interaction, file upload and download, network transmission and so on.

This section describes the usage of CPU – intensive and IO – intensive tasks

  • When the proportion of thread waiting time is higher, more threads are needed to enable other threads to continue using THE CPU, so as to improve THE CPU utilization.
  • When the proportion of thread CPU time is higher, fewer threads are needed. Usually, the number of threads is the same as the number of CPU cores. This type of development mainly occurs in some logic with frequent computing operations.

Differences between CPU intensive tasks and IO intensive tasks

Computation-intensive tasks require a large amount of computation and consume CPU resources, depending on the computing power of the CPU. This type of computationally intensive task can also be completed with multi-task, but the more tasks, the more time spent in task switching, and the lower the EFFICIENCY of CPU task execution. Therefore, for the most efficient utilization of CPU, the number of computationally intensive tasks should be equal to the number of CPU cores at the same time, avoiding thread or process switching.

Since computationally intensive tasks consume CPU resources, code execution efficiency is critical. Scripting languages such as Python are inefficient and completely unsuitable for computationally intensive tasks. For computationally intensive tasks, it is best to write in C.

IO intensive tasks are characterized by low CPU consumption and spend most of the task’s time waiting for IO operations to complete (because THE IO speed is much slower than the CPU and memory speed). Tasks involving network and disk IO are IO intensive tasks.

For IO intensive tasks, the higher the number of threads, the higher the CPU efficiency, but there is a limit.

conclusion

  1. A computation-oriented application (CPU intensive program) can utilize all the CPU cores in a multi-threaded or multi-process run. For example, a 16-core CPU can run 16 computational tasks at the same time with 16 threads, which is the maximum efficiency. However, if the number of threads/processes far exceeds the number of CPU cores, the task becomes less efficient, since frequent thread or process switching is also time consuming. Therefore, for CPU-intensive tasks, the number of threads/processes equal to the number of cpus is best.
  2. If it is a disk or network based application (IO intensive program), a thread in the IO wait, another thread can be run in the CPU, sometimes CPU idle, all threads waiting for IO, this time they are at the same time, the single thread, at this time or in a a wait. We all know that IO is slow compared to CPU. The number of threads can be several times the number of CPU cores (as the case may be).

The resources

  • What are CPU intensive and IO intensive?
  • CPU intensive vs. IO intensive