Python multi-process VS multi-thread (多核CPU利用率)
2013-05-14 13:55
381 查看
现在用python开发服务器代码,因此简单对比了一下其multi-process和multi-thread的CPU利用率
对比图(top命令),结论:python(cpython)由于GIL的存在无法使用threading充分利用CPU资源,如果服务器为多核,请考虑使用multi-process提升性能
多进程( multi-process)
多线程(multi-thread)
源代码
多进程( multi-process)
多线程(multi-thread)
对比图(top命令),结论:python(cpython)由于GIL的存在无法使用threading充分利用CPU资源,如果服务器为多核,请考虑使用multi-process提升性能
多进程( multi-process)
多线程(multi-thread)
源代码
多进程( multi-process)
import multiprocessing def thread_func(): print "thread in" while True: pass if __name__ == "__main__": t1 = multiprocessing.Process(target = thread_func) t1.start() t2 = multiprocessing.Process(target = thread_func) t2.start() t1.join() t2.join()
多线程(multi-thread)
from threading import Thread def thread_func(): print "thread in" while True: pass if __name__ == "__main__": t1 = Thread(target = thread_func) t1.start() t2 = Thread(target = thread_func) t2.start() t1.join() t2.join()
相关文章推荐
- Python multi-process VS multi-thread (多核CPU利用率)
- Operating System-Thread(2) Multi-Process-Parallel vs Multi-Thread-Parallel
- 复习进程和线程 process vs thread
- Process和Thread在指定CPU运行
- 多核cpu的服务器cpu利用率
- VS2013 查看程序各个函数的CPU利用率<转>
- multi-CPU, multi-core and hyper-thread--转
- Process vs Thread
- difference between Multi process and multi thread
- Multi-thread & Multi-process
- VS2013 查看程序各个函数的CPU利用率
- SetThreadAffinityMask设置使用多核CPU的哪个核心
- Linux查看多核CPU利用率
- SetThreadAffinityMask设置使用多核CPU的哪个核心
- Linux process vs thread
- Using AfxBeginThread for multi-thread in VS C++
- Process vs Thread
- Linux Process VS Thread VS LWP
- Multi-thread VS function call
- Analysis of Process Multi-Thread Manangement Based on a simpilified Linux Kernel--myKernel