On Monday, August 27, 2012 1:28:34 PM UTC-7, Ravi wrote:
>
> I think increasing the number of max_connection solved the isseue. I did
> not see any more "Too many connections" errors since past three days.
>
Good.
> Few more question: When I open a connection to db, does the connection
> close automatically. How the connection is handled by Sequel and what is
> its scope?
>
The connection stays open until:
1) A disconnect is detected on it.
2) The connection is disconnected manually via Database#disconnect.
> eg:
> I have a following class dbConnect to connect to db:
>
> class dbConnect
> def initialize
> @db = Sequel.connect("myswl:...", :max_connection=>3,
> :pool_sleep_time=>0.01, :pool_timeout=>30)
> end
> def execute_query
> #perform some query here
> end
> end
> Can I define a function to close this particular (@db) connection or it
> will be handled by Sequel??
>
That's not a connection, that's a Database object (which has a pool of
connections). If you really want a separate Database object and connection
pool just to execute one query, you can pass a block to Sequel.connect:
Sequel.connect("myswl:...", :max_connection=>3, :pool_sleep_time=>0.01,
:pool_timeout=>30) do |db|
# ...
end
That's not generally a good idea, though.
>
> Now, in another file:
>
> def db_perform
> db = dbConnect.new
> db.exec_query
> end
> db_perform
>
> Scope of this connection? Does the db connection automatically close at
> the end of the above function (db_perform)?
>
No, connections will remain in the connection pool so that they can be used
by other threads. If you really want to control the scope of connections,
use the master branch, set :connection_handling=>:disconnect, and use
Database#synchronize to manually control the scope of each connection.
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/-/GJ2uijtUAEMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.