Skip to content

Commit

Permalink
Use tokio's unstable disable_lifo_slot to improve NATS communicatio…
Browse files Browse the repository at this point in the history
…n with farmer under plotting load
  • Loading branch information
nazar-pc committed Jul 11, 2024
1 parent 360e29d commit ceec8a4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 50 deletions.
6 changes: 4 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[target.'cfg(target_arch = "x86_64")']
# Require AES-NI on x86-64 by default
rustflags = ["-C", "target-feature=+aes"]
# TODO: Remove `tokio_unstable` once farmer no longer uses it
rustflags = ["-C", "target-feature=+aes", "--cfg", "tokio_unstable"]

[target.'cfg(target_arch = "aarch64")']
# TODO: AES flag is such that we have decent performance on ARMv8, remove once `aes` crate with MSRV bump ships:
# https://github.com/RustCrypto/block-ciphers/pull/395
rustflags = ["--cfg", "aes_armv8"]
# TODO: Remove `tokio_unstable` once farmer no longer uses it
rustflags = ["--cfg", "aes_armv8", "--cfg", "tokio_unstable"]
6 changes: 4 additions & 2 deletions .github/workflows/snapshot-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# TODO: Remove `tokio_unstable` once farmer no longer uses it
build-args: |
SUBSTRATE_CLI_GIT_COMMIT_HASH=${{ github.sha }}
RUSTFLAGS=${{ matrix.platform.rustflags }}
"RUSTFLAGS=${{ matrix.platform.rustflags }} --cfg tokio_unstable"
- name: Trigger trivy-security-scan Workflow
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # @v3.0.0
Expand Down Expand Up @@ -124,7 +125,8 @@ jobs:
runs-on: ${{ matrix.build.os }}
env:
PRODUCTION_TARGET: target/${{ matrix.build.target }}/production
RUSTFLAGS: ${{ matrix.build.rustflags }}
# TODO: Remove `tokio_unstable` once farmer no longer uses it
RUSTFLAGS: ${{ matrix.build.rustflags }} --cfg tokio_unstable

steps:
- name: Checkout
Expand Down
103 changes: 57 additions & 46 deletions crates/subspace-farmer/src/bin/subspace-farmer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ enum Command {
},
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
fn main() -> anyhow::Result<()> {
tracing_subscriber::registry()
.with(
fmt::layer()
Expand All @@ -98,57 +97,69 @@ async fn main() -> anyhow::Result<()> {

let command = Command::parse();

match command {
Command::Farm(farming_args) => {
commands::farm::farm::<PosTableLegacy, PosTable>(farming_args).await?;
}
Command::Cluster(cluster_args) => {
commands::cluster::cluster::<PosTableLegacy, PosTable>(cluster_args).await?;
}
Command::Benchmark(benchmark_args) => {
commands::benchmark::benchmark(benchmark_args)?;
}
Command::Info { disk_farms } => {
if disk_farms.is_empty() {
info!("No farm was specified, so there is nothing to do");
} else {
commands::info(disk_farms);
let mut runtime_builder = tokio::runtime::Builder::new_multi_thread();
runtime_builder.enable_all();
// TODO: This is a hack to work around https://github.com/tokio-rs/tokio/issues/4941 and
// should be replaced with `#[tokio::main]` attribute once resolved
#[cfg(tokio_unstable)]
runtime_builder.disable_lifo_slot();
let runtime = runtime_builder
.build()
.map_err(|error| anyhow::anyhow!("Failed to build tokio runtime: {error}"))?;

runtime.block_on(async {
match command {
Command::Farm(farming_args) => {
commands::farm::farm::<PosTableLegacy, PosTable>(farming_args).await?;
}
}
Command::Scrub {
disk_farms,
disable_farm_locking,
target,
dry_run,
} => {
if disk_farms.is_empty() {
info!("No farm was specified, so there is nothing to do");
} else {
commands::scrub(&disk_farms, disable_farm_locking, target, dry_run);
Command::Cluster(cluster_args) => {
commands::cluster::cluster::<PosTableLegacy, PosTable>(cluster_args).await?;
}
}
Command::Wipe { disk_farms } => {
for disk_farm in &disk_farms {
if !disk_farm.exists() {
panic!("Directory {} doesn't exist", disk_farm.display());
Command::Benchmark(benchmark_args) => {
commands::benchmark::benchmark(benchmark_args)?;
}
Command::Info { disk_farms } => {
if disk_farms.is_empty() {
info!("No farm was specified, so there is nothing to do");
} else {
commands::info(disk_farms);
}
}

for disk_farm in &disk_farms {
if disk_farm.join("known_addresses.bin").exists() {
info!("Wiping known addresses");
let _ = fs::remove_file(disk_farm.join("known_addresses.bin"));
Command::Scrub {
disk_farms,
disable_farm_locking,
target,
dry_run,
} => {
if disk_farms.is_empty() {
info!("No farm was specified, so there is nothing to do");
} else {
commands::scrub(&disk_farms, disable_farm_locking, target, dry_run);
}

SingleDiskFarm::wipe(disk_farm)?;
}
Command::Wipe { disk_farms } => {
for disk_farm in &disk_farms {
if !disk_farm.exists() {
panic!("Directory {} doesn't exist", disk_farm.display());
}
}

for disk_farm in &disk_farms {
if disk_farm.join("known_addresses.bin").exists() {
info!("Wiping known addresses");
let _ = fs::remove_file(disk_farm.join("known_addresses.bin"));
}

if disk_farms.is_empty() {
info!("No farm was specified, so there is nothing to do");
} else {
info!("Done");
SingleDiskFarm::wipe(disk_farm)?;
}

if disk_farms.is_empty() {
info!("No farm was specified, so there is nothing to do");
} else {
info!("Done");
}
}
}
}
Ok(())
Ok(())
})
}

0 comments on commit ceec8a4

Please sign in to comment.