-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Playing around with this concept myself, I'd like to suggest the following implementation:
def xfetch_early?(ttl:, compute_time:, beta: 1.0)
Kernel.rand < Math::E ** -(ttl.to_f / compute_time / beta)
end
def original_xfetch_api(expiry, delta:, beta: 1.0)
# original: Time.now - (delta * beta * Math.log(rand)) >= expiry
xfetch_early?(expiry - Time.now, compute_time: delta, beta: beta)
end- implement using the algorithm's inverse, which is more declarative.
- the instant probability over
ttl, e.g.e^(-ttl/5.0)becomes easy to graph and understand xfetch_early?is static/pure, having no dependency onTime- it's time-unit agnostic, use secs, msecs, minutes, etc for
ttlandcompute_time
Metadata
Metadata
Assignees
Labels
No labels