Skip to content

Commit

Permalink
Update Rails isolation_level docs with new learnings (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorturk authored Feb 2, 2024
1 parent c9b36dd commit 4002aea
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions guides/rails-integration/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Because `rails` apps are built on top of `rack`, they are compatible with `falco

## Isolation Level

Rails 7.1 introduced the ability to change its internal isolation level from threads (default) to fibers. When you use `falcon` with Rails, it will automatically set the isolation level to fibers to improve performance.
Rails 7.1 introduced the ability to change its internal isolation level from threads (default) to fibers. When you use `falcon` with Rails, it will automatically set the isolation level to fibers.

Beware that this change may increase the utilization of shared resources such as Active Record's connection pool, since you'll likely be running many more fibers than threads. In the future, Rails is likely to adjust connection pool handling so this shouldn't be an issue in practice.
Beware that changing the isolation level may increase the utilization of shared resources such as Active Record's connection pool, since you'll likely be running many more fibers than threads. In the future, Rails is likely to adjust connection pool handling so this shouldn't be an issue in practice.

To mitigate the issue in the meantime, you can wrap Active Record calls in a `with_connection` block so they're released at the end of the block, as opposed to the default behavior where Rails keeps the connection checked out until its finished returning the response:

Expand All @@ -23,7 +23,7 @@ ActiveRecord::Base.connection_pool.with_connection do
end
~~~

Or to simply retain the default Rails behavior, add the following to `config/application.rb` to reset the isolation level to threads:
Alternatively, to retain the default Rails behavior, you can add the following to `config/application.rb` to reset the isolation level to threads, but beware that sharing connections between fibers may result in unexpected errors within Active Record and is not recommended:

~~~ ruby
config.active_support.isolation_level = :thread
Expand Down

0 comments on commit 4002aea

Please sign in to comment.