This project is archived and is in readonly mode.
Tweaks to make ActiveRecord Fiber-friendly
-
Jeremy Kemper
- Milestone cleared.
- State changed from new to open
- Assigned user set to Jeremy Kemper
Cool - thanks for working on this, Mike!
Looks like the pool implementation itself could be configurable so you could pick a threaded or fibered variant.
Patches (and tests) welcome, of course :)
-
Mike Perham
Any suggestions on the switching logic? I like the idea of config.fibersafe! which works in a similar fashion to config.threadsafe! It would be able to rejigger the Rails stack (AR, memcache-client, e.g.) to use Fiber-safe versions.
-
Mike Perham
- Tag set to patch
Patch attached. I'm unhappy with a few areas that perhaps you can suggest alternatives:
- How do we cleanly get the concurrency_model value from the
Rails::Application instance down to the ConnectionPool? My defined?
code is definitely a hack.
- I had to pull in EventMachine into the Gemfile in order to test
the Fibers actually executing. The wait queue uses EM to pause
while waiting for a connection and I'm not sure we want to
introduce that dependency into ActiveRecord, even if it's pulled in
dynamically.
- There's no real way to implement remove_stale_cached_threads! since we can't get a list of Fibers in the system. I hacked it in em_postgresql by registering the application's FiberPool manually. I don't know if this is a showstopper but it's a concern.
-
Dan Pickett
- Tag changed from patch to bugmash, patch
Advanced bugmashin': Can some bugmashers critique the patch and revise/comment as necessary?
-
wtn
+1
Hope to see this patch get accepted.
-
José Valim
- Assigned user changed from Jeremy Kemper to Aaron Patterson
-
Aaron Patterson
- Milestone set to 3.1
I will attempt to test / fix this. I don't like the architecture of the patch. I think we should have two subclasses of connection pool (one for threads and one for fibers) then switch the instantiation logic. Having initialize extend the current instance seems not good.
We can have the spec contain configuration info. IIRC, the spec comes from the database configuration yaml file, so config could be something like:
development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 concurrency: fiber(I'm not sure this is exactly what the config file would look like)
I'm marking this for Rails 3.1 as this seems like too much for a bugfix release.
