Python multithreading vs. multi-process CPU usage

Source: Internet
Author: User
Tags cpu usage

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

Related Article

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.