Add more comments to the scaler oracle
@@ -11,6 +11,11 @@ const PROVER_DISABLE_THRESHOLD: Duration = Duration::from_secs(5 * 60);
/// Scaler oracle provides information for prover scaler
/// service about required amount of provers for server
/// to operate optimally.
+///
+/// Important note: this oracle does not maintain it state in a separate
+/// thread, the state is updated upon request. For oracle to operate
+/// optimally, it is expected that `provers_required` method will be polled
+/// with a predictable (and not too big) intervals.
pub struct ScalerOracle {
/// Last moment in time when a block for proving was
/// available.
@@ -35,7 +40,17 @@ impl ScalerOracle {
}
}
+ /// Decides how many prover entities should be created depending on the amount of existing
+ /// entities and the amount of pending blocks.
pub fn provers_required(&mut self, working_provers_count: u32) -> Result<u32, failure::Error> {
+ // Currently the logic of this method is very simple:
+ // If we have no provers and there are no pending blocks, do not start the prover.
+ // If we have an active prover and it's been a while since we've had a block, stop the prover.
+ // Otherwise, require 1 prover to operate (either start or retain existing one).
+ //
+ // Later this algorithm will be improved to provide better scalability, but for now the
+ // simplest possible solution is preferred.
+
let storage = self.db.access_storage()?;
let jobs = storage.prover_schema().unstarted_jobs_count()?;
