|
2 | 2 |
|
3 | 3 | This guide explains how to host Rails applications with Falcon. |
4 | 4 |
|
| 5 | +**We strongly recommend using the latest stable release of Rails with Falcon.** The integration is much smoother and you will benefit from the latest features and bug fixes. This guide is primarily intended for users of Rails 8.0 and later. |
| 6 | + |
5 | 7 | ## Integration with Rails |
6 | 8 |
|
7 | 9 | Because Rails apps are built on top of Rack, they are compatible with Falcon. |
@@ -54,24 +56,12 @@ require_relative "config/environment" |
54 | 56 |
|
55 | 57 | ## Isolation Level |
56 | 58 |
|
57 | | -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. |
58 | | - |
59 | | -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. |
60 | | - |
61 | | -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: |
| 59 | +Rails provides 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. |
62 | 60 |
|
63 | | -~~~ ruby |
64 | | -ActiveRecord::Base.connection_pool.with_connection do |
65 | | - Example.find(1) |
66 | | -end |
67 | | -~~~ |
68 | | - |
69 | | -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: |
| 61 | +## ActionCable |
70 | 62 |
|
71 | | -~~~ ruby |
72 | | -config.active_support.isolation_level = :thread |
73 | | -~~~ |
| 63 | +Falcon fully supports ActionCable with the [`Async::Cable` adapter](https://github.com/socketry/async-cable). |
74 | 64 |
|
75 | | -## ActionCable |
| 65 | +## ActiveJob |
76 | 66 |
|
77 | | -Falcon supports `rack.hijack` and is compatible with ActionCable. If you use the `async` adapter, you should run Falcon in threaded mode, or in forked mode with `--count 1`. Otherwise, your messaging system will be distributed over several processes with no IPC mechanism. You might like to try out [async-redis](https://github.com/socketry/async-redis) as an asynchronous message bus. |
| 67 | +Falcon fully supports ActiveJob with the [`Async::Job` adapter](https://github.com/socketry/async-job-adapter-active_job). |
0 commit comments