#[non_exhaustive]pub struct Limits { /* private fields */ }Expand description
Every bound net-io enforces. Unset values take the defaults of the driver that runs the connection.
§Examples
use net_io::{DriverKind, Limits, MinRate};
use std::time::Duration;
let limits = Limits::builder()
.max_connections(20_000)
.idle_timeout(Duration::from_secs(15))
.min_rate(MinRate::new(512, Duration::from_secs(10)))
.build()?;
assert_eq!(limits.max_connections(), Some(20_000));
assert_eq!(limits.read_timeout(), None);
assert_eq!(limits.resolve(DriverKind::Blocking).read_timeout(), Some(Duration::from_secs(30)));Implementations§
Source§impl Limits
impl Limits
Sourcepub fn builder() -> LimitsBuilder
pub fn builder() -> LimitsBuilder
A builder with every value unset.
let limits = net_io::Limits::builder().max_connections(100).build()?;
assert_eq!(limits.max_per_source(), None);Sourcepub fn reactor_defaults() -> Limits
pub fn reactor_defaults() -> Limits
Every value set to the reactor’s defaults.
assert_eq!(net_io::Limits::reactor_defaults().max_connections(), Some(10_000));Sourcepub fn blocking_defaults() -> Limits
pub fn blocking_defaults() -> Limits
Every value set to the blocking driver’s defaults.
assert_eq!(net_io::Limits::blocking_defaults().idle_timeout(), Some(std::time::Duration::from_secs(5)));Sourcepub fn to_builder(&self) -> LimitsBuilder
pub fn to_builder(&self) -> LimitsBuilder
A builder starting from these values.
Every value carried over counts as set, so lowering max_connections
below a carried-over max_per_listener fails validation. Start from
Limits::builder to let dependent values follow max_connections.
let limits = net_io::Limits::blocking_defaults().to_builder().max_connections(256).build()?;
assert_eq!(limits.max_connections(), Some(256));Sourcepub fn resolve(&self, driver: DriverKind) -> Limits
pub fn resolve(&self, driver: DriverKind) -> Limits
These limits with unset values filled from driver’s defaults.
let limits = net_io::Limits::builder().max_connections(10).build()?;
let resolved = limits.resolve(net_io::DriverKind::Blocking);
assert_eq!(resolved.max_per_source().map(|(n, _)| n), Some(10));Sourcepub fn validate(
&self,
workers: u16,
descriptor_limit: Option<u64>,
) -> Result<(), NetError>
pub fn validate( &self, workers: u16, descriptor_limit: Option<u64>, ) -> Result<(), NetError>
Checks the values, with unset ones taken from the blocking driver’s
defaults, against each other, the worker count, and the process’s
descriptor limit. ServerBuilder::build runs the same checks with the
defaults of the driver it resolved.
§Errors
InvalidConfig { field, reason } for the first rule broken.
let limits = net_io::Limits::builder().max_connections(1_000_000).build()?;
assert!(limits.validate(4, Some(1024)).is_err());Sourcepub fn max_connections(&self) -> Option<u32>
pub fn max_connections(&self) -> Option<u32>
The global connection cap.
Sourcepub fn max_per_listener(&self) -> Option<u32>
pub fn max_per_listener(&self) -> Option<u32>
The per-listener connection cap.
Sourcepub fn max_per_source(&self) -> Option<(u32, PrefixPolicy)>
pub fn max_per_source(&self) -> Option<(u32, PrefixPolicy)>
The per-source concurrency cap and how sources are grouped. Each listener applies its own value to its own connections. Every open connection counts, including one finishing a graceful close, so a client at the cap that reconnects at once can be refused until its last connection is closed.
Sourcepub fn accept_batch(&self) -> Option<u16>
pub fn accept_batch(&self) -> Option<u16>
Connections accepted per wake-up.
Sourcepub fn handshake_timeout(&self) -> Option<Duration>
pub fn handshake_timeout(&self) -> Option<Duration>
Time for the PROXY header and TLS handshake together.
Sourcepub fn idle_timeout(&self) -> Option<Duration>
pub fn idle_timeout(&self) -> Option<Duration>
Time to wait for the next exchange.
Sourcepub fn read_timeout(&self) -> Option<Duration>
pub fn read_timeout(&self) -> Option<Duration>
Time to wait for bytes during an exchange.
Sourcepub fn write_timeout(&self) -> Option<Duration>
pub fn write_timeout(&self) -> Option<Duration>
Time to wait for the peer to take bytes.
Sourcepub fn park_timeout(&self) -> Option<Duration>
pub fn park_timeout(&self) -> Option<Duration>
Time a parked connection may wait for its completion.
Sourcepub fn proxy_header_max(&self) -> Option<u16>
pub fn proxy_header_max(&self) -> Option<u16>
The PROXY v2 address-and-TLV cap.
Sourcepub fn read_class(&self) -> Option<(SizeClass, SizeClass)>
pub fn read_class(&self) -> Option<(SizeClass, SizeClass)>
The initial and maximum read buffer class.
Sourcepub fn output_budget(&self) -> Option<u32>
pub fn output_budget(&self) -> Option<u32>
Pool memory a connection’s output may hold.
Sourcepub fn completion_queue(&self) -> Option<u32>
pub fn completion_queue(&self) -> Option<u32>
A worker’s completion queue length.
Sourcepub fn buffer_budget(&self) -> Option<u64>
pub fn buffer_budget(&self) -> Option<u64>
Total bytes of buffers all workers may allocate.
Each worker’s pool keeps at most the budget divided by the workers in its free lists and frees what is released above that, and a pool that needs a buffer of one size with the budget spent frees the buffers it keeps of other sizes first, so the budget comes back after a burst.
On the reactor a TLS connection takes its two buffers (the largest read class
in, 64 KiB out) only when its first bytes arrive, and the connections whose
handshake has not finished may hold at most a quarter of the budget, divided
by the workers, on each worker (at least one handshake each). A connection
whose handshake would take buffers above that is closed with
Limit(BufferBudget); plaintext connections keep the rest.
Sourcepub fn drain_timeout(&self) -> Option<Duration>
pub fn drain_timeout(&self) -> Option<Duration>
The drain deadline.
Sourcepub fn first_request_grace(&self) -> Option<Duration>
pub fn first_request_grace(&self) -> Option<Duration>
How long a drain waits for the first request of a connection that has sent nothing yet.
Sourcepub fn graceful_linger(&self) -> Option<(Duration, u32)>
pub fn graceful_linger(&self) -> Option<(Duration, u32)>
The graceful-close linger: time and bytes read and discarded.
Sourcepub fn denial_linger(&self) -> Option<Duration>
pub fn denial_linger(&self) -> Option<Duration>
How long a connection that was sent a denial lingers before it closes.
Sourcepub fn denial_linger_max(&self) -> Option<u32>
pub fn denial_linger_max(&self) -> Option<u32>
How many connections may close softly (linger after a denial, or
close_after_flush) at once, server-wide.
Sourcepub fn refusal_bytes_max(&self) -> Option<u16>
pub fn refusal_bytes_max(&self) -> Option<u16>
The largest refusal reply.
Sourcepub fn lane_reserve(&self, lane: Lane) -> Option<u32>
pub fn lane_reserve(&self, lane: Lane) -> Option<u32>
The connection slots reserved for lane (lanes 0 to 7).