如何启用基于法拉第和事件机同步的高性能http客户端?(How to enable high performance http client which is based on faraday and

编程入门 行业动态 更新时间:2024-10-26 04:31:39
如何启用基于法拉第和事件机同步的高性能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 end

I 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::FiberPool

It's easy, just uncomment this line in application.rb:

config.middleware.insert_before Rails::Rack::Logger, Rack::FiberPool

更多推荐

本文发布于:2023-07-30 22:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340306.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:法拉第   高性能   客户端   事件   enable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!