using ruby threads with delay
===

I have written a ruby script which contains the list of files(~250) to be downloaded. Since sequential download will take ages. I thought of downloading each file in a separate thread. Even though I have given the delay of 20, it looks like all the threads are hitting the server at a time. Hence I am getting 502 error and none of the files are downloaded. How can I download all the files parallelly without overloading the server.


    #list of fiiles
    files = []
    threads = []  
    files.each do |file|
       threads  << Thread.new(file){ | file |
         sleep(20)  
         #Download the file using either curb or Net::HTTP
         sleep(20)
    }
    end

    threads.each(&:join)