0

I have initialized 250 threads at a time and they are returning back to update some data in the database. I am using Postgresql database in my rails 2 application. I have set Pool size 100 and max connections 100 but the problem is after 100 connections remaining threads are causing problem like "FATAL ERROR: Too many clients". So now i want is as soon as any thread complete its process then kill that thread. SO to achieve this what should i do?

Here is my code:

consider detail = "contains 250 items in an array"
 threads = []
      detail.each do |item|
          threads << Thread.new( item) do | item |
           # block of code
          end
      end
   threads.each { | t | t.join } 

1 Answer 1

0

I hope you are using Rails 2.2 where connection pooling has been implemented. Check this:

http://guides.rubyonrails.org/2_2_release_notes.html#connection-pooling

and this http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html

1
  • I have used the same approach but still getting same error. Please suggest how to i handle maximum connections using threading?
    – Trupti
    Feb 7, 2013 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.