Skip to content

Commit

Permalink
Update prover scaling formula
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Movchan committed Jun 8, 2020
1 parent 79be6aa commit 7a36ba3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
24 changes: 5 additions & 19 deletions core/server/src/prover_server/scaler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Built-in deps
use std::time::{Duration, Instant};
// Workspace deps
use models::config_options::parse_env;
use storage::ConnectionPool;

/// Disable the prover service after 5 minutes with no blocks to generate.
Expand Down Expand Up @@ -52,25 +53,10 @@ impl ScalerOracle {
// simplest possible solution is preferred.

let storage = self.db.access_storage()?;
let jobs = storage.prover_schema().unstarted_jobs_count()?;
let pending_jobs = storage.prover_schema().pending_jobs_count()?;
let idle_provers: u64 = parse_env("IDLE_PROVERS");
let provers_required = pending_jobs + idle_provers;

if jobs != 0 {
self.last_time_with_blocks = Instant::now();
}

if working_provers_count == 0 && jobs == 0 {
// No provers active, no jobs as well => no need to start one.
return Ok(0);
}

let provers_required = if self.last_time_with_blocks.elapsed() >= PROVER_DISABLE_THRESHOLD {
// Long time no blocks => shutdown prover.
0
} else {
// Either a new block has appeared or not so long without blocks => start/retain prover.
1
};

Ok(provers_required)
Ok(provers_required as u32)
}
}
9 changes: 9 additions & 0 deletions core/storage/src/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ impl<'a> ProverSchema<'a> {
})
}

pub fn pending_jobs_count(&self) -> QueryResult<u64> {
self.0.conn().transaction(|| {
let last_committed_block = BlockSchema(&self.0).get_last_committed_block()? as u64;
let last_verified_block = BlockSchema(&self.0).get_last_verified_block()? as u64;

Ok(last_committed_block - last_verified_block)
})
}

/// Given the block size, chooses the next block to prove for the certain prover.
/// Returns `None` if either there are no blocks of given size to prove, or
/// there is already an ongoing job for non-proved block.
Expand Down
2 changes: 2 additions & 0 deletions etc/env/dev.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ PROVER_SERVER_URL=http://0.0.0.0:8088
PROVER_SERVER_BIND=0.0.0.0:8088
# Prover container kubernetes resources.(adjust according to BLOCK_CHUNK_SIZES selected)
PROVER_MIN_RESOURCES="{\"requests\": {\"cpu\": 1, \"memory\": \"6Gi\"}}"
# Number of idle provers running (to scale up faster)
IDLE_PROVERS=1

SERVER_API_HOST=localhost
SERVER_API_HOST_CERT=""
Expand Down

0 comments on commit 7a36ba3

Please sign in to comment.