Ruby sleep in API requests getting dropped -


whenever add sleep api request in rails application , send many @ once threads, ends skipping responses. ill show example

i have api looks this

module api  module v1   class ping < grape::api    include api::v1::defaults      resource :ping      desc 'execute ping'      params     end      post       if params['delay'].present?         delay = params['delay'].to_f         status 200         sleep delay         return {response: 'pong', delay: delay}       else          return {response: 'pong'}       end     end   end  end end end 

now if open 2 other servers , run api threads @ same time, if send without delay works, if send delay randomly lose responses

array=[]  # without delay 1000.times{thread.new{ a=restclient.post "http://172.18.139.39:3000/api/v1/ping", { } ; array.push(a) } }   # delay 1000.times{thread.new{ a=restclient.post "http://172.18.139.39:3000/api/v1/ping", { delay: 5 } ; array.push(a) } } 

i push responses without delay array.length 1000 , delay somewhere between 500-800.

what can done allow sleep in api request when threading?


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -