# Too many connection

**URL:** <https://www.ruby-forum.com/t/too-many-connection/182074>\
**Category:** Rails\
**Created:** [January 22, 2010, 10:26am UTC](https://www.ruby-forum.com/t/too-many-connection/182074 "2010-01-22T10:26:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lune9](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e79b87/32.png) [@lune9](https://www.ruby-forum.com/u/lune9)\
**Post date:** [January 22, 2010, 10:26am UTC](https://www.ruby-forum.com/t/too-many-connection/182074/1 "2010-01-22T10:26:21Z")

</div>

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
