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
98
99
100
101
102
103
104
105
106
use std::time::Duration;
#[derive(Default, Clone)]
pub struct Config {
pub scheduler: SchedulerConfig,
pub remote: RemoteConfig,
}
impl Config {
pub fn new(scheduler: SchedulerConfig, remote: RemoteConfig) -> Config {
Config { scheduler, remote }
}
}
#[derive(Debug, Clone)]
pub struct ServerConfig {
pub events_capacity: usize,
pub recv_buffer_size: usize,
pub send_buffer_size: usize,
}
impl Default for ServerConfig {
fn default() -> Self {
Self {
events_capacity: 1024,
recv_buffer_size: 1024,
send_buffer_size: 1024,
}
}
}
#[derive(Debug, Clone)]
pub struct ClientConfig {
pub events_capacity: usize,
pub recv_buffer_size: usize,
pub send_buffer_size: usize,
}
impl Default for ClientConfig {
fn default() -> Self {
Self {
events_capacity: 1024,
recv_buffer_size: 1024,
send_buffer_size: 1024,
}
}
}
#[derive(Clone, Default)]
pub struct RemoteConfig {
pub enabled: bool,
pub listening: String,
pub server: ServerConfig,
pub client: ClientConfig,
}
impl RemoteConfig {
pub fn listening_at(listening: &str, server: ServerConfig, client: ClientConfig) -> Self {
Self {
enabled: true,
listening: listening.to_string(),
server,
client,
}
}
}
#[derive(Clone)]
pub struct SchedulerConfig {
pub default_mailbox_capacity: usize,
pub logging_enabled: bool,
pub metric_reporting_enabled: bool,
pub metric_reporting_interval: Duration,
pub delay_precision: Duration,
pub actor_worker_threads: usize,
pub extra_worker_threads: usize,
pub eager_shutdown_enabled: bool,
}
impl Default for SchedulerConfig {
fn default() -> Self {
SchedulerConfig {
default_mailbox_capacity: 16,
logging_enabled: true,
metric_reporting_enabled: false,
metric_reporting_interval: Duration::from_secs(1),
delay_precision: Duration::from_millis(1),
actor_worker_threads: 4,
extra_worker_threads: 1,
eager_shutdown_enabled: true,
}
}
}
impl SchedulerConfig {
pub fn with_total_threads(total_threads: usize) -> Self {
SchedulerConfig {
actor_worker_threads: total_threads,
..Default::default()
}
}
pub(crate) fn total_threads_required(&self) -> usize {
self.actor_worker_threads + self.extra_worker_threads + 1
}
}