3

I have a requirement to do polling that gradually gets slower over time. Is there a mathematical formula that is common to use in such a scenario?

For example I might want to poll 10 seconds after the first try and then gradually get slower to around every 1-5 minutes.

Joel Cunningham
  • 13,620
  • 8
  • 43
  • 49
  • It would be nice to define a "slowdown factor". Say its value is "0.8" then you would poll at 10, 8, 6.4 etc. Or you could use a constant subtraction and poll at 10, 9, 8 etc. It really depends on what you want to do. Be careful with floating point arithmetic. – Miserable Variable Feb 15 '14 at 07:09

1 Answers1

0

I think geometric serieses are common choices. This is how 10 * 1.2**N looks like:

irb(main):009:0> (0..20).map{|i| 10 * 1.2**i }
=> [10.0, 12.0, 14.399999999999999, 17.279999999999998, 20.735999999999997, 24.883199999999995,
29.85983999999999, 35.831807999999995, 42.99816959999998, 51.597803519999985, 61.917364223999975,
74.30083706879996, 89.16100448255996, 106.99320537907195, 128.39184645488632, 154.0702157458636,
184.8842588950363, 221.86111067404354, 266.23333280885225, 319.4799993706227, 383.3759992447472]

You may also want to check the cumulative time until declaring "timeout".

irb(main):010:0> (0..20).map{|i| 10 * 1.2**i }.inject(:+)
=> 2250.255995468484

FYI, Linux TCP SYN retry employs more aggressive slowdown factor 3 * 2**N

irb(main):011:0> (0..5).map{|i| 3 * 2**i }
=> [3, 6, 12, 24, 48, 96]
irb(main):012:0> (0..5).map{|i| 3 * 2**i }.inject(:+)
=> 189
nodakai
  • 7,773
  • 3
  • 30
  • 60