internetarchive / internetarchive/xfetch
Alternative Algorithm Implementation
- Dominant language
- PHP
- Stars
- 19
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
Playing around with this concept myself, I'd like to suggest the following implementation:
```ruby
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
```
1. implement using the algorithm's inverse, which is more declarative.
2. the instant probability over `ttl`, e.g. [`e^(-ttl/5.0)` becomes easy to graph and understand](https://www.google.com/search?q=y=e^(-x/5))
3. `xfetch_early?` is static/pure, having no dependency on `Time`
4. it's time-unit agnostic, use secs, msecs, minutes, etc for `ttl` and `compute_time`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.