简体   繁体   English

计算并发python脚本的最大数量

[英]Figuring out the max number of concurrent python scripts

Say I want to run:说我想跑:

python script1.py &
python script2.py &

Each script is the same and just processes different files.每个脚本都是相同的,只是处理不同的文件。 How can I figure out how many of these scripts can I split into ?我怎样才能弄清楚我可以分成多少个这些脚本?

What is the relation to the CPU core count or number of threads ?与 CPU 核心数或线程数有什么关系? (memory wise I can figure it out) (记忆明智我可以弄清楚)

Whenever you execute python script.py & this will create a new process that will be running in background and performing the work specified in script.py .每当您执行python script.py &这将创建一个新进程,该进程将在后台运行并执行script.py指定的工作。

You can basically start the maximum number of process as supported on your system, you can find out using executing the command cat /proc/sys/kernel/pid_max which will probably returns 32768 .您基本上可以启动系统支持的最大进程数,您可以使用执行命令cat /proc/sys/kernel/pid_max它可能会返回32768 This number represents the maximum unique process identifiers the system can allocate to the processes.该数字表示系统可以分配给进程的最大唯一进程标识符。


Relation between CPU cores and number of threads: CPU内核与线程数的关系:

Threads don't exists independently on their own they resides within a bounding process (the process which creates the threads).线程不是独立存在的,它们驻留在边界进程(创建线程的进程)中。 Threads do have their own stack and registers.线程确实有自己的堆栈和寄存器。 Modern computers can creates 1000's(of course software threads) of thread simultaneously.现代计算机可以同时创建 1000 个(当然是软件线程)线程。 But generally speaking the number of parallel threads that can execute is limited to number of CPU cores available on the system.但一般来说,可以执行的并行线程数受限于系统上可用的 CPU 内核数。 In case of the system that supports hyper-threading this number may be higher.如果系统支持超线程,这个数字可能会更高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM