On Wednesday, August 29, 2012 10:51:26 AM UTC-7, rv wrote:
>
> On Tuesday, August 28, 2012 6:58:53 PM UTC-7, Jeremy Evans wrote:
>>
>> On Tuesday, August 28, 2012 5:13:33 PM UTC-7, Ravi wrote:
>>>
>>> Increasing max_connection also not working. I ran the application 50-60 
>>> times in few span of seconds (at each call it creates 3-4 databse objects) 
>>> and now it is giving me same error. "Too many connections"
>>
>>
>> Is there a reason that you are running 50-60 copies of the application, 
>> and creating 3-4 Database objects in each one?  That sounds like a very 
>> poor design to me.
>>
> Yes, this is the requirement. There can be multiple users 
> accessing/running this program. Just out of curious, what is the drawback 
> of creating more than one db object say 2 or 3?
>

Each Database object you create has a separate connection pool.  Since you 
are using single threaded mode, if you create 2 or 3 Database objects to 
connect to the same database, you will have 2 or 3 connections to the 
database per process.  If you have a single Database object, you will only 
have 1 connection to the database per process.  So having a single Database 
object instead of 2 or 3 will double or triple the number of processes you 
can run before you hit your database connection limit.
 

>  
>>
>>> I think I need to close/disconnect the DB for each thread I have in the 
>>> app.
>>>
>>
>> You should fix your design instead of attempting to do this.  If you 
>> really want to do this, I've already mentioned how in earlier messages.
>>
> Agree. I have fixed the design keeping in mind what we discussed. Also, I 
> designed the program thinking that the db will disconnect all connections 
> when the program exits or ends. but I think the connections are always 
> there only the DB object is destroyed.
>

Any sane OS should automatically close the database connection sockets when 
the process exits.  There are cases where the database will think a 
connection is open when it is actually closed (packet loss can cause that), 
but it's not that common in LAN environments.

Note that you say you are using single threaded mode, but above you say you 
want to "close/disconnect the DB for each thread I have in the app".  Are 
you using multiple threads in your app or not?
 

>  
>>
>>> Also, is there a way externally I can check the number of connections to 
>>> the database or close all connections (out of app)?
>>>
>>
>> DB.pool.size gives you the current size of the pool.  You would need to 
>> make your application offer some way for users to call Database#disconnect 
>> inside the app (signals, web api, etc.).  Not that you should actually do 
>> this, as it's a bad idea.
>>
>
> DB.pool.size give me the pool size in current instance of program but 
> since I am unable to connect to database now(Too many connections) I was 
> searching a way I can handle/monitor all  open connections (after the 
> program exits). 
>

If you want to monitor all open connections to the database, you need a 
database tool that lets you do that.  I'm assuming most databases provide 
such a tool.  It doesn't make sense to query individual programs to ask for 
the number of connections they have open, you want to handle this at the 
database level.
 

>
>> Fix your design:
>>
>> 1) Unless you need to connect to arbitrary databases based on runtime 
>> input, assign your Database object to a constant on app initialization. 
>>  You should generally not create Database objects at runtime in most cases. 
>>  If you are doing this without a good reason, your design needs to be 
>> fixed.  Based on the code you have posted so far, I don't see a good reason 
>> for you to create Database objects at runtime.
>>
>
> I am creating the DB object once only when starting the app/program (may 
> be at run time). but what if the program run multiple times, the DB object 
> is destroyed at the end of program?
> How can I initialize the program or create Database object once before 
> running the app/program ie, not at runtime.   
>

Your question is either phrased wrong (hopefully this) or indicates a 
complete lack of understanding of the basics of how operating systems run 
programs.  The only way I can think to answer it is that if you want to 
have a single Database object that all of your applications talk to, you 
need to create a separate program that connects to the database (usually 
called a server program), and have the clients connect to that program.  
This is probably the most common architecture for applications that deal 
with databases.  You appear to have clients programs that connect directly 
to the database.  While that is certainly a valid way to do things if 
appropriate security measures are in place, it's not a common design for 
new applications. Using a separate server program allows for much greater 
control over how many connections are made to the database, so with that 
approach it would be very unlikely that you would exceed the connection 
limit for your database.

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/-/YfmEhEtjanAJ.
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.

Reply via email to