Python multithreading vs. multi-process CPU usage
# Multi-process
This is not a run-over process before the use of the situation
After running 2 multi-process:
Usage Rate 65%,
After running 4 multi-process:
CPU Usage: 100%
--------------------------------------------------Split Line------------------------------------------------------------
Multithreading:
4 threads are turned on, but the usage rate is always 20, because in Python, there is always only one thread working
-------------------------------------------------Split Line---------------------------------------------------------------
Java Multithreading:
Java to turn on two thread dead cycles utilization: 52.3%
Java to turn on 4 thread dead cycles utilization: 99%
------------------------------------------------------------Split Line---------------------------------------------------
See here, you seem to find out what!!
1, by the visible, Python thread is how chicken.
2, of course, also know that threads can be parallel (4 threads assigned to other physical cores, in the eyes of the CPU, only threads), threads are possible (can) be assigned to different CPU cores to execute.
3, in addition, the CPU has a policy, some CPUs, although the core is more, but not all the core work at the same time, because to consider the energy saving, heat, etc., it will selectively turn off some of the core
4, Python can be multi-process + main thread way to achieve parallel
Current CPU Mainstream structure:
N-Core N*2 threads: for example, a dual core four thread, it is a pseudo quad core, not a true four core, simulating each physical core into 4 logical cores
Good For example: There are two wide 4 meters across the road (dual core), was used to plan the line into 8 1 meters of the road, then it can run at the same time 8 width 1 meters of the car, but the width of 4 meters can only run 2 cars
N-Core N threads: for example quad-core four threads
Good For example: There are four 4 meters wide road, can run 16 1 meters of the car, can also run 4 cars 4 wide meters. This is why the same generation of i3 is cheaper than i5, and in parallel with small amounts of data,
Dual-core four threads work, but large amounts of data do not compare to true quad-core.
Python multithreading vs. multi-process CPU usage