File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,20 +56,21 @@ def configure_busy_handler_timeout
5656 return unless @config . key? ( :timeout )
5757
5858 timeout = self . class . type_cast_config_to_integer ( @config [ :timeout ] )
59+ timeout_seconds = timeout . fdiv ( 1000 )
60+ retry_interval = 6e-5 # 60 microseconds
61+
5962 @raw_connection . busy_handler do |count |
6063 timed_out = false
61- # capture the start time of this blocked write
62- @start_time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) if count == 0
6364 # keep track of elapsed time every 100 iterations (to lower load)
64- if count % 100 == 0
65- @elapsed_time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) - @start_time
65+ if ( count % 100 ) . zero?
6666 # fail if we exceed the timeout value (captured from the timeout config option, converted to seconds)
67- timed_out = @elapsed_time > timeout
67+ timed_out = ( count * retry_interval ) > timeout_seconds
6868 end
6969 if timed_out
7070 false # this will cause the BusyException to be raised
7171 else
72- sleep 0.001 # sleep 1 millisecond (or whatever)
72+ sleep ( retry_interval )
73+ true
7374 end
7475 end
7576 end
You can’t perform that action at this time.
0 commit comments