У меня есть скрипт ruby, который подключается к базе данных mongo на удаленном сервере и выполняет запрос find_by. Иногда выполнение занимает менее 1 секунды, тогда как иногда для выполнения требуется около 15 минут. Что может быть причиной такого поведения?
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