Python multi-process improves CPU utilization

Source: Internet
Author: User

CPU Parameters:

1 Physical cpu,2 logical CPUs (Hyper-threading), single-core specific http://blog.csdn.net/dba_waterbin/article/details/8644626 physical CPU, logical CPU, and CPU cores

Package files, single process

#Coding=utf-8 fromMultiprocessingImportProcessImportsys, OSImport TimedefTimetask (times): cmd="Tar zcfph/data/nerri_%s.tar.gz/data/backup"%Times Os.system (cmd)defworks_multi_process (func, Worknum): Proc_record= []     forIinchRange (worknum): P= Process (target = func, args =(i,)) P.start () Proc_record.append (p) forPinchProc_record:p.join ()defworks_single_process (func, Worknum): Proc_record= []     forIinchRange (worknum): P= Process (target = func, args =(i,)) P.start () P.join ( )if __name__=='__main__':    PrintTime.strftime ('============start:%h%m%s==========') procs= 2works_multi_process (Timetask, procs)PrintTime.strftime ('============end:%h%m%s========')

Results of Transport:

Single process:

============start:154554==========
============end:154903===========

Multi-process:

============start:155513==========

============end:155627========

viewing disk and CPU utilization: Iostat-x 1 10

Ps:

Single process consumes about 90 CPU average CPU about 45

Number of process processes 2 per process consumes about 90 CPU total CPU around 100

Number of process processes 31 processes Occupy CPU 90 or so the other two processes occupy cpu45 around the total CPU 100 or so

Number of process processes 4 per process consumes around cpu45 total CPU 100

The thread scheduling of the system. Even a single thread, at different time slices, can also be dispatched to different cores. can control which core to run on ~

Python multi-process improves CPU utilization

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.