I need to implement a task in rails which ping huge number of hosts and check if its reachable or not. The result has to be displayed as fast as possible and number of hosts can scale up to some 10k or may be even more.

So far, I have tried to do using thread pool and its taking way long time.

```
      work_q = Queue.new
      @hosts.each{|x| work_q.push x }
      workers = (0...200).map do
           Thread.new do
                begin
                     while host = work_q.pop(true)
                          ping_count = 1
                          server = host.address
                          result = `ping -q -c #{ping_count} #{server}`
                          if ($?.exitstatus == 0) 
                               @res[host.hostname] =  "up"
                          else
                               @res[host.hostname] = "down"
                          end
                     end
                rescue ThreadError
                end
           end
      end;

```

I also tried to use sidekiq to implement it as async task. Here is the way I thought of implementing it.
1. Pass the host ip to the job queue in sidekiq and find the last job id/worker id 
2. Check the status of the last worker id and persist in some way.(not sure how to persist the worker id in better way)
3. Schedule a task to check the completion status of the last worker. Once the last worker is completed restart the sidekiq and ping the hosts all over again.
4. In this way you have the latest status of all hosts (up or down) based on ping result in min interval of time.
5. Whenever user clicks to check the status of hosts, show them the result and it will be latest one.

Can anybody help with any other idea, they can think of to do it in better way. 
Thanks for the help.