From 3bfaff8766ad4a78b51293492fcf9d6e9af46100 Mon Sep 17 00:00:00 2001 From: Trevor Turk Date: Fri, 2 Feb 2024 16:24:07 -0600 Subject: [PATCH] Update Rails isolation_level docs with new learnings --- guides/rails-integration/readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guides/rails-integration/readme.md b/guides/rails-integration/readme.md index 9fdaf99f..37aaf682 100644 --- a/guides/rails-integration/readme.md +++ b/guides/rails-integration/readme.md @@ -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: @@ -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