Returned low thread priorty as it seems after thorough tests that there is an impact afterall. But this functionality is now controlled by option 'mining.lower'.
This commit is contained in:
@@ -42,6 +42,10 @@ open = { version = "1.6.0", optional = true }
|
|||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3.7", features = ["impl-default", "wincon", "shellscalingapi"]}
|
winapi = { version = "0.3.7", features = ["impl-default", "wincon", "shellscalingapi"]}
|
||||||
|
thread-priority = "0.2.1"
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
|
thread-priority = "0.2.1"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
minreq = { version = "2.3.1", features = ["punycode", "https-rustls"] }
|
minreq = { version = "2.3.1", features = ["punycode", "https-rustls"] }
|
||||||
|
|||||||
+4
-2
@@ -1,5 +1,5 @@
|
|||||||
# The hash of first block in a chain to know with which nodes to work
|
# The hash of first block in a chain to know with which nodes to work
|
||||||
origin = "00000102C2F9BFD2803284D93327F089D60FC72A06F19AF2384567F2646B8348"
|
origin = "0AE588D62D710422A7972EA1E8A659CC8E93DB59489ACE32C499CD279B000000"
|
||||||
# A path to your key file to load autamatically
|
# A path to your key file to load autamatically
|
||||||
key_file = "default.key"
|
key_file = "default.key"
|
||||||
|
|
||||||
@@ -31,4 +31,6 @@ forwarders = ["94.140.14.14:53", "94.140.15.15:53"]
|
|||||||
#Mining options
|
#Mining options
|
||||||
[mining]
|
[mining]
|
||||||
# How many CPU threads to spawn for mining, zero = number of CPU cores
|
# How many CPU threads to spawn for mining, zero = number of CPU cores
|
||||||
threads = 0
|
threads = 0
|
||||||
|
# Set lower priority for mining threads
|
||||||
|
lower = true
|
||||||
@@ -65,7 +65,7 @@ impl Chain {
|
|||||||
/// Reads options from DB or initializes and writes them to DB if not found
|
/// Reads options from DB or initializes and writes them to DB if not found
|
||||||
fn init_db(&mut self) {
|
fn init_db(&mut self) {
|
||||||
let options = self.get_options();
|
let options = self.get_options();
|
||||||
if !self.origin.is_zero() && !self.origin.is_zero() && self.origin.to_string() != options.origin {
|
if !self.origin.is_zero() && !options.origin.is_empty() && self.origin.to_string() != options.origin {
|
||||||
self.clear_db();
|
self.clear_db();
|
||||||
}
|
}
|
||||||
if options.version < DB_VERSION {
|
if options.version < DB_VERSION {
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ pub mod constants;
|
|||||||
pub use constants::*;
|
pub use constants::*;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
use thread_priority::*;
|
||||||
|
|
||||||
/// Convert bytes array to HEX format
|
/// Convert bytes array to HEX format
|
||||||
pub fn to_hex(buf: &[u8]) -> String {
|
pub fn to_hex(buf: &[u8]) -> String {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
@@ -91,6 +94,25 @@ pub fn is_yggdrasil(addr: &IpAddr) -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
pub fn setup_miner_thread(cpu: u32) {
|
||||||
|
let _ = set_current_thread_priority(ThreadPriority::Min);
|
||||||
|
//let _ = set_current_thread_ideal_processor(IdealProcessor::from(cpu));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
pub fn setup_miner_thread(cpu: u32) {
|
||||||
|
let _ = set_current_thread_priority(ThreadPriority::Min);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
pub fn setup_miner_thread(cpu: u32) {
|
||||||
|
// MacOS is not supported by thread_priority crate
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::{check_domain, is_yggdrasil};
|
use crate::{check_domain, is_yggdrasil};
|
||||||
|
|||||||
+7
-3
@@ -16,7 +16,7 @@ use ed25519_dalek::Keypair;
|
|||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
use crate::blockchain::hash_utils::*;
|
use crate::blockchain::hash_utils::*;
|
||||||
use crate::Context;
|
use crate::{Context, setup_miner_thread};
|
||||||
use crate::event::Event;
|
use crate::event::Event;
|
||||||
use crate::commons::KEYSTORE_DIFFICULTY;
|
use crate::commons::KEYSTORE_DIFFICULTY;
|
||||||
use crate::bytes::Bytes;
|
use crate::bytes::Bytes;
|
||||||
@@ -172,18 +172,22 @@ pub fn check_public_key_strength(key: &Bytes, strength: u32) -> bool {
|
|||||||
pub fn create_key(context: Arc<Mutex<Context>>) {
|
pub fn create_key(context: Arc<Mutex<Context>>) {
|
||||||
let mining = Arc::new(AtomicBool::new(true));
|
let mining = Arc::new(AtomicBool::new(true));
|
||||||
let miners_count = Arc::new(AtomicUsize::new(0));
|
let miners_count = Arc::new(AtomicUsize::new(0));
|
||||||
{ context.lock().unwrap().bus.post(Event::KeyGeneratorStarted); }
|
context.lock().unwrap().bus.post(Event::KeyGeneratorStarted);
|
||||||
|
let lower = context.lock().unwrap().settings.mining.lower;
|
||||||
let threads = context.lock().unwrap().settings.mining.threads;
|
let threads = context.lock().unwrap().settings.mining.threads;
|
||||||
let threads = match threads {
|
let threads = match threads {
|
||||||
0 => num_cpus::get(),
|
0 => num_cpus::get(),
|
||||||
_ => threads
|
_ => threads
|
||||||
};
|
};
|
||||||
for _cpu in 0..threads {
|
for cpu in 0..threads {
|
||||||
let context = Arc::clone(&context);
|
let context = Arc::clone(&context);
|
||||||
let mining = mining.clone();
|
let mining = mining.clone();
|
||||||
let miners_count = miners_count.clone();
|
let miners_count = miners_count.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
miners_count.fetch_add(1, atomic::Ordering::SeqCst);
|
miners_count.fetch_add(1, atomic::Ordering::SeqCst);
|
||||||
|
if lower {
|
||||||
|
setup_miner_thread(cpu as u32);
|
||||||
|
}
|
||||||
match generate_key(KEYSTORE_DIFFICULTY, mining.clone()) {
|
match generate_key(KEYSTORE_DIFFICULTY, mining.clone()) {
|
||||||
None => {
|
None => {
|
||||||
debug!("Keystore mining finished");
|
debug!("Keystore mining finished");
|
||||||
|
|||||||
+5
-1
@@ -8,7 +8,7 @@ use chrono::Utc;
|
|||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use num_cpus;
|
use num_cpus;
|
||||||
|
|
||||||
use crate::{Block, Bytes, Context, Keystore};
|
use crate::{Block, Bytes, Context, Keystore, setup_miner_thread};
|
||||||
use crate::commons::{CHAIN_VERSION, LOCKER_DIFFICULTY, KEYSTORE_DIFFICULTY};
|
use crate::commons::{CHAIN_VERSION, LOCKER_DIFFICULTY, KEYSTORE_DIFFICULTY};
|
||||||
use crate::blockchain::types::BlockQuality;
|
use crate::blockchain::types::BlockQuality;
|
||||||
use crate::blockchain::hash_utils::*;
|
use crate::blockchain::hash_utils::*;
|
||||||
@@ -141,6 +141,7 @@ impl Miner {
|
|||||||
context.lock().unwrap().bus.post(Event::MinerStarted);
|
context.lock().unwrap().bus.post(Event::MinerStarted);
|
||||||
let thread_spawn_interval = Duration::from_millis(10);
|
let thread_spawn_interval = Duration::from_millis(10);
|
||||||
let live_threads = Arc::new(AtomicU32::new(0u32));
|
let live_threads = Arc::new(AtomicU32::new(0u32));
|
||||||
|
let lower = context.lock().unwrap().settings.mining.lower;
|
||||||
let cpus = num_cpus::get();
|
let cpus = num_cpus::get();
|
||||||
let threads = context.lock().unwrap().settings.mining.threads;
|
let threads = context.lock().unwrap().settings.mining.threads;
|
||||||
let threads = match threads {
|
let threads = match threads {
|
||||||
@@ -155,6 +156,9 @@ impl Miner {
|
|||||||
let live_threads = Arc::clone(&live_threads);
|
let live_threads = Arc::clone(&live_threads);
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
live_threads.fetch_add(1, Ordering::SeqCst);
|
live_threads.fetch_add(1, Ordering::SeqCst);
|
||||||
|
if lower {
|
||||||
|
setup_miner_thread(cpu as u32);
|
||||||
|
}
|
||||||
let full = job.block.transaction.is_some();
|
let full = job.block.transaction.is_some();
|
||||||
match find_hash(Arc::clone(&context), job.block, Arc::clone(&mining), cpu) {
|
match find_hash(Arc::clone(&context), job.block, Arc::clone(&mining), cpu) {
|
||||||
None => {
|
None => {
|
||||||
|
|||||||
+3
-1
@@ -84,7 +84,9 @@ impl Default for Dns {
|
|||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct Mining {
|
pub struct Mining {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub threads: usize
|
pub threads: usize,
|
||||||
|
#[serde(default)]
|
||||||
|
pub lower: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user