使用することもできますfork
-これはエレガントなソリューションではありませんが、仕事を成し遂げ、余分な可動部分を導入しません. Rails アプリ全体で fork を実行するには (かなり面倒ですが、リクエストを処理する Rails アプリはすぐに応答します)、プロセスを切り離します。
class SomeController < ApplicationController
def heavy_lifting
process = fork do
# calculate PI or process input
# ...
# sends the kill signal to current Process, which is the Rails App actually calculating PI
Process.kill("HUP")
end
Process.detach(process)
# respond here
end
end
処理/ジョブの実行に数メガのメモリしか必要としない場合fork
でも、親プロセスと同じ量のメモリを割り当てることに注意してください。fork が一般的に行うことの概要を以下に示します。
更新 - スレッドと同じこと
class SomeController < ApplicationController
def heavy_lifting
Thread.new do
# calculate PI or process input
# ...
Thread.kill
end
# respond here
end
end