best_priority() can starve the worker threads of good relays
best_priority()
tries to measure unmeasured and failing relays first.
But if fraction_relays
or min_relays
always fail, those relays will always end up first in the priority queue. (More precisely, those relays will end up first in the priority queue, until the results of the good relays time out are discarded for being too old.)
Thinking about starvation is complicated, because of the freshness_reduction_factor
on some errors.
Here's a very simple algorithm that avoids starving good relays for failed relays:
- Count the number of times that sbws has attempted to get a result from each relay.
- Test the relays with the lowest number of attempts first. (Don't check if the attempt succeeded or failed.)
For this priority rule to work, every time a relay is queued, it must get a result. Here's how we can make that happen"
- Modify
result_putter_error()
to store an error result to the queue. - Make sure timeouts store an error result to the queue.
- Add a unit test and integration test that makes sure every queued relay has a result.
Here's an alternative that might be simpler to implement:
- before a relay is queued using
pool.apply_async()
inrun_speedtest()
, store aResultAttempt
to the queue - only count
ResultAttempt
s when prioritising relays