Too many connection

Hi,

I actually have a mysql error in my ruby script.
After several requests I have the “too many connections” error.
But I don’t why because I created a queue that runs 5 threads. Every
thread execute many mysql requests.
I limited the queue to 5 threads to not overload mysql. But it seems
that doesn’t work. Here is an example of my script.
I precise that I use activerecord.

threads = (1…5).map do |i|
Thread.new(QUEUE) do |q|
until ( q == (tab = q.deq))
functions_that_executes_many_mysql_requests
end
end
end

10.times do |t|
30.times do |s|
QUEUE.enq(des_parametres)
end
threads.size.times { QUEUE.enq QUEUE}
threads.each {|u| u.join}
end

I hope someone can help me

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs