2

I have a ruby script which is connecting to a mongo db on remote server and does find_by query. Sometimes the execution takes less than 1 second where as sometimes it takes around 15mins to execute.What could be the reason for this behavior?

script.rb

    require '/home/ubuntu/praneetha/check_mongo/publisher_models.rb'
$stdout.sync = true

begin
   count = 1
    user_id = '53ce011f9937d923a4000001'
    while(true)
     puts "count: #{count}"
      t1 = Time.now.utc
      puts "Time.now is ========= #{t1}"
      p = Puser.find_by(:puid => user_id)
      puts "puser is  ====#{p.class}"
      t2 = Time.now.utc
       t3 = t2-t1
      puts "time taken =====> #{t3}"
      if t3>2
        puts "I have an error at time #{t1} and total time is #{t3} "
      end

     count = count + 1
     sleep(300)
     end

end

publisher_models.rb

 require 'mongoid'
require 'em-synchrony'

class Puser
  include Mongoid::Document
  field :email, type: String
  #custom user id for the user. This should be indexed at the time of creation
  field :puid, type: String

end
Praneetha
  • 303
  • 4
  • 17

0 Answers0