我有一个ruby脚本,它连接到远程服务器上的mongo db并执行find_by查询。有时执行时间不到1秒,有时需要大约15分钟才能执行。这可能是造成这种行为的原因吗?
script.rb
select cheffname
from speciality
where speciality in ('Chinese Cuisine', 'Japanese Cuisine')
group by cheffname
having count(*) = 2;
publisher_models.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