itsi-server 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +7 -0
- data/Cargo.lock +1536 -45
- data/README.md +4 -0
- data/_index.md +6 -0
- data/exe/itsi +33 -74
- data/ext/itsi_error/src/lib.rs +9 -0
- data/ext/itsi_error/target/debug/build/clang-sys-da71b0344e568175/out/common.rs +355 -0
- data/ext/itsi_error/target/debug/build/clang-sys-da71b0344e568175/out/dynamic.rs +276 -0
- data/ext/itsi_error/target/debug/build/clang-sys-da71b0344e568175/out/macros.rs +49 -0
- data/ext/itsi_error/target/debug/build/rb-sys-49f554618693db24/out/bindings-0.9.110-mri-arm64-darwin23-3.4.2.rs +8865 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-1mmt5sux7jb0i/s-h510z7m8v9-0bxu7yd.lock +0 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-2vn3jey74oiw0/s-h5113n0e7e-1v5qzs6.lock +0 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-37uv9dicz7awp/s-h510ykifhe-0tbnep2.lock +0 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-37uv9dicz7awp/s-h510yyocpj-0tz7ug7.lock +0 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-37uv9dicz7awp/s-h510z0xc8g-14ol18k.lock +0 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-3g5qf4y7d54uj/s-h5113n0e7d-1trk8on.lock +0 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-3lpfftm45d3e2/s-h510z7m8r3-1pxp20o.lock +0 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-3o4qownhl3d7n/s-h510ykifek-1uxasnk.lock +0 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-3o4qownhl3d7n/s-h510yyocki-11u37qm.lock +0 -0
- data/ext/itsi_error/target/debug/incremental/itsi_error-3o4qownhl3d7n/s-h510z0xc93-0pmy0zm.lock +0 -0
- data/ext/itsi_rb_helpers/Cargo.toml +1 -0
- data/ext/itsi_rb_helpers/src/heap_value.rs +18 -0
- data/ext/itsi_rb_helpers/src/lib.rs +34 -7
- data/ext/itsi_rb_helpers/target/debug/build/clang-sys-da71b0344e568175/out/common.rs +355 -0
- data/ext/itsi_rb_helpers/target/debug/build/clang-sys-da71b0344e568175/out/dynamic.rs +276 -0
- data/ext/itsi_rb_helpers/target/debug/build/clang-sys-da71b0344e568175/out/macros.rs +49 -0
- data/ext/itsi_rb_helpers/target/debug/build/rb-sys-eb9ed4ff3a60f995/out/bindings-0.9.110-mri-arm64-darwin23-3.4.2.rs +8865 -0
- data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-040pxg6yhb3g3/s-h5113n7a1b-03bwlt4.lock +0 -0
- data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-131g1u4dzkt1a/s-h51113xnh3-1eik1ip.lock +0 -0
- data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-131g1u4dzkt1a/s-h5111704jj-0g4rj8x.lock +0 -0
- data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-1q2d3drtxrzs5/s-h5113n79yl-0bxcqc5.lock +0 -0
- data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-374a9h7ovycj0/s-h51113xoox-10de2hp.lock +0 -0
- data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-374a9h7ovycj0/s-h5111704w7-0vdq7gq.lock +0 -0
- data/ext/itsi_server/Cargo.toml +69 -30
- data/ext/itsi_server/src/lib.rs +79 -147
- data/ext/itsi_server/src/{body_proxy → ruby_types/itsi_body_proxy}/big_bytes.rs +10 -5
- data/ext/itsi_server/src/{body_proxy/itsi_body_proxy.rs → ruby_types/itsi_body_proxy/mod.rs} +22 -3
- data/ext/itsi_server/src/ruby_types/itsi_grpc_request.rs +147 -0
- data/ext/itsi_server/src/ruby_types/itsi_grpc_response.rs +19 -0
- data/ext/itsi_server/src/ruby_types/itsi_grpc_stream/mod.rs +216 -0
- data/ext/itsi_server/src/{request/itsi_request.rs → ruby_types/itsi_http_request.rs} +101 -117
- data/ext/itsi_server/src/{response/itsi_response.rs → ruby_types/itsi_http_response.rs} +72 -41
- data/ext/itsi_server/src/ruby_types/itsi_server/file_watcher.rs +225 -0
- data/ext/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +355 -0
- data/ext/itsi_server/src/ruby_types/itsi_server.rs +82 -0
- data/ext/itsi_server/src/ruby_types/mod.rs +55 -0
- data/ext/itsi_server/src/server/bind.rs +13 -5
- data/ext/itsi_server/src/server/byte_frame.rs +32 -0
- data/ext/itsi_server/src/server/cache_store.rs +74 -0
- data/ext/itsi_server/src/server/itsi_service.rs +172 -0
- data/ext/itsi_server/src/server/lifecycle_event.rs +3 -0
- data/ext/itsi_server/src/server/listener.rs +102 -2
- data/ext/itsi_server/src/server/middleware_stack/middleware.rs +153 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/allow_list.rs +47 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_api_key.rs +58 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_basic.rs +82 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_jwt.rs +321 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/cache_control.rs +139 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/compression.rs +300 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/cors.rs +287 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/deny_list.rs +48 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/error_response.rs +127 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/etag.rs +191 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/grpc_service.rs +72 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/header_interpretation.rs +85 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/intrusion_protection.rs +195 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/log_requests.rs +82 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/mod.rs +82 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/proxy.rs +216 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/rate_limit.rs +124 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/redirect.rs +76 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/request_headers.rs +43 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/response_headers.rs +34 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +93 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/static_assets.rs +162 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/string_rewrite.rs +158 -0
- data/ext/itsi_server/src/server/middleware_stack/middlewares/token_source.rs +12 -0
- data/ext/itsi_server/src/server/middleware_stack/mod.rs +315 -0
- data/ext/itsi_server/src/server/mod.rs +8 -1
- data/ext/itsi_server/src/server/process_worker.rs +38 -12
- data/ext/itsi_server/src/server/rate_limiter.rs +565 -0
- data/ext/itsi_server/src/server/request_job.rs +11 -0
- data/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +119 -42
- data/ext/itsi_server/src/server/serve_strategy/mod.rs +9 -6
- data/ext/itsi_server/src/server/serve_strategy/single_mode.rs +256 -111
- data/ext/itsi_server/src/server/signal.rs +19 -0
- data/ext/itsi_server/src/server/static_file_server.rs +984 -0
- data/ext/itsi_server/src/server/thread_worker.rs +139 -94
- data/ext/itsi_server/src/server/types.rs +43 -0
- data/ext/itsi_tracing/Cargo.toml +1 -0
- data/ext/itsi_tracing/src/lib.rs +216 -45
- data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-0994n8rpvvt9m/s-h510hfz1f6-1kbycmq.lock +0 -0
- data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-0bob7bf4yq34i/s-h5113125h5-0lh4rag.lock +0 -0
- data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2fcodulrxbbxo/s-h510h2infk-0hp5kjw.lock +0 -0
- data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2iak63r1woi1l/s-h510h2in4q-0kxfzw1.lock +0 -0
- data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2kk4qj9gn5dg2/s-h5113124kv-0enwon2.lock +0 -0
- data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2mwo0yas7dtw4/s-h510hfz1ha-1udgpei.lock +0 -0
- data/lib/itsi/{request.rb → http_request.rb} +29 -5
- data/lib/itsi/http_response.rb +39 -0
- data/lib/itsi/server/Itsi.rb +11 -19
- data/lib/itsi/server/config/dsl.rb +506 -0
- data/lib/itsi/server/config.rb +103 -8
- data/lib/itsi/server/default_app/default_app.rb +38 -0
- data/lib/itsi/server/grpc_interface.rb +213 -0
- data/lib/itsi/server/rack/handler/itsi.rb +8 -17
- data/lib/itsi/server/rack_interface.rb +23 -4
- data/lib/itsi/server/scheduler_interface.rb +1 -1
- data/lib/itsi/server/scheduler_mode.rb +4 -0
- data/lib/itsi/server/signal_trap.rb +7 -1
- data/lib/itsi/server/version.rb +1 -1
- data/lib/itsi/server.rb +74 -63
- data/lib/itsi/standard_headers.rb +86 -0
- metadata +84 -15
- data/ext/itsi_scheduler/extconf.rb +0 -6
- data/ext/itsi_server/src/body_proxy/mod.rs +0 -2
- data/ext/itsi_server/src/request/mod.rs +0 -1
- data/ext/itsi_server/src/response/mod.rs +0 -1
- data/ext/itsi_server/src/server/itsi_server.rs +0 -288
- data/lib/itsi/server/options_dsl.rb +0 -401
- data/lib/itsi/stream_io.rb +0 -38
- /data/lib/itsi/{index.html → server/default_app/index.html} +0 -0
@@ -1,17 +1,13 @@
|
|
1
|
-
use crate::
|
2
|
-
|
3
|
-
|
4
|
-
};
|
1
|
+
use crate::ruby_types::itsi_server::itsi_server_config::ItsiServerConfig;
|
2
|
+
use crate::server::signal::SIGNAL_HANDLER_CHANNEL;
|
3
|
+
use crate::server::{lifecycle_event::LifecycleEvent, process_worker::ProcessWorker};
|
5
4
|
use itsi_error::{ItsiError, Result};
|
6
5
|
use itsi_rb_helpers::{
|
7
6
|
call_proc_and_log_errors, call_with_gvl, call_without_gvl, create_ruby_thread,
|
8
7
|
};
|
9
8
|
use itsi_tracing::{error, info, warn};
|
10
9
|
use magnus::Value;
|
11
|
-
use nix::{
|
12
|
-
libc::{self, exit},
|
13
|
-
unistd::Pid,
|
14
|
-
};
|
10
|
+
use nix::{libc::exit, unistd::Pid};
|
15
11
|
|
16
12
|
use std::{
|
17
13
|
sync::{atomic::AtomicUsize, Arc},
|
@@ -24,8 +20,7 @@ use tokio::{
|
|
24
20
|
};
|
25
21
|
use tracing::{debug, instrument};
|
26
22
|
pub(crate) struct ClusterMode {
|
27
|
-
pub
|
28
|
-
pub server: Arc<Server>,
|
23
|
+
pub server_config: Arc<ItsiServerConfig>,
|
29
24
|
pub process_workers: parking_lot::Mutex<Vec<ProcessWorker>>,
|
30
25
|
pub lifecycle_channel: broadcast::Sender<LifecycleEvent>,
|
31
26
|
}
|
@@ -35,12 +30,8 @@ static CHILD_SIGNAL_SENDER: parking_lot::Mutex<Option<watch::Sender<()>>> =
|
|
35
30
|
parking_lot::Mutex::new(None);
|
36
31
|
|
37
32
|
impl ClusterMode {
|
38
|
-
pub fn new(
|
39
|
-
|
40
|
-
listeners: Vec<Listener>,
|
41
|
-
lifecycle_channel: broadcast::Sender<LifecycleEvent>,
|
42
|
-
) -> Self {
|
43
|
-
let process_workers = (0..server.workers)
|
33
|
+
pub fn new(server_config: Arc<ItsiServerConfig>) -> Self {
|
34
|
+
let process_workers = (0..server_config.server_params.read().workers)
|
44
35
|
.map(|_| ProcessWorker {
|
45
36
|
worker_id: WORKER_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
|
46
37
|
..Default::default()
|
@@ -48,10 +39,9 @@ impl ClusterMode {
|
|
48
39
|
.collect();
|
49
40
|
|
50
41
|
Self {
|
51
|
-
|
52
|
-
server,
|
42
|
+
server_config,
|
53
43
|
process_workers: parking_lot::Mutex::new(process_workers),
|
54
|
-
lifecycle_channel,
|
44
|
+
lifecycle_channel: SIGNAL_HANDLER_CHANNEL.0.clone(),
|
55
45
|
}
|
56
46
|
}
|
57
47
|
|
@@ -73,13 +63,56 @@ impl ClusterMode {
|
|
73
63
|
) -> Result<()> {
|
74
64
|
match lifecycle_event {
|
75
65
|
LifecycleEvent::Start => Ok(()),
|
66
|
+
LifecycleEvent::PrintInfo => {
|
67
|
+
self.print_info().await?;
|
68
|
+
Ok(())
|
69
|
+
}
|
76
70
|
LifecycleEvent::Shutdown => {
|
71
|
+
self.server_config.stop_watcher()?;
|
77
72
|
self.shutdown().await?;
|
78
73
|
Ok(())
|
79
74
|
}
|
80
75
|
LifecycleEvent::Restart => {
|
81
|
-
|
82
|
-
|
76
|
+
self.server_config.dup_fds()?;
|
77
|
+
self.shutdown().await.ok();
|
78
|
+
info!("Shutdown complete. Calling reload exec");
|
79
|
+
self.server_config.reload_exec()?;
|
80
|
+
Ok(())
|
81
|
+
}
|
82
|
+
LifecycleEvent::Reload => {
|
83
|
+
let should_reexec = self.server_config.clone().reload(true)?;
|
84
|
+
if should_reexec {
|
85
|
+
self.server_config.dup_fds()?;
|
86
|
+
self.shutdown().await.ok();
|
87
|
+
self.server_config.reload_exec()?;
|
88
|
+
}
|
89
|
+
let mut workers_to_load = self.server_config.server_params.read().workers;
|
90
|
+
let mut next_workers = Vec::new();
|
91
|
+
for worker in self.process_workers.lock().drain(..) {
|
92
|
+
if workers_to_load == 0 {
|
93
|
+
worker.graceful_shutdown(self.clone()).await
|
94
|
+
} else {
|
95
|
+
workers_to_load -= 1;
|
96
|
+
worker.reboot(self.clone()).await?;
|
97
|
+
next_workers.push(worker);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
self.process_workers.lock().extend(next_workers);
|
101
|
+
while workers_to_load > 0 {
|
102
|
+
let mut workers = self.process_workers.lock();
|
103
|
+
let worker = ProcessWorker {
|
104
|
+
worker_id: WORKER_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
|
105
|
+
..Default::default()
|
106
|
+
};
|
107
|
+
let worker_clone = worker.clone();
|
108
|
+
let self_clone = self.clone();
|
109
|
+
create_ruby_thread(move || {
|
110
|
+
call_without_gvl(move || {
|
111
|
+
worker_clone.boot(self_clone).ok();
|
112
|
+
})
|
113
|
+
});
|
114
|
+
workers.push(worker);
|
115
|
+
workers_to_load -= 1
|
83
116
|
}
|
84
117
|
Ok(())
|
85
118
|
}
|
@@ -106,8 +139,10 @@ impl ClusterMode {
|
|
106
139
|
};
|
107
140
|
if let Some(dropped_worker) = worker {
|
108
141
|
dropped_worker.request_shutdown();
|
109
|
-
let force_kill_time =
|
110
|
-
|
142
|
+
let force_kill_time = Instant::now()
|
143
|
+
+ Duration::from_secs_f64(
|
144
|
+
self.server_config.server_params.read().shutdown_timeout,
|
145
|
+
);
|
111
146
|
while dropped_worker.is_alive() && force_kill_time > Instant::now() {
|
112
147
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
113
148
|
}
|
@@ -121,13 +156,20 @@ impl ClusterMode {
|
|
121
156
|
for worker in self.process_workers.lock().iter() {
|
122
157
|
worker.force_kill();
|
123
158
|
}
|
159
|
+
error!("Force shutdown!");
|
124
160
|
unsafe { exit(0) };
|
125
161
|
}
|
162
|
+
LifecycleEvent::ChildTerminated => {
|
163
|
+
CHILD_SIGNAL_SENDER.lock().as_ref().inspect(|i| {
|
164
|
+
i.send(()).ok();
|
165
|
+
});
|
166
|
+
Ok(())
|
167
|
+
}
|
126
168
|
}
|
127
169
|
}
|
128
170
|
|
129
171
|
pub async fn shutdown(&self) -> Result<()> {
|
130
|
-
let shutdown_timeout = self.
|
172
|
+
let shutdown_timeout = self.server_config.server_params.read().shutdown_timeout;
|
131
173
|
let workers = self.process_workers.lock().clone();
|
132
174
|
|
133
175
|
workers.iter().for_each(|worker| worker.request_shutdown());
|
@@ -163,35 +205,71 @@ impl ClusterMode {
|
|
163
205
|
Err(ItsiError::Break())
|
164
206
|
}
|
165
207
|
|
166
|
-
pub fn
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
208
|
+
pub async fn print_info(self: Arc<Self>) -> Result<()> {
|
209
|
+
println!("Itsi Cluster Info:");
|
210
|
+
println!("Master PID: {:?}", Pid::this());
|
211
|
+
if let Some(memory_limit) = self.server_config.server_params.read().worker_memory_limit {
|
212
|
+
println!("Worker Memory Limit: {}", memory_limit);
|
213
|
+
}
|
214
|
+
|
215
|
+
if self.server_config.watcher_fd.is_some() {
|
216
|
+
println!("File Watcher Enabled: true",);
|
217
|
+
if let Some(watchers) = self
|
218
|
+
.server_config
|
219
|
+
.server_params
|
220
|
+
.read()
|
221
|
+
.notify_watchers
|
222
|
+
.as_ref()
|
223
|
+
{
|
224
|
+
for watcher in watchers {
|
225
|
+
println!(
|
226
|
+
"Watching path: {} => {}",
|
227
|
+
watcher.0,
|
228
|
+
watcher
|
229
|
+
.1
|
230
|
+
.iter()
|
231
|
+
.map(|path| path.join(","))
|
232
|
+
.collect::<Vec<String>>()
|
233
|
+
.join(" ")
|
234
|
+
);
|
235
|
+
}
|
175
236
|
}
|
176
237
|
}
|
238
|
+
println!(
|
239
|
+
"Silent Mode: {}",
|
240
|
+
self.server_config.server_params.read().silence
|
241
|
+
);
|
242
|
+
println!(
|
243
|
+
"Preload: {}",
|
244
|
+
self.server_config.server_params.read().preload
|
245
|
+
);
|
246
|
+
let workers = self.process_workers.lock().clone();
|
247
|
+
for worker in workers {
|
248
|
+
worker.print_info()?;
|
249
|
+
sleep(Duration::from_millis(50)).await;
|
250
|
+
}
|
251
|
+
Ok(())
|
177
252
|
}
|
178
253
|
|
179
254
|
pub fn stop(&self) -> Result<()> {
|
180
|
-
unsafe { libc::signal(libc::SIGCHLD, libc::SIG_DFL) };
|
181
|
-
|
182
255
|
for worker in self.process_workers.lock().iter() {
|
183
256
|
if worker.is_alive() {
|
184
257
|
worker.force_kill();
|
185
258
|
}
|
186
259
|
}
|
187
|
-
|
188
260
|
Ok(())
|
189
261
|
}
|
190
262
|
|
191
263
|
#[instrument(skip(self), fields(mode = "cluster", pid=format!("{:?}", Pid::this())))]
|
192
264
|
pub fn run(self: Arc<Self>) -> Result<()> {
|
193
265
|
info!("Starting in Cluster mode");
|
194
|
-
if let Some(proc) = self
|
266
|
+
if let Some(proc) = self
|
267
|
+
.server_config
|
268
|
+
.server_params
|
269
|
+
.read()
|
270
|
+
.hooks
|
271
|
+
.get("before_fork")
|
272
|
+
{
|
195
273
|
call_with_gvl(|_| call_proc_and_log_errors(proc.clone()))
|
196
274
|
}
|
197
275
|
self.process_workers
|
@@ -202,8 +280,6 @@ impl ClusterMode {
|
|
202
280
|
let (sender, mut receiver) = watch::channel(());
|
203
281
|
*CHILD_SIGNAL_SENDER.lock() = Some(sender);
|
204
282
|
|
205
|
-
unsafe { libc::signal(libc::SIGCHLD, Self::receive_signal as usize) };
|
206
|
-
|
207
283
|
let mut lifecycle_rx = self.lifecycle_channel.subscribe();
|
208
284
|
let self_ref = self.clone();
|
209
285
|
|
@@ -215,14 +291,15 @@ impl ClusterMode {
|
|
215
291
|
_ = receiver.changed() => {
|
216
292
|
let mut workers = self_ref.process_workers.lock();
|
217
293
|
workers.retain(|worker| {
|
218
|
-
worker.boot_if_dead(
|
294
|
+
worker.boot_if_dead(self_ref.clone())
|
219
295
|
});
|
220
296
|
if workers.is_empty() {
|
221
297
|
warn!("No workers running. Send SIGTTIN to increase worker count");
|
222
298
|
}
|
223
299
|
}
|
224
300
|
_ = memory_check_interval.tick() => {
|
225
|
-
|
301
|
+
let worker_memory_limit = self_ref.server_config.server_params.read().worker_memory_limit;
|
302
|
+
if let Some(memory_limit) = worker_memory_limit {
|
226
303
|
let largest_worker = {
|
227
304
|
let workers = self_ref.process_workers.lock();
|
228
305
|
workers.iter().max_by(|wa, wb| wa.memory_usage().cmp(&wb.memory_usage())).cloned()
|
@@ -231,7 +308,7 @@ impl ClusterMode {
|
|
231
308
|
if let Some(current_mem_usage) = largest_worker.memory_usage(){
|
232
309
|
if current_mem_usage > memory_limit {
|
233
310
|
largest_worker.reboot(self_ref.clone()).await.ok();
|
234
|
-
if let Some(hook) = self_ref.
|
311
|
+
if let Some(hook) = self_ref.server_config.server_params.read().hooks.get("after_memory_threshold_reached") {
|
235
312
|
call_with_gvl(|_| hook.call::<_, Value>((largest_worker.pid(),)).ok() );
|
236
313
|
}
|
237
314
|
}
|
@@ -1,27 +1,30 @@
|
|
1
|
+
use std::sync::Arc;
|
2
|
+
|
1
3
|
use cluster_mode::ClusterMode;
|
2
4
|
use itsi_error::Result;
|
3
5
|
use single_mode::SingleMode;
|
4
|
-
|
6
|
+
|
5
7
|
pub mod cluster_mode;
|
6
8
|
pub mod single_mode;
|
7
9
|
|
10
|
+
#[derive(Clone)]
|
8
11
|
pub(crate) enum ServeStrategy {
|
9
12
|
Single(Arc<SingleMode>),
|
10
13
|
Cluster(Arc<ClusterMode>),
|
11
14
|
}
|
12
15
|
|
13
16
|
impl ServeStrategy {
|
14
|
-
pub fn run(
|
17
|
+
pub fn run(self) -> Result<()> {
|
15
18
|
match self {
|
16
|
-
ServeStrategy::Single(single_router) => single_router.
|
17
|
-
ServeStrategy::Cluster(cluster_router) => cluster_router.
|
19
|
+
ServeStrategy::Single(single_router) => single_router.run(),
|
20
|
+
ServeStrategy::Cluster(cluster_router) => cluster_router.run(),
|
18
21
|
}
|
19
22
|
}
|
20
23
|
|
21
24
|
pub(crate) fn stop(&self) -> Result<()> {
|
22
25
|
match self {
|
23
|
-
ServeStrategy::Single(single_router) => single_router.
|
24
|
-
ServeStrategy::Cluster(cluster_router) => cluster_router.
|
26
|
+
ServeStrategy::Single(single_router) => single_router.stop(),
|
27
|
+
ServeStrategy::Cluster(cluster_router) => cluster_router.stop(),
|
25
28
|
}
|
26
29
|
}
|
27
30
|
}
|