-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread priority #2566
Thread priority #2566
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,14 @@ use futures::stream::{FuturesOrdered, FuturesUnordered}; | |
use futures::{FutureExt, StreamExt}; | ||
use parking_lot::Mutex; | ||
use prometheus_client::registry::Registry; | ||
use std::fs; | ||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; | ||
use std::num::{NonZeroU8, NonZeroUsize}; | ||
use std::path::PathBuf; | ||
use std::pin::pin; | ||
use std::str::FromStr; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use std::{fmt, fs}; | ||
use subspace_core_primitives::crypto::kzg::{embedded_kzg_settings, Kzg}; | ||
use subspace_core_primitives::{PublicKey, Record, SectorIndex}; | ||
use subspace_erasure_coding::ErasureCoding; | ||
|
@@ -47,6 +47,7 @@ use subspace_networking::libp2p::multiaddr::Protocol; | |
use subspace_networking::libp2p::Multiaddr; | ||
use subspace_networking::utils::piece_provider::PieceProvider; | ||
use subspace_proof_of_space::Table; | ||
use thread_priority::ThreadPriority; | ||
use tokio::sync::Semaphore; | ||
use tracing::{debug, error, info, info_span, warn}; | ||
use zeroize::Zeroizing; | ||
|
@@ -66,6 +67,50 @@ fn should_farm_during_initial_plotting() -> bool { | |
total_cpu_cores > 8 | ||
} | ||
|
||
/// Plotting thread priority | ||
#[derive(Debug, Parser, Copy, Clone)] | ||
enum PlottingThreadPriority { | ||
/// Minimum priority | ||
Min, | ||
/// Default priority | ||
Default, | ||
/// Max priority (not recommended) | ||
Max, | ||
} | ||
|
||
impl FromStr for PlottingThreadPriority { | ||
type Err = String; | ||
|
||
fn from_str(s: &str) -> anyhow::Result<Self, Self::Err> { | ||
match s { | ||
"min" => Ok(Self::Min), | ||
"default" => Ok(Self::Default), | ||
"max" => Ok(Self::Max), | ||
s => Err(format!("Thread priority {s} is not valid")), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for PlottingThreadPriority { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str(match self { | ||
Self::Min => "min", | ||
Self::Default => "default", | ||
Self::Max => "max", | ||
}) | ||
} | ||
} | ||
|
||
impl From<PlottingThreadPriority> for Option<ThreadPriority> { | ||
fn from(value: PlottingThreadPriority) -> Self { | ||
match value { | ||
PlottingThreadPriority::Min => Some(ThreadPriority::Min), | ||
PlottingThreadPriority::Default => None, | ||
PlottingThreadPriority::Max => Some(ThreadPriority::Max), | ||
} | ||
} | ||
} | ||
|
||
/// Arguments for farmer | ||
#[derive(Debug, Parser)] | ||
pub(crate) struct FarmingArgs { | ||
|
@@ -193,6 +238,10 @@ pub(crate) struct FarmingArgs { | |
/// each with a pair of CPU cores. | ||
#[arg(long, conflicts_with_all = & ["sector_encoding_concurrency", "replotting_thread_pool_size"])] | ||
replotting_cpu_cores: Option<String>, | ||
/// Plotting thread priority, by default de-prioritizes plotting threads in order to make sure | ||
/// farming is successful and computer can be used comfortably for other things | ||
#[arg(long, default_value_t = PlottingThreadPriority::Min)] | ||
plotting_thread_priority: PlottingThreadPriority, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to change this feature if we consider it useful? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there different circumstances and |
||
/// Disable farm locking, for example if file system doesn't support it | ||
#[arg(long)] | ||
disable_farm_locking: bool, | ||
|
@@ -346,6 +395,7 @@ where | |
plotting_cpu_cores, | ||
replotting_thread_pool_size, | ||
replotting_cpu_cores, | ||
plotting_thread_priority, | ||
disable_farm_locking, | ||
} = farming_args; | ||
|
||
|
@@ -571,6 +621,7 @@ where | |
plotting_thread_pool_core_indices | ||
.into_iter() | ||
.zip(replotting_thread_pool_core_indices), | ||
plotting_thread_priority.into(), | ||
)?; | ||
let farming_thread_pool_size = farming_thread_pool_size | ||
.map(|farming_thread_pool_size| farming_thread_pool_size.get()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any specific reason why reference implementation wants to use this plotting when its clearly not recommended? Maybe this should not be an option at all ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is actually a much more fine-grained control available over priority. But for now I decided to give extreme option for users to try and experiment with. It will likely evolve over time, we may end up removing it if not helpful. This might be desirable to accelerate plotting at all costs, but it will likely make farming while plotting not possible at all (though not guaranteed).