How to enable high performance http client which is based on faraday and event machine synchrony?

StackOverflow https://stackoverflow.com/questions/14434861

سؤال

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.

هل كانت مفيدة؟

المحلول

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

config.middleware.insert_before Rails::Rack::Logger, Rack::FiberPool
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top