【问题标题】:Why does Puma create multiple PIDs if its multi-thread instead of multi-process?如果 Puma 是多线程而不是多进程,为什么 Puma 会创建多个 PID?
【发布时间】:2017-05-08 07:49:59
【问题描述】:

如果 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

我一直在学习线程与进程,我认为线程是“进程内的执行路径”,所以这让我感到困惑。

【问题讨论】:

    标签: ruby-on-rails multithreading puma


    【解决方案1】:

    Puma 是一个线程服务器,但也允许多个工作人员(进程)。如果您查看初始化日志,它会提到它产生了多少 workers

    [22095] * Process workers: 2
    

    这称为 Puma 的集群模式。每个进程都会产生

    [22095] * Min threads: 1, max threads: 1
    

    并发处理请求的线程数量。

    了解更多信息:Puma Clustered Mode

    【讨论】:

      猜你喜欢
      • 2019-05-15
      • 2017-06-01
      • 1970-01-01
      • 2013-07-27
      • 1970-01-01
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      相关资源
      最近更新 更多