[LRUG] Puma, CLOSE_WAIT. Arg.
Jason Lee
jlsync at gmail.com
Thu Feb 18 09:35:00 PST 2016
A long time ago I was using heroku, MRI, puma, and ActionController::Live.
Exceptions would cause database connections to leak, this was a problem for
me because the heroku free tier only gives you 20 database connections and
I was using a db connection on every streaming request in order to use
postresql's listen/notify feature ( instead of using, say, redis pub/sub).
This code https://gist.github.com/jlsync/ea499fa90a9abfe04fa9 manages
database connections by using
ActiveRecord::Base.connection_pool.checkout
to get a connection and then a ruby "ensure" block at the end to "checkin"
the connection back to the pool.
The code also uses
Thread.list.count
to monitor the active ruby/puma thread count, and also
ActiveRecord::Base.connection_pool.size
ActiveRecord::Base.connection_pool.connections.size
to monitor database connections.
You can see these monitoring counts being logged directly to the UI here
https://jlquiz.herokuapp.com/ (after logging in).
my puma config included
on_worker_boot do
# worker specific setup
ActiveSupport.on_load(:active_record) do
ActiveRecord::Base.establish_connection
end
end
Using some of these ideas might help you.
Jason.
On Thu, Feb 18, 2016 at 4:01 PM, Simon Morley <simon at polkaspots.com> wrote:
> As an interim update, adding the recommended
> ActiveRecord::Base.connection_pool.disconnect! doesn't seem to help :(
>
> We're seeing far fewer timeouts but they're still happening on that db
> connection. And when they happen, it's carnage for 15s.
>
>
>
> Simon Morley
>
> Big Chief | PolkaSpots Supafly Wi-Fi
> Bigger Chief | Cucumber Tony
>
> Got an unlicensed Meraki? Set it free with Cucumber
> cucumberwifi.io/meraki
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20160218/b9ff82f9/attachment-0002.html>
More information about the Chat
mailing list