Use std::available_parallelism instead of num_cpus (#633)
* Explicitly set minimum rust version * Use std::available_parallelism instead of num_cpus
This commit is contained in:
parent
460fa3c105
commit
fe585ac24c
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -196,7 +196,6 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"memchr",
|
"memchr",
|
||||||
"nom",
|
"nom",
|
||||||
"num_cpus",
|
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"paste",
|
"paste",
|
||||||
|
|
|
@ -9,6 +9,7 @@ repository = "https://github.com/master-of-zen/Av1an"
|
||||||
keywords = ["video"]
|
keywords = ["video"]
|
||||||
categories = ["command-line-utilities"]
|
categories = ["command-line-utilities"]
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
rust-version = "1.59"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -9,6 +9,7 @@ repository = "https://github.com/master-of-zen/Av1an"
|
||||||
keywords = ["video"]
|
keywords = ["video"]
|
||||||
categories = ["command-line-utilities"]
|
categories = ["command-line-utilities"]
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
rust-version = "1.59"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "av1an-core"
|
name = "av1an-core"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
rust-version = "1.59"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Zen <master_of_zen@protonmail.com>"]
|
authors = ["Zen <master_of_zen@protonmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
|
@ -20,7 +21,6 @@ atty = "0.2.14"
|
||||||
av-format = "0.3.1"
|
av-format = "0.3.1"
|
||||||
av-ivf = "0.2.2"
|
av-ivf = "0.2.2"
|
||||||
memchr = "2.4.1"
|
memchr = "2.4.1"
|
||||||
num_cpus = "1.13.0"
|
|
||||||
anyhow = "1.0.42"
|
anyhow = "1.0.42"
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
@ -6,6 +6,7 @@ use std::process::ExitStatus;
|
||||||
use std::sync::atomic::{self, AtomicU64};
|
use std::sync::atomic::{self, AtomicU64};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::thread::available_parallelism;
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
use memchr::memmem;
|
use memchr::memmem;
|
||||||
|
@ -123,7 +124,7 @@ impl<'a> Broker<'a> {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(any(target_os = "linux", target_os = "windows"))] {
|
if #[cfg(any(target_os = "linux", target_os = "windows"))] {
|
||||||
if let Some(threads) = set_thread_affinity {
|
if let Some(threads) = set_thread_affinity {
|
||||||
let available_threads = num_cpus::get();
|
let available_threads = available_parallelism().expect("Unrecoverable: Failed to get thread count").get();
|
||||||
let requested_threads = threads.saturating_mul(self.project.workers);
|
let requested_threads = threads.saturating_mul(self.project.workers);
|
||||||
if requested_threads > available_threads {
|
if requested_threads > available_threads {
|
||||||
warn!(
|
warn!(
|
||||||
|
|
|
@ -29,6 +29,7 @@ use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||||
|
use std::thread::available_parallelism;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use ::ffmpeg::color::TransferCharacteristic;
|
use ::ffmpeg::color::TransferCharacteristic;
|
||||||
|
@ -327,7 +328,9 @@ pub fn determine_workers(encoder: Encoder) -> u64 {
|
||||||
let mut system = sysinfo::System::new();
|
let mut system = sysinfo::System::new();
|
||||||
system.refresh_memory();
|
system.refresh_memory();
|
||||||
|
|
||||||
let cpu = num_cpus::get() as u64;
|
let cpu = available_parallelism()
|
||||||
|
.expect("Unrecoverable: Failed to get thread count")
|
||||||
|
.get() as u64;
|
||||||
// available_memory returns kb, convert to gb
|
// available_memory returns kb, convert to gb
|
||||||
let ram_gb = system.available_memory() / 10_u64.pow(6);
|
let ram_gb = system.available_memory() / 10_u64.pow(6);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
|
||||||
use std::process::{exit, Command, Stdio};
|
use std::process::{exit, Command, Stdio};
|
||||||
use std::sync::atomic::{self, AtomicBool, AtomicU64, AtomicUsize};
|
use std::sync::atomic::{self, AtomicBool, AtomicU64, AtomicUsize};
|
||||||
use std::sync::{mpsc, Arc};
|
use std::sync::{mpsc, Arc};
|
||||||
|
use std::thread::available_parallelism;
|
||||||
use std::{cmp, fs, iter, thread};
|
use std::{cmp, fs, iter, thread};
|
||||||
|
|
||||||
use ansi_term::{Color, Style};
|
use ansi_term::{Color, Style};
|
||||||
|
@ -1340,7 +1341,11 @@ properly into a mkv file. Specify mkvmerge as the concatenation method by settin
|
||||||
Some(filter) => Some(filter),
|
Some(filter) => Some(filter),
|
||||||
None => None,
|
None => None,
|
||||||
},
|
},
|
||||||
self.vmaf_threads.unwrap_or_else(num_cpus::get),
|
self.vmaf_threads.unwrap_or_else(|| {
|
||||||
|
available_parallelism()
|
||||||
|
.expect("Unrecoverable: Failed to get thread count")
|
||||||
|
.get()
|
||||||
|
}),
|
||||||
) {
|
) {
|
||||||
error!("VMAF calculation failed with error: {}", e);
|
error!("VMAF calculation failed with error: {}", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ use std::convert::TryInto;
|
||||||
use std::fmt::Error;
|
use std::fmt::Error;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
use std::thread::available_parallelism;
|
||||||
|
|
||||||
use ffmpeg::format::Pixel;
|
use ffmpeg::format::Pixel;
|
||||||
use splines::{Interpolation, Key, Spline};
|
use splines::{Interpolation, Key, Spline};
|
||||||
|
@ -299,7 +300,9 @@ pub fn vmaf_auto_threads(workers: usize) -> usize {
|
||||||
const OVER_PROVISION_FACTOR: f64 = 1.25;
|
const OVER_PROVISION_FACTOR: f64 = 1.25;
|
||||||
|
|
||||||
// Logical CPUs
|
// Logical CPUs
|
||||||
let threads = num_cpus::get();
|
let threads = available_parallelism()
|
||||||
|
.expect("Unrecoverable: Failed to get thread count")
|
||||||
|
.get();
|
||||||
|
|
||||||
cmp::max(
|
cmp::max(
|
||||||
((threads / workers) as f64 * OVER_PROVISION_FACTOR) as usize,
|
((threads / workers) as f64 * OVER_PROVISION_FACTOR) as usize,
|
||||||
|
|
Loading…
Reference in a new issue