有没有一种简单的方法可以在 Passenger 的请求周期之外运行垃圾收集?
Unicorn 有 OobGC 可用于运行 GC.start
在一定数量的请求之后。
Phusion Passenger 中有类似的东西吗?
Unicorn has OobGC rack middleware that can be used to run GC.start
after a certain number of requests.
Is there a similar sort of thing in Phusion Passenger?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Phusion Passenger 4 正式引入了带外垃圾收集机制。它比 Unicorn 更灵活,允许任意工作,而不仅仅是垃圾收集。 http:// blog.phusion.nl/2013/01/22/phusion-passenger-4-technology-preview-out-of-band-work/
Phusion Passenger 4 officially introduces an out of band garbage collection mechanism. It's more flexible than Unicorn's by allowing any arbitrary work, not just garbage collection. http://blog.phusion.nl/2013/01/22/phusion-passenger-4-technology-preview-out-of-band-work/
挂钩
PhusionPassenger::Rack::RequestHandler#process_request()
是我发现的唯一机制。要以与 Unicorn OobGC 类似的方式执行此操作,您可以使用以下模块:
并在初始化程序中调用它:
Hooking into
PhusionPassenger::Rack::RequestHandler#process_request()
is the only mechanism I have found.To do this in a similar way to the Unicorn OobGC, you can use the following module:
and invoke it in an initializer with:
你必须修补乘客。在每个请求被移交后执行
GC.start
可确保在保留客户端请求时不会发生垃圾收集。如果您想减少平均请求时间,您可能会考虑这是一项单行更改。在 lib/phusion_passenger/abstract_request_handler.rb 中,修补
accept_and_process_next_request
并在末尾添加GC.start
调用,并设置适当的间隔。有关示例,请参阅此提交(感谢@raphaelcm)。
You have to patch Passenger. Doing a
GC.start
after each request has been handed off ensures that garbage collection never occurs while holding a client request. This is a one-line change that you might consider if you're trying to reduce your average request time.In lib/phusion_passenger/abstract_request_handler.rb, patch
accept_and_process_next_request
and add theGC.start
call at the end, with an appropriate interval.See this commit for an example (thanks, @raphaelcm).