简体   繁体   English

(Nginx+Passenger) 运行线程的 Rails 与passenger_max_requests 设置一起使用时会被杀死

[英](Nginx+Passenger) Rails running Threads get killed when used along with passenger_max_requests setting

My Nginx+Passenger settings are the following:我的 Nginx+Passenger 设置如下:

passenger_max_pool_size 6;
passenger_max_requests 600;

And in my Rails Controller i use threads to do excel imports in the following manner:在我的 Rails Controller 中,我使用线程以下列方式执行 excel 导入:

t = Thread.new do
 @json_response = Import::Admin.create_admin_user params
end

The problem that i encounter is after the process serves 600 requests (which is the limit set to avoid memory leaks) it shuts down the process even if the above mentioned thread is alive and running on it.我遇到的问题是在进程服务了 600 个请求之后(这是为避免 memory 泄漏而设置的限制),即使上述线程处于活动状态并在其上运行,它也会关闭进程。

You are using Threads incorrectly, server won't wait for a Thread to finish.您使用的线程不正确,服务器不会等待线程完成。 If you need to perform heavy weight calculations, use background jobs.如果您需要执行繁重的计算,请使用后台作业。 For example ActiveJob with Sidekiq.例如带有 Sidekiq 的 ActiveJob。

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

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