Enum cuprate_blockchain::config::ReaderThreads
source · pub enum ReaderThreads {
OnePerThread,
One,
Number(usize),
Percent(f32),
}Expand description
Amount of database reader threads to spawn when using service.
This controls how many reader thread service’s
thread-pool will spawn to receive and send requests/responses.
It does nothing outside of service.
It will always be at least 1, up until the amount of threads on the machine.
The main function used to extract an actual
usable thread count out of this is ReaderThreads::as_threads.
Variants§
OnePerThread
Spawn 1 reader thread per available thread on the machine.
For example, a 32-thread system will spawn
32 reader threads using this setting.
One
Only spawn 1 reader thread.
Number(usize)
Spawn a specified amount of reader threads.
Note that no matter how large this value, it will be ultimately capped at the amount of system threads.
§0
ReaderThreads::Number(0) represents “use maximum value”,
as such, it is equal to ReaderThreads::OnePerThread.
let reader_threads = ReaderThreads::from(0_usize);
assert!(matches!(reader_threads, ReaderThreads::OnePerThread));Percent(f32)
Spawn a specified % of reader threads.
This must be a value in-between 0.0..1.0
where 1.0 represents ReaderThreads::OnePerThread.
§Example
For example, using a 16-core, 32-thread Ryzen 5950x CPU:
| Input | Total thread used |
|---|---|
ReaderThreads::Percent(0.0) | 32 (maximum value) |
ReaderThreads::Percent(0.5) | 16 |
ReaderThreads::Percent(0.75) | 24 |
ReaderThreads::Percent(1.0) | 32 |
ReaderThreads::Percent(2.0) | 32 (saturating) |
ReaderThreads::Percent(f32::NAN) | 32 (non-normal default) |
§0.0
ReaderThreads::Percent(0.0) represents “use maximum value”,
as such, it is equal to ReaderThreads::OnePerThread.
§Not quite 0.0
If the thread count multiplied by the percentage ends up being non-zero, but not 1 thread, the minimum value 1 will be returned.
assert_eq!(ReaderThreads::Percent(0.000000001).as_threads().get(), 1);Implementations§
source§impl ReaderThreads
impl ReaderThreads
sourcepub fn as_threads(&self) -> NonZeroUsize
pub fn as_threads(&self) -> NonZeroUsize
This converts ReaderThreads into a safe, usable
number representing how many threads to spawn.
This function will always return a number in-between 1..=total_thread_count.
It uses cuprate_helper::thread::threads() internally to determine the total thread count.
§Example
use cuprate_blockchain::config::ReaderThreads as Rt;
let total_threads: std::num::NonZeroUsize =
cuprate_helper::thread::threads();
assert_eq!(Rt::OnePerThread.as_threads(), total_threads);
assert_eq!(Rt::One.as_threads().get(), 1);
assert_eq!(Rt::Number(0).as_threads(), total_threads);
assert_eq!(Rt::Number(1).as_threads().get(), 1);
assert_eq!(Rt::Number(usize::MAX).as_threads(), total_threads);
assert_eq!(Rt::Percent(0.01).as_threads().get(), 1);
assert_eq!(Rt::Percent(0.0).as_threads(), total_threads);
assert_eq!(Rt::Percent(1.0).as_threads(), total_threads);
assert_eq!(Rt::Percent(f32::NAN).as_threads(), total_threads);
assert_eq!(Rt::Percent(f32::INFINITY).as_threads(), total_threads);
assert_eq!(Rt::Percent(f32::NEG_INFINITY).as_threads(), total_threads);
// Percentage only works on more than 1 thread.
if total_threads.get() > 1 {
assert_eq!(
Rt::Percent(0.5).as_threads().get(),
(total_threads.get() as f32 / 2.0) as usize,
);
}Trait Implementations§
source§impl Clone for ReaderThreads
impl Clone for ReaderThreads
source§fn clone(&self) -> ReaderThreads
fn clone(&self) -> ReaderThreads
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for ReaderThreads
impl Debug for ReaderThreads
source§impl Default for ReaderThreads
impl Default for ReaderThreads
source§fn default() -> ReaderThreads
fn default() -> ReaderThreads
source§impl<T: Into<usize>> From<T> for ReaderThreads
impl<T: Into<usize>> From<T> for ReaderThreads
source§fn from(value: T) -> Self
fn from(value: T) -> Self
Create a ReaderThreads::Number.
If value is 0, this will return ReaderThreads::OnePerThread.
source§impl PartialEq for ReaderThreads
impl PartialEq for ReaderThreads
source§fn eq(&self, other: &ReaderThreads) -> bool
fn eq(&self, other: &ReaderThreads) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd for ReaderThreads
impl PartialOrd for ReaderThreads
source§fn partial_cmp(&self, other: &ReaderThreads) -> Option<Ordering>
fn partial_cmp(&self, other: &ReaderThreads) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Copy for ReaderThreads
impl StructuralPartialEq for ReaderThreads
Auto Trait Implementations§
impl Freeze for ReaderThreads
impl RefUnwindSafe for ReaderThreads
impl Send for ReaderThreads
impl Sync for ReaderThreads
impl Unpin for ReaderThreads
impl UnwindSafe for ReaderThreads
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 16 bytes
Size for each variant:
OnePerThread: 0 bytesOne: 0 bytesNumber: 12 bytesPercent: 4 bytes