Forum: JRuby ActiveRecord 3.0, 3.2 thread safety and connection pool fairness

27598e1b77ce41fb0bd8a6fc4a3715d4?d=identicon&s=25 Patrick Mahoney (Guest)
on 2012-05-22 18:50
(Received via mailing list)
I've been trying to run a few non-Rails ActiveRecord apps in a Java
servlet
container in full multithreaded mode. I kept running into problems
under
moderate load, and I believe I've tracked down the causes.

I want to post this for posterity and ask if other JRuby users have
seen these
same problems. I am also seeking testing and comments on my patches, if
possible.

1) ActiveRecord has thread safety issues. I see this error in my logs
"Detected invalid hash contents due to unsynchronized modifications
with
concurrent users org/jruby/RubyHash.java:1356:in `keys'"

Fix accepted: https://github.com/rails/rails/pull/6398/files

2) ActiveRecord's connection pool is not "fair". My thread pool is
larger
than my database connection pool, and I regularly see timeouts
acquiring
database connections under only moderate load (where direct JDBC calls
for
a container-managed connection pool see no such timeouts).

Fix also accepted (though it somehow breaks tests of eager loading on
postgres),
but this is more complex and not so clean:
https://github.com/rails/rails/pull/6416

I'm a bit surprised/nervous if I am the first to encounter these
issues...

Thanks,

--
Patrick Mahoney
4bfcb18ca5298df54d8eb410244d004f?d=identicon&s=25 Uwe Kubosch (donv)
on 2012-05-23 15:56
(Received via mailing list)
On 2012-05-22, at 18:49, Patrick Mahoney wrote:

> 2) ActiveRecord's connection pool is not "fair". My thread pool is larger
> than my database connection pool, and I regularly see timeouts acquiring
> database connections under only moderate load (where direct JDBC calls for
> a container-managed connection pool see no such timeouts).

Last I looked at the AR DB connection pool, it never released
connections for active threads.  That means you MUST have at least as
many connections in your pool as you have active threads.  In a web app,
the threads are often short lived, and the connections they occupy are
released when the thread dies.  This is not the case for long-lived
threads in a non-web app.

--
Uwe Kubosch
http://jruby.org/
F76f3e46a94eb011d85d14bf54425950?d=identicon&s=25 Roger Gilliar (Guest)
on 2012-05-23 16:05
(Received via mailing list)
I had to manually remove the connections in a multithreaded Swing app.

ActiveRecord::Base.clear_active_connections!

Regards
  Roger

Am 23.05.2012 um 15:55 schrieb Uwe Kubosch:
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.