如果 Puma 是多线程而不是多进程,为什么它会创建多个 PID?
Why does Puma create multiple PIDs if its multi-thread instead of multi-process?
为什么 Puma 是多线程的,为什么要创建多个 PID?
我以为多个线程会存在于同一个进程中。
在本地启动 Puma 时:
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
[22095] Puma starting in cluster mode...
[22095] * Version 3.6.0 (ruby 2.2.2-p95), codename: Sleepy Sunday Serenity
[22095] * Min threads: 1, max threads: 1
[22095] * Environment: development
[22095] * Process workers: 2
[22095] * Preloading application
[22095] * Listening on tcp://localhost:3000
[22095] Use Ctrl-C to stop
[22095] - Worker 0 (pid: 22183) booted, phase: 0
[22095] - Worker 1 (pid: 22184) booted, phase: 0
当运行 ps aux | grep puma
:
me 22184 ... puma: cluster worker 1: 22095 [app]
me 22183 ... puma: cluster worker 0: 22095 [app]
me 22095 ... puma 3.6.0 (tcp://localhost:3000) [app]
me 22289 ... grep puma
我一直在学习线程与进程,我认为线程是 "path of execution inside a process",所以这让我感到困惑。
Puma 是一个线程服务器,但也允许多个工作者(进程)。如果您查看初始化日志,它会提到生成了多少 workers
。
[22095] * Process workers: 2
这就是Puma的集群模式。每个进程都会生成
[22095] * Min threads: 1, max threads: 1
并发处理请求的线程数量。
了解更多信息:Puma Clustered Mode
为什么 Puma 是多线程的,为什么要创建多个 PID?
我以为多个线程会存在于同一个进程中。
在本地启动 Puma 时:
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
[22095] Puma starting in cluster mode...
[22095] * Version 3.6.0 (ruby 2.2.2-p95), codename: Sleepy Sunday Serenity
[22095] * Min threads: 1, max threads: 1
[22095] * Environment: development
[22095] * Process workers: 2
[22095] * Preloading application
[22095] * Listening on tcp://localhost:3000
[22095] Use Ctrl-C to stop
[22095] - Worker 0 (pid: 22183) booted, phase: 0
[22095] - Worker 1 (pid: 22184) booted, phase: 0
当运行 ps aux | grep puma
:
me 22184 ... puma: cluster worker 1: 22095 [app]
me 22183 ... puma: cluster worker 0: 22095 [app]
me 22095 ... puma 3.6.0 (tcp://localhost:3000) [app]
me 22289 ... grep puma
我一直在学习线程与进程,我认为线程是 "path of execution inside a process",所以这让我感到困惑。
Puma 是一个线程服务器,但也允许多个工作者(进程)。如果您查看初始化日志,它会提到生成了多少 workers
。
[22095] * Process workers: 2
这就是Puma的集群模式。每个进程都会生成
[22095] * Min threads: 1, max threads: 1
并发处理请求的线程数量。
了解更多信息:Puma Clustered Mode