Class: THTP::Server::Middleware::ActiveRecordPool
- Inherits:
-
Object
- Object
- THTP::Server::Middleware::ActiveRecordPool
- Defined in:
- lib/thtp/server/middleware.rb
Overview
Performs explicit rather than implicit AR connection management to ensure we don’t run out of SQL connections. Note that this approach is suboptimal from a contention standpoint (better to check out once per thread), but that sync time should be irrelevant if we size our pool correctly, which we do. It is also suboptimal if we have any handler methods that do not hit the database at all, but that’s unlikely.
For more details, check out (get it?): bibwild.wordpress.com/2014/07/17/activerecord-concurrency-in-rails4-avoid-leaked-connections/
This is probably only useful on servers.
Instance Method Summary collapse
- #call(rpc, *rpc_args_and_opts) ⇒ Object
-
#initialize(app) ⇒ ActiveRecordPool
constructor
A new instance of ActiveRecordPool.
Constructor Details
#initialize(app) ⇒ ActiveRecordPool
Returns a new instance of ActiveRecordPool.
38 39 40 41 |
# File 'lib/thtp/server/middleware.rb', line 38 def initialize(app) require 'active_record' # if you don't have it, why do you want this? @app = app end |
Instance Method Details
#call(rpc, *rpc_args_and_opts) ⇒ Object
43 44 45 |
# File 'lib/thtp/server/middleware.rb', line 43 def call(rpc, *rpc_args_and_opts) ActiveRecord::Base.connection_pool.with_connection { @app.call(rpc, *rpc_args_and_opts) } end |