Skip to content

Commit

Permalink
Switch default connection pool to timed_queue on Ruby 3.2+
Browse files Browse the repository at this point in the history
The timed_queue connection pool was already the default on Ruby
3.4+.  However, recent discussions have shown that it is much
better than the threaded connection pool, at least in cases where
a sampling profiler is used.

This should be a drop-in replacement for most applications. However,
the timed_queue connection pool does not support the
available_connections and allocated accessors that the threaded
connection pool supports.  Those accessors are planned for removal
in Sequel 6, but are not formally deprecated yet.  Applications
that are using those accessors should either stop, or specify
pool_class: :threaded to continue using the threaded connection
pool.
  • Loading branch information
jeremyevans committed Sep 5, 2024
1 parent 75ac94c commit 8268b44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
=== master

* Switch default connection pool to timed_queue on Ruby 3.2+ (jeremyevans)

=== 5.84.0 (2024-09-01)

* Support creating VIRTUAL tables on SQLite via the create_table :using option (jeremyevans)
Expand Down
4 changes: 2 additions & 2 deletions lib/sequel/connection_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def connection_pool_class(opts)
else
pc = if opts[:single_threaded]
opts[:servers] ? :sharded_single : :single
# :nocov:
elsif RUBY_VERSION >= '3.4' # SEQUEL6 or maybe earlier switch to 3.2
elsif RUBY_VERSION >= '3.2'
opts[:servers] ? :sharded_timed_queue : :timed_queue
# :nocov:
else
opts[:servers] ? :sharded_threaded : :threaded
end
# :nocov:

connection_pool_class(:pool_class=>pc)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/core/connection_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1271,12 +1271,12 @@ def @pool.acquire(_,_=nil) raise Sequel::DatabaseDisconnectError; end
Sequel::ConnectionPool.send(:get_pool, db, :single_threaded=>true, :servers=>{}).pool_type.must_equal :sharded_single
end

it "should default to :single without :single_threaded or :servers" do
Sequel::ConnectionPool.send(:get_pool, db, {}).pool_type.must_equal(RUBY_VERSION >= '3.4' ? :timed_queue : :threaded)
it "should default to :timed_queue/:threaded without :single_threaded or :servers" do
Sequel::ConnectionPool.send(:get_pool, db, {}).pool_type.must_equal(RUBY_VERSION >= '3.2' ? :timed_queue : :threaded)
end

it "should default to :single without :single_threaded with :servers" do
Sequel::ConnectionPool.send(:get_pool, db, :servers=>{}).pool_type.must_equal(RUBY_VERSION >= '3.4' ? :sharded_timed_queue : :sharded_threaded)
it "should default to :sharded_timed_queue/:sharded_threaded without :single_threaded with :servers" do
Sequel::ConnectionPool.send(:get_pool, db, :servers=>{}).pool_type.must_equal(RUBY_VERSION >= '3.2' ? :sharded_timed_queue : :sharded_threaded)
end
end unless ENV['SEQUEL_DEFAULT_CONNECTION_POOL']

Expand Down

0 comments on commit 8268b44

Please sign in to comment.