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
on 2012-05-22 18:50
on 2012-05-23 15:56
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/
on 2012-05-23 16:05
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
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.