如何启用基于法拉第和事件机同步的高性能http客户端?(How to enable high performance http client which is based on faraday and event machine synchrony?)
我正在重构一个使用法拉第作为请求客户端的ROR项目,并预定义适配器与EM同步一起使用,如下所示:
def which_faraday_adapter? if Utils::ModuleLoaded.synchrony? && Utils::ModuleLoaded.fiberpool? :em_synchrony else :net_http end end module ModuleLoaded def self.synchrony? defined?(EM::Synchrony) && EM.reactor_running? end def self.fiberpool? CfConsole::Application.config.middleware.middlewares.include?(Rack::FiberPool) end end我知道我可以在config / application.rb中启用FiberPool,但是如何启用EM.synchrony?
我是红宝石的新手,掌握了EM的基本知识,但我仍然不太清楚其含义:
defined?(EM::Synchrony) && EM.reactor_running?所以任何解释和样品都非常感谢。
I'm refactoring a ROR project which is using Faraday as request client and has predefined adapter to use with EM synchrony like this:
def which_faraday_adapter? if Utils::ModuleLoaded.synchrony? && Utils::ModuleLoaded.fiberpool? :em_synchrony else :net_http end end module ModuleLoaded def self.synchrony? defined?(EM::Synchrony) && EM.reactor_running? end def self.fiberpool? CfConsole::Application.config.middleware.middlewares.include?(Rack::FiberPool) end endI know I can enable FiberPool in my config/application.rb, but how can I enable EM.synchrony?
I'm new in ruby with basic knowledge of EM but I'm still not very clear about the meaning of:
defined?(EM::Synchrony) && EM.reactor_running?So any explanations and samples are really appreciated.
最满意答案
这很简单,只需取消注释application.rb中的这一行:
config.middleware.insert_before Rails::Rack::Logger, Rack::FiberPoolIt's easy, just uncomment this line in application.rb:
config.middleware.insert_before Rails::Rack::Logger, Rack::FiberPool更多推荐
发布评论