Friday, November 11, 2016

This Week in Rails: connection statistics, query caching fixes and more!

Posted by vipulnsward

Hello everyone!

And welcome to our special edition from, live from RubyConf in Cincinnati 😎.

This is Vipul along with Tim and Prathamesh teaming together to bring you all the latest news from the Rails community.  Lets get started!

Rails Contributors

This week 20 people contributed to Rails. We also got 3 first time contributors. Thanks all for your amazing contributions ❤️

If you too are looking to help out, head over to our issues.

Improved

Active Record connection pool adds a stat method

ActiveRecord::Base.connection_pool now has a stat method that returns statistics about the current status of a connection pool. For Example:

>> ActiveRecord::Base.connection_pool.stat
=> { max: 25, total: 1, busy: 1, dead: 0, idle: 0, num_waiting: 0, checkout_timeout: 5 }

Avoid unscope(:order) when limit is passed for a count query

If a limit is passed, record fetching order is very important for performance.

This fix makes changes so that we don’t unscope and remove the order from a count query when a limit clause is passed to it.

JRuby dependencies are now resolved for the latest version

As part of the ongoing effort of making Rails 5 compatible with JRuby, the test suite got updates for the JRuby version it runs on, to make it satisfy the dependencies required for the tests.

Fixed

Clear query cache during checkin, instead of an execution callback

Previously ActiveRecord::QueryCache using the new Rails executor may result in dirty query caches across threads. 

Releasing a connection in one thread may return it to the pool with cache still enabled and dirty, and the executor lost track of the connection so it may clear another, and another thread may pick up the dirty cache and never turn it off.

This fix makes changes so that query cache does not persist while a connection moves through the pool and is assigned to a new thread.

Configure query caching (per thread) on the connection pool

If the result of ActiveRecord::Base.connection is different across different threads, enabling the query cache in one thread will have been leaked, which could change the state of another.

This addresses the issue by making query caching local to the current thread.

One More Thing ™

Bona fide system testing in Rails 5.1

From DHH on Twitter:

The work being done is soon to be bundled into a new gem inside of Rails, that will hopefully be part of Rails 5.1!

Wrapping up

That’s it from This Week in Rails! There were many other great contributions, too numerous to list here, but feel free to check them out!

Until next week!