Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add set-get concurrency level cmd (#3965)
* fix version num

* update set concurrency level and get concurrency level

* update nextest.sh

* revert nextest.sh

* update nextest.sh

* update nextest.sh

* update nextest.sh

* update nextest.sh

* update barnard fork version test

* update barnard fork version test
  • Loading branch information
nkysg committed Sep 26, 2023
1 parent 7698f19 commit 2436a7a
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 33 additions & 6 deletions cmd/starcoin/src/dev/concurrency_level_cmd.rs
Expand Up @@ -11,21 +11,24 @@ use starcoin_logger::prelude::*;

/// concurrency_level command option
#[derive(Debug, Parser)]
#[clap(name = "concurrency_level")]
pub struct ConcurrencyLevelCommandOpt {
#[clap(name = "set_concurrency_level")]
pub struct SetConcurrencyLevelCommandOpt {
#[clap(name = "level", help = "set vm concurrency_level")]
level: usize,
}

pub struct ConcurrencyLevelCommand;
pub struct SetConcurrencyLevelCommand;

impl CommandAction for ConcurrencyLevelCommand {
impl CommandAction for SetConcurrencyLevelCommand {
type State = CliState;
type GlobalOpt = StarcoinOpt;
type Opt = ConcurrencyLevelCommandOpt;
type Opt = SetConcurrencyLevelCommandOpt;
type ReturnItem = String;

fn run(&self, ctx: &ExecContext<Self::State, Self::GlobalOpt, Self::Opt>) -> Result<String> {
fn run(
&self,
ctx: &ExecContext<Self::State, Self::GlobalOpt, Self::Opt>,
) -> Result<Self::ReturnItem> {
let opt = ctx.opt();
let client = ctx.state().client();
let concurrency_level = std::cmp::min(opt.level, num_cpus::get());
Expand All @@ -34,3 +37,27 @@ impl CommandAction for ConcurrencyLevelCommand {
Ok(format!("set concurrency_level to {}", concurrency_level))
}
}

/// get_concurrency_level command option
#[derive(Debug, Parser)]
#[clap(name = "get_concurrency_level")]
pub struct GetConcurrencyLevelCommandOpt;

pub struct GetConcurrencyLevelCommand;

impl CommandAction for GetConcurrencyLevelCommand {
type State = CliState;
type GlobalOpt = StarcoinOpt;
type Opt = GetConcurrencyLevelCommandOpt;
type ReturnItem = String;

fn run(
&self,
ctx: &ExecContext<Self::State, Self::GlobalOpt, Self::Opt>,
) -> Result<Self::ReturnItem> {
let client = ctx.state().client();
let level = client.get_concurrency_level()?;
info!("client get vm concurrency_level {}", level);
Ok(format!("get concurrency_level is {}", level))
}
}
3 changes: 2 additions & 1 deletion cmd/starcoin/src/lib.rs
Expand Up @@ -142,7 +142,8 @@ pub fn add_command(
.subcommand(dev::panic_cmd::PanicCommand)
.subcommand(dev::sleep_cmd::SleepCommand)
.subcommand(dev::gen_block_cmd::GenBlockCommand)
.subcommand(dev::ConcurrencyLevelCommand),
.subcommand(dev::SetConcurrencyLevelCommand)
.subcommand(dev::GetConcurrencyLevelCommand),
)
.command(CustomCommand::with_name("contract").subcommand(contract::GetContractDataCommand))
}
8 changes: 4 additions & 4 deletions network/src/service.rs
Expand Up @@ -40,7 +40,7 @@ use std::ops::RangeInclusive;
use std::sync::Arc;

const BARNARD_HARD_FORK_PEER_VERSION_STRING_PREFIX: &str = "barnard_rollback_block_fix";
const BARNARD_HARD_FORK_VERSION: [i32; 3] = [1, 12, 9];
const BARNARD_HARD_FORK_VERSION: [i32; 3] = [1, 13, 7];

pub struct NetworkActorService {
/// Worker and inner have ChainInfo instances separately. There might be some way to solve the problem.
Expand Down Expand Up @@ -926,11 +926,11 @@ mod test {
assert!(!greater_barnard_fork_version(&v1));
let v2 = String::from("starcoin 1.13.0-alpha (build:halley-v1.13.1-alpha-dirty)");
assert!(!greater_barnard_fork_version(&v2));
let v3 = String::from("starcoin/1.13.0-alpha (build:v1.13.0-alpha) (kele01)");
assert!(greater_barnard_fork_version(&v3));
let v3 = String::from("starcoin/1.13.7 (build:v1.13.7) (kele01)");
assert!(!greater_barnard_fork_version(&v3));
let v4 = String::from("starcoin/1.12.9 (build:v1.12.9) (kele01)");
assert!(!greater_barnard_fork_version(&v4));
let v5 = String::from("starcoin/1.13.1 (build:v1.13.1) (kele01)");
let v5 = String::from("starcoin/1.13.7 (build:v1.13.8-alpha) (kele01)");
assert!(greater_barnard_fork_version(&v5));
}
}
14 changes: 14 additions & 0 deletions rpc/api/generated_rpc_schema/debug.json
Expand Up @@ -161,6 +161,20 @@
"type": "null"
}
}
},
{
"name": "debug.get_concurrency_level",
"params": [],
"result": {
"name": "usize",
"schema": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "uint",
"type": "integer",
"format": "uint",
"minimum": 0.0
}
}
}
]
}
4 changes: 4 additions & 0 deletions rpc/api/src/debug/mod.rs
Expand Up @@ -32,6 +32,10 @@ pub trait DebugApi {
/// Update vm concurrency level, level = min(level, num_cpus::get)
#[rpc(name = "debug.set_concurrency_level")]
fn set_concurrency_level(&self, level: usize) -> Result<()>;

/// Get vm concurrency level
#[rpc(name = "debug.get_concurrency_level")]
fn get_concurrency_level(&self) -> Result<usize>;
}
#[test]
fn test() {
Expand Down
5 changes: 5 additions & 0 deletions rpc/client/src/lib.rs
Expand Up @@ -736,6 +736,11 @@ impl RpcClient {
.map_err(map_err)
}

pub fn get_concurrency_level(&self) -> anyhow::Result<usize> {
self.call_rpc_blocking(|inner| inner.debug_client.get_concurrency_level())
.map_err(map_err)
}

pub fn chain_id(&self) -> anyhow::Result<ChainId> {
self.call_rpc_blocking(|inner| inner.chain_client.id())
.map_err(map_err)
Expand Down
4 changes: 4 additions & 0 deletions rpc/server/src/module/debug_rpc.rs
Expand Up @@ -88,4 +88,8 @@ impl DebugApi for DebugRpcImpl {
StarcoinVM::set_concurrency_level_once(level);
Ok(())
}

fn get_concurrency_level(&self) -> Result<usize> {
Ok(StarcoinVM::get_concurrency_level())
}
}
2 changes: 1 addition & 1 deletion scripts/nextest.sh
Expand Up @@ -14,7 +14,7 @@ ulimit -a

# install cargo-nextest
echo "Setup cargo-nextest."
cargo nextest -V >/dev/null 2>&1 || cargo install cargo-nextest --locked
cargo nextest -V >/dev/null 2>&1 || cargo install cargo-nextest --version "0.9.57" --locked

# following options are tuned for current self hosted CI machine
# --test-threads 12, proper test concurrency level, balance failure rate and test speed
Expand Down
2 changes: 1 addition & 1 deletion vm/e2e-tests/Cargo.toml
Expand Up @@ -4,7 +4,7 @@ authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
publish = { workspace = true }
version = "1.13.5"
version = "1.13.7"
homepage = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion vm/transaction-benchmarks/Cargo.toml
Expand Up @@ -4,7 +4,7 @@ authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
publish = { workspace = true }
version = "1.13.5"
version = "1.13.7"
homepage = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }
Expand Down

0 comments on commit 2436a7a

Please sign in to comment.