On Wednesday, March 26, 2014 8:15:23 PM UTC-7, Jeff wrote:
>
> I have a Rails app that makes connections to other DBs. There may be 
> multiple users connecting to multiple DBs.
>
> The app makes a database connection as part of an action.  However, I 
> noticed a problem: there's too many DB connections remaining open, which is 
> causing the DB to not have enough connections remaining for new 
> connections.  (psql: FATAL: remaining connection slots are reserved for 
> non-replication superuser connections)
>
> So I should manually call disconnect to disconnect connections. That's 
> fair enough.
>
> However, is there a better way, maybe some way to persist a DB connection 
> through the app unless it wasn't used in the last 5 minutes? Rather than 
> re-opening DB connections with each action and each user, it'd be more 
> efficient to keep the DB connection open and share it amongst users and 
> requests, but automatically disconnect if it hasn't been called in the last 
> few minutes.
>

There's nothing built in that does what you want.  You could do it with a 
custom connection pool subclass, or possibly an extension to the existing 
sharded threaded connection pool.  There's not really documentation beyond 
the method RDoc for this, so look at the connection pool source files if 
you are interested in doing that.

To connect to a database for the period of a single action, you can use the 
server_block and arbitrary_servers extensions in conjunction with a rack 
middleware (see 
https://groups.google.com/forum/#!topic/sequel-talk/HuNdQR1CHQI).  This 
automatically disconnects after the request ends, so you shouldn't have a 
problem with not having enough connections.  Unless connection setup time 
for the database makes this unacceptable, that is what I would recommended.
 

> In Python I think you can use pickling for this purpose. Maybe.
>

No, you can't pickle sockets in Python, and you can't marshal sockets in 
Ruby.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to