1

I have been using concurrent-ruby 1.1.5 with Rails 5.1.6 and MySQL 8.0. I have to make 500 DB calls, so I tried to make it using concurrent ruby but the results are extremely slow than expected

Normal Loop call - This takes on an average 7-8 seconds

[1..500].map do
  ## Db Call
end

After changing the code and using concurrent ruby, this time increases to 12-13 sec

thread_pool = Concurrent::FixedThreadPool.new(10)
promises = []
[1..500].map do
  Concurrent::Promises.future({ executor: thread_pool }) do
    Rails.application.executor.wrap do
      ActiveRecord::Base.connection_pool.with_connection do
        ## Db Call
      end
    end
  end
end

Not able to debug what could be the possible reason which is making the concurrent requests slow. Am I missing something?

0 Answers0