Discussion:
DB connection pool vs. max (concurrent) connections
Steven McPhillips
2012-11-12 02:43:13 UTC
Permalink
Hi,

I have an interesting issue with one of my Ruby+Sequel web apps. The app is
very infrequently used, and the (MySQL) dba employs fairly aggressive
connection pruning. This means that connections in Sequel's db pool are
almost always invalidated when a request comes through (because MySQL has
disconnected them). My immediate thought was to reduce the max_connections
option (Sequel.connect) to 1, but I have a feeling (confirmed?<https://groups.google.com/d/topic/sequel-talk/yb_u0uDiCDk/discussion> I've
been lazy and not tested for myself) doing so would mean the app would only
have 1 active db connection.

So my question: can I configure Sequel to not pool connections, but still
ensure each request can access a (freshly minted as required) db
connection, perhaps with an upper limit on maximum active connections? Am I
just getting confused between db.max_connections vs db.pool.max_connections?

I'm running Sequel v3.41.0.
Sequel.connect(jdbc:mysql://localhost:3306/stats?user=test&zeroDateTimeBehavior=convertToNull, :max_connections
=> 10)
Using the db connection is achieved by yielding it, and
catching Sequel::DatabaseDisconnectError to automatically retry (somewhat
5.times do
begin
rescue Sequel::DatabaseDisconnectError => e
Log.info("Connecting to the database failed. Retrying...")
sleep(2)

end
end
--
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/xRGys-4-uRQJ.
To post to this group, send email to sequel-talk-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to sequel-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
Jeremy Evans
2012-11-12 02:47:53 UTC
Permalink
Post by Steven McPhillips
Hi,
I have an interesting issue with one of my Ruby+Sequel web apps. The app
is very infrequently used, and the (MySQL) dba employs fairly aggressive
connection pruning. This means that connections in Sequel's db pool are
almost always invalidated when a request comes through (because MySQL has
disconnected them). My immediate thought was to reduce the max_connections
option (Sequel.connect) to 1, but I have a feeling (confirmed?<https://groups.google.com/d/topic/sequel-talk/yb_u0uDiCDk/discussion> I've
been lazy and not tested for myself) doing so would mean the app would only
have 1 active db connection.
So my question: can I configure Sequel to not pool connections, but still
ensure each request can access a (freshly minted as required) db
connection, perhaps with an upper limit on maximum active connections? Am I
just getting confused between db.max_connections vs db.pool.max_connections?
You probably should use the connection_validator extension that ships with
Sequel 3.41.0
(http://sequel.rubyforge.org/rdoc-plugins/files/lib/sequel/extensions/connection_validator_rb.html).

Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/lw3XXhZaVsMJ.
To post to this group, send email to sequel-talk-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to sequel-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
Steven McPhillips
2012-11-12 04:20:55 UTC
Permalink
Post by Jeremy Evans
You probably should use the connection_validator extension that ships with
Sequel 3.41.0 (
http://sequel.rubyforge.org/rdoc-plugins/files/lib/sequel/extensions/connection_validator_rb.html
).
Many thanks! Will check the changelog before posting in future :)
--
You received this message because you are subscribed to the Google Groups "sequel-talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/QoJlOrlGlNQJ.
To post to this group, send email to sequel-talk-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to sequel-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
Loading...