pub enum ReaderThreads {
OnePerThread,
One,
Number(usize),
Percent(f32),
}
Expand description
Amount of database reader threads to spawn.
This controls how many reader threads the DatabaseReadService
thread-pool will spawn to receive and send requests/responses.
§Invariant
The main function used to extract an actual
usable thread count out of this is ReaderThreads::as_threads
.
This will always return at least 1, up until the amount of threads on the machine.
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) -> NonZero<usize>
pub fn as_threads(&self) -> NonZero<usize>
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_database_service::ReaderThreads as R;
let total_threads: std::num::NonZeroUsize =
cuprate_helper::thread::threads();
assert_eq!(R::OnePerThread.as_threads(), total_threads);
assert_eq!(R::One.as_threads().get(), 1);
assert_eq!(R::Number(0).as_threads(), total_threads);
assert_eq!(R::Number(1).as_threads().get(), 1);
assert_eq!(R::Number(usize::MAX).as_threads(), total_threads);
assert_eq!(R::Percent(0.01).as_threads().get(), 1);
assert_eq!(R::Percent(0.0).as_threads(), total_threads);
assert_eq!(R::Percent(1.0).as_threads(), total_threads);
assert_eq!(R::Percent(f32::NAN).as_threads(), total_threads);
assert_eq!(R::Percent(f32::INFINITY).as_threads(), total_threads);
assert_eq!(R::Percent(f32::NEG_INFINITY).as_threads(), total_threads);
// Percentage only works on more than 1 thread.
if total_threads.get() > 1 {
assert_eq!(
R::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<'de> Deserialize<'de> for ReaderThreads
impl<'de> Deserialize<'de> for ReaderThreads
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ReaderThreads, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ReaderThreads, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<T> From<T> for ReaderThreads
impl<T> From<T> for ReaderThreads
Source§fn from(value: T) -> ReaderThreads
fn from(value: T) -> ReaderThreads
Create a ReaderThreads::Number
.
If value
is 0
, this will return ReaderThreads::OnePerThread
.
Source§impl PartialEq for ReaderThreads
impl PartialEq for ReaderThreads
Source§impl PartialOrd for ReaderThreads
impl PartialOrd for ReaderThreads
Source§impl Serialize for ReaderThreads
impl Serialize for ReaderThreads
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl 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: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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