Thank Jeremy for the reply. See below.

On Thursday, August 23, 2012 5:38:01 PM UTC-7, Jeremy Evans wrote:
>
> On Thursday, August 23, 2012 3:34:57 PM UTC-7, Ravi wrote:
>>
>> I have written a multi threaded code to update db.Number of threads may 
>> range from 45-50 or even more.
>>
>> Getting following error Mysql::Error: Too many connections 
>> (Sequel::DatabaseConnectionError)
>>
>
> That's a error raised by the database server telling you you have too many 
> connections to the server. That's not necessarily all connections from 
> Sequel, it includes any other connections to the database (mysql command 
> line program, a graphical mysql client, etc.).
>
>
The database is only connected through this code. No one else is accessing 
it.  That is good thing to know, I will check the configuration and try to 
increase number of connection if possible.

You can't change the number of allowed connections from Sequel, you need to 
> change your MySQL database configuration to increase the number of 
> connections.  The only work around in Sequel is lowering the number of 
> connections that Sequel will create (like you saw, the default is 4).  You 
> mentioned raising the number from 4 to 30, which could be causing your 
> problem.  Do you get the same error message when running with the default 
> of 4 connections?
>

I got same error before (2-3 times) with default :max_connection settings 
so I have increased the :max_connections variable to 30 and that worsen the 
problem. 
Since there are more than 50 instances/thread that update the database at 
same time and if I lower :max_connections; wont the Sequal will throw 
Sequel::PoolTimeout error.. if it could not connect to all 50 instances.
The other workaround I was thinking as following

attempt = 1
begin
  DB = Sequel.connect(....)
rescue Sequel::DatabaseConnectionError
  if attempt<6
    DB.disconnect  #it will serve all open connections first
    sleep(attempt*2)
    attempt +=1
    retry
  else
    raise_error("reached max attempts")
  end
rescue => e
 raise_error(...)
end  

Also can the other variables ( :pool_sleep_time=>0.01, :pool_timeout=>30) 
do this work for me?

>
> Note that you can have a connection pool with 4 connections serve 50 
> threads, as long as each thread on average accesses the database 8% of the 
> time. 
>
What error will Sequel raise if it crosses the above criteria? 


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