Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

separate fiber yielding and em-synchrony? #8

Closed
bmidgley opened this Issue · 3 comments

2 participants

@bmidgley

The last time I tried em-synchrony, it broke dns lookup with its monkeypatching.

Is it possible to get the fiber-yielding behavior of your pg client without any of the monkeypatching ugliness of em-synchrony?

@royaltm
Owner

Hmm... maybe I didn't state it clearly but EM-Synchrony is optional.

You may require 'em-synchrony/pg' and benefit from fiber-aware pg driver without the need of EM-Synchrony gem.

However without em-synchrony you must remember:

  1. to wrap EM.run with Fiber.new e.g.:

    require 'em-synchrony/pg'
    EM.run do
      Fiber.new do
        pg.query(...)
        ... your stuff goes here
      end.resume
    end
    
  2. you should also provide some kind of connection pool (you may borrow it from EM-Synchrony) for proper handling of fiber-concurrency.

see https://github.com/igrigorik/em-synchrony/blob/master/lib/em-synchrony/connection_pool.rb

My advice is to try the latest em-synchrony anyway, perhaps it's DNS issues have been resolved.

@bmidgley

Thanks for the response. I did see em-synchrony is optional but it's not clear what you end up with when not using it. em-synchrony is just too dramatic and risky for our project. I don't like that when it (silently) fails to patch something then you get different behavior from the same API calls.

We have rack fiber pool and we also create a fiber inside every em callback, so we're always running in a yieldable fiber.

Is there code that demonstrates patching active record to use yielding calls?

@royaltm
Owner

Yes, there is in one of those earlier em-postgres implementations: https://github.com/leftbee/em-postgresql-adapter/blob/master/lib/active_record/connection_adapters/em_postgresql_adapter.rb

I don't use ActiveRecord myself (IMO too much unnecessary layers, I use my own ORM).
Though it would be great If you happen to adapt leftbee/em-postgresql-adapter's ActiveRecord Patch to ruby-em-pg-client. If you would contribute of course :).
I'm aware ActiveRecord is popular these days, but I don't really have the time to develop something i'm not using.

@royaltm royaltm closed this
@royaltm royaltm referenced this issue in fl00r/em-pg-sequel
Merged

em-pg-client 0.3 update #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.