配置 puma 以使用 pdfkit

Config puma to use pdfkit

我正在尝试将 unicorn 更改为 puma,但是 pdfkit 有问题].要将 pdf 与 unicorn 一起使用,我必须从 3 个工人开始,但如果我对 puma 做同样的事情,它会停在 55%。

这是我的 puma 配置。

# config/puma.rb
port 3000
threads 0, 16
workers 3

我的开始日志:

=> Booting Puma
=> Rails 4.2.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[23551] Puma starting in cluster mode...
[23551] * Version 3.8.2 (ruby 2.3.1-p112), codename: Sassy Salamander
[23551] * Min threads: 0, max threads: 16
[23551] * Environment: development
[23551] * Process workers: 4
[23551] * Preloading application
[23551] * Listening on tcp://localhost:3000
[23551] Use Ctrl-C to stop
[23551] - Worker 0 (pid: 23571) booted, phase: 0
[23551] - Worker 1 (pid: 23580) booted, phase: 0
[23551] - Worker 2 (pid: 23589) booted, phase: 0
[23551] - Worker 3 (pid: 23598) booted, phase: 0

并在我尝试创建 pdf 时记录(它永远不会完成)。

Completed 200 OK in 40ms (Views: 4.2ms | ActiveRecord: 5.7ms)
[=================================>                          ] 55%

我必须说的另一件事是,在我的布局中,我使用了类似的东西(它通过对同一应用程序的请求呈现页眉和页脚):

  - if request_from_pdfkit?
    %meta{:name => 'pdfkit-header_html', :content => pdf_header_url(:protocol => 'http', :codigo =>params[:title])}
    %meta{:name => 'pdfkit-footer_html', :content => pdf_footer_url(:protocol => 'http', :codigo =>params[:title])}

感谢您的帮助!

编辑: 我做了其他尝试,我创建了 2 个端点,1 个使应用程序睡眠很多时间(/sleeprequest),其他呈现基本的 json(/examplerequest )。 我从相同的配置开始,如果我执行 /seleeprequest,应用程序将被阻止并且不接受 /examplerequest.

在那之前我有一个 nginx 和这个基本的 conf(我不知道它是否有问题):

  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  } 

还有我的流程

ps aux | grep puma
alejand+ 29391  2.1  1.2 573648 206572 pts/22  Sl+  10:18   0:07 puma 3.8.2 (tcp://localhost:3000)
alejand+ 29413  1.0  2.2 1193920 365412 pts/22 Sl+  10:18   0:03 puma: cluster worker 0: 29391
alejand+ 29422  0.5  1.9 1180024 313324 pts/22 Sl+  10:18   0:01 puma: cluster worker 1: 29391
alejand+ 29431  0.5  2.0 1180024 329728 pts/22 Sl+  10:18   0:02 puma: cluster worker 2: 29391

我终于找到我的错误了!

我在 rails 环境配置文件中禁用了共现:

 config.allow_concurrency = true

一切正常!!问题是我无法处理并发请求。

尝试在 config/application.rb 文件中添加以下行:

 config.allow_concurrency = true