1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! Configuration options which can alter the behavior of the pool.
use tokio::time::Duration;
/// Policy which is applicable to a connection pool.
#[derive(Clone, Debug)]
pub struct Policy {
/// The total number of spares wanted within the pool.
///
/// This is the count of spares, across all backends, that the pool attempts
/// to keep available, as "unclaimed connections".
///
/// As an example, if N claims are checked out of the pool, the pool will
/// attempt to create "N + spares_wanted" total connections.
pub spares_wanted: usize,
/// The maximum number of connections within the pool.
/// This is a hard capacity across all backends combined.
///
/// To adjust the capacity for each backend individually, see:
/// [SetConfig::max_count].
pub max_slots: usize,
/// The interval at which rebalancing backends should occur.
pub rebalance_interval: Duration,
/// Sets the timeout for a client of the pool making a claim.
pub claim_timeout: Duration,
/// Configuration for a slot set attempting to connect to a backend.
pub set_config: SetConfig,
}
impl Default for Policy {
fn default() -> Self {
Self {
spares_wanted: 8,
max_slots: 16,
rebalance_interval: Duration::from_secs(60),
claim_timeout: Duration::from_secs(30),
set_config: SetConfig::default(),
}
}
}
/// Configuration options for "Slot Sets".
///
/// Slot sets are groups of slots which all are connected to the same backend.
#[derive(Clone, Debug)]
pub struct SetConfig {
/// The max number of slots for the connection set.
///
/// The total number of slots across all backends is capped
/// by [Policy::max_slots].
pub max_count: usize,
/// The minimum time before retrying connection requests
pub min_connection_backoff: Duration,
/// The maximum time to backoff between connection requests
pub max_connection_backoff: Duration,
/// When retrying a connection, add a random amount of delay between [0, spread).
///
/// If "Duration::ZERO" is used, no spread is added.
pub spread: Duration,
/// How long to wait before checking on the health of a connection.
///
/// This has no backoff - on success, we wait this same period, and on
/// failure, we reconnect, which uses the normal "connection_backoff"
/// configs.
///
/// To prevent periodic checks, supply "Duration::MAX".
pub health_interval: Duration,
/// The maximum amount of time a health check has before failing.
///
/// This is a bound on the following methods of the backend connector:
/// - [crate::backend::Connector::is_valid]
/// - [crate::backend::Connector::on_acquire]
/// - [crate::backend::Connector::on_recycle]
pub health_check_timeout: Duration,
}
impl Default for SetConfig {
fn default() -> Self {
Self {
max_count: 16,
min_connection_backoff: Duration::from_millis(20),
max_connection_backoff: Duration::from_secs(30),
spread: Duration::from_millis(20),
health_interval: Duration::from_secs(30),
health_check_timeout: Duration::from_secs(3),
}
}
}